diff --git a/ci-detector/src/main/java/io/github/tarek360/ci/Ci.kt b/ci-detector/src/main/java/io/github/tarek360/ci/Ci.kt index bb15413..4118c51 100644 --- a/ci-detector/src/main/java/io/github/tarek360/ci/Ci.kt +++ b/ci-detector/src/main/java/io/github/tarek360/ci/Ci.kt @@ -3,12 +3,7 @@ package io.github.tarek360.ci abstract class Ci { open val gitHostToken: String? by lazy { - val token = Environment.getVariable("KOSHRY_GIT_HOST_TOKEN") - if (token.isNullOrBlank()) { - Environment.getVariable("DANGER_GITHUB_API_TOKEN") - } else { - token - } + Environment.getVariable("KOSHRY_GIT_HOST_TOKEN") } abstract val buildId: Int? diff --git a/ci-detector/src/main/java/io/github/tarek360/ci/TeamCityCi.kt b/ci-detector/src/main/java/io/github/tarek360/ci/TeamCityCi.kt new file mode 100644 index 0000000..3c15be2 --- /dev/null +++ b/ci-detector/src/main/java/io/github/tarek360/ci/TeamCityCi.kt @@ -0,0 +1,20 @@ +package io.github.tarek360.ci + +class TeamCityCi : Ci() { + + override val buildId: Int? by lazy { + val buildId: String? = Environment.getVariable("TEAMCITY_BUILD_ID") + buildId?.toInt() + } + + override val projectOwnerNameRepoName: String? by lazy { + Environment.getVariable("GITHUB_REPO_SLUG") + } + + override val pullRequestId: Int? by lazy { + val teamcityBuildBranch = + Environment.getVariable("TEAMCITY_BUILD_BRANCH")?.split("/") + val id = teamcityBuildBranch?.get(0) + id?.toInt() + } +} diff --git a/githost/src/main/java/io/github/tarek360/githost/github/GitHub.kt b/githost/src/main/java/io/github/tarek360/githost/github/GitHub.kt index 155d2e8..9fa8f18 100644 --- a/githost/src/main/java/io/github/tarek360/githost/github/GitHub.kt +++ b/githost/src/main/java/io/github/tarek360/githost/github/GitHub.kt @@ -18,7 +18,7 @@ class GitHub(private val gitHostInfo: GitHostInfo, isEnterprise: Boolean = false // if it's not mocked web server if (baseUrl.isEmpty()) { baseUrl = if (isEnterprise) { - "https://${gitHostInfo.domain}/api/v3" + "https://${gitHostInfo.domain}/api/v3/" } else { "https://api.github.com/" } diff --git a/githost/src/test/kotlin/io/github/tarek360/githost/github/GitHubTest.kt b/githost/src/test/kotlin/io/github/tarek360/githost/github/GitHubTest.kt index 5fd7e37..d439993 100644 --- a/githost/src/test/kotlin/io/github/tarek360/githost/github/GitHubTest.kt +++ b/githost/src/test/kotlin/io/github/tarek360/githost/github/GitHubTest.kt @@ -35,7 +35,7 @@ class GitHubTest { val gitHostInfo = GitHostInfo("github.enterprise-company.com", "tarek360/RichPath", 1, "abcd1234") GitHub(gitHostInfo, true) - baseUrl mustEqual "https://github.enterprise-company.com/api/v3" + baseUrl mustEqual "https://github.enterprise-company.com/api/v3/" } @After diff --git a/gradle.properties b/gradle.properties index e4ae216..cf3d20a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true GROUP_ID=io.github.tarek360.koshry -VERSION=0.0.4 +VERSION=0.0.4.3 BUILD_NUMBER=0 DESCRIPTION=Koshry for CI BINTRAY_REPO=Koshry diff --git a/koshry/src/main/java/io/github/tarek360/koshry/CiProvider.kt b/koshry/src/main/java/io/github/tarek360/koshry/CiProvider.kt index abed183..a047f4a 100644 --- a/koshry/src/main/java/io/github/tarek360/koshry/CiProvider.kt +++ b/koshry/src/main/java/io/github/tarek360/koshry/CiProvider.kt @@ -3,18 +3,17 @@ package io.github.tarek360.koshry import io.github.tarek360.ci.Ci import io.github.tarek360.ci.CircleCi import io.github.tarek360.ci.Environment +import io.github.tarek360.ci.TeamCityCi import io.github.tarek360.ci.TravisCi class CiProvider { - fun provide(): Ci? { - return when { - Environment.getVariable("TRAVIS") == "true" -> TravisCi() - Environment.getVariable("CIRCLECI") == "true" -> CircleCi() - else -> null + fun provide(): Ci? { + return when { + Environment.getVariable("TRAVIS") == "true" -> TravisCi() + Environment.getVariable("CIRCLECI") == "true" -> CircleCi() + Environment.getVariable("TEAMCITY_BUILD_ID")?.isNotBlank() == true -> TeamCityCi() + else -> null + } } - - } - - -} \ No newline at end of file +}