Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Download link in "+botinfo extended" is wrong if the build was compil…
…ed via GitHub (#2223) Fixes #2130 * Build URL generation extracted to method * Build URL generation extracted * Download link in "+botinfo extended" is wrong if the build was compiled via GitHub #2130
- Loading branch information
Showing
7 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ta-discord/src/main/java/com/mrpowergamerbr/loritta/commands/vanilla/discord/BuildInfo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mrpowergamerbr.loritta.commands.vanilla.discord | ||
|
||
import java.util.jar.Attributes | ||
|
||
class BuildInfo(val attribute: Attributes) { | ||
val githubBuildId = attribute[GITHUB_BUILD_ID] as String | ||
fun buildUrl(): String { | ||
return if (isJenkinsBuild()) | ||
createJenkinsBuildURL() | ||
else | ||
createGithubBuildURL() | ||
} | ||
|
||
private fun createGithubBuildURL() = "$GITHUB_BUILD_BASE_URL$githubBuildId" | ||
private fun createJenkinsBuildURL(): String { | ||
val buildNumber = attribute[BUILD_NUMBER] as String | ||
return "$JENKINS_BUILD_BASE_URL$buildNumber/" | ||
} | ||
|
||
private fun isJenkinsBuild() = (githubBuildId as String) == "" | ||
|
||
private companion object { | ||
val BUILD_NUMBER = Attributes.Name("Build-Number") | ||
val GITHUB_BUILD_ID = Attributes.Name("Github-Build-Id") | ||
const val GITHUB_BUILD_BASE_URL = "https://github.com/LorittaBot/Loritta/actions/runs/" | ||
const val JENKINS_BUILD_BASE_URL = "https://jenkins.perfectdreams.net/job/Loritta/" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...iscord/src/test/java/com/mrpowergamerbr/loritta/commands/vanilla/discord/BuildInfoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.mrpowergamerbr.loritta.commands.vanilla.discord | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import java.util.jar.Attributes | ||
|
||
class BuildInfoTest { | ||
@Test | ||
fun `generate Jenkins build URL`() { | ||
val attribute = Attributes() | ||
attribute[BUILD_NUMBER] = "123" | ||
attribute[GITHUB_BUILD_ID] = "" | ||
|
||
val buildInfo = BuildInfo(attribute) | ||
|
||
assertThat( buildInfo.buildUrl()).isEqualTo("https://jenkins.perfectdreams.net/job/Loritta/123/") | ||
} | ||
@Test | ||
fun `generate Github build URL`() { | ||
val attribute = Attributes() | ||
attribute[BUILD_NUMBER] = "123" | ||
attribute[GITHUB_BUILD_ID] = "456" | ||
|
||
val buildInfo = BuildInfo(attribute) | ||
|
||
assertThat( buildInfo.buildUrl()).isEqualTo("https://github.com/LorittaBot/Loritta/actions/runs/456") | ||
} | ||
|
||
private companion object { | ||
val BUILD_NUMBER = Attributes.Name("Build-Number") | ||
val GITHUB_BUILD_ID= Attributes.Name("Github-Build-Id") | ||
} | ||
} |