Skip to content
This repository was archived by the owner on Feb 19, 2020. It is now read-only.

Commit e373555

Browse files
authored
Merge pull request #40 from codacy/fix-travis-ci
Fix resolving the commitUUID
2 parents 0c0dbd6 + 78a0ceb commit e373555

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/main/scala/com/codacy/CodacyCoveragePlugin.scala

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,18 @@ object CodacyCoveragePlugin extends AutoPlugin {
2525
val codacyProjectToken = settingKey[Option[String]]("Your project token.")
2626
val coberturaFile = settingKey[File]("Path for project Cobertura file.")
2727
val codacyApiBaseUrl = settingKey[Option[String]]("The base URL for the Codacy API.")
28+
val codacyCommit = settingKey[Option[String]]("The commit uuid of the coverage.")
2829

2930
lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
3031
codacyCoverage := {
3132
codacyCoverageCommand(state.value, baseDirectory.value, coberturaFile.value,
3233
crossTarget.value / "coverage-report" / "codacy-coverage.json",
33-
codacyProjectToken.value, codacyApiBaseUrl.value)
34+
codacyProjectToken.value, codacyApiBaseUrl.value, codacyCommit.value)
3435
},
3536
aggregate in codacyCoverage := false,
3637
codacyProjectToken := None,
3738
codacyApiBaseUrl := None,
39+
codacyCommit := None,
3840
coberturaFile := crossTarget.value / ("coverage-report" + File.separator + "cobertura.xml")
3941
)
4042
}
@@ -48,20 +50,20 @@ object CodacyCoveragePlugin extends AutoPlugin {
4850
private val publicApiBaseUrl = "https://api.codacy.com"
4951

5052
private def codacyCoverageCommand(state: State, rootProjectDir: File, coberturaFile: File, codacyCoverageFile: File,
51-
codacyToken: Option[String], codacyApiBaseUrl: Option[String]): Unit = {
53+
codacyToken: Option[String], codacyApiBaseUrl: Option[String],
54+
sbtCodacyCommit: Option[String]): Unit = {
5255
implicit val logger: Logger = state.log
5356

54-
val commitUUID =
55-
sys.env.get("CI_COMMIT") orElse
56-
sys.env.get("TRAVIS_PULL_REQUEST_SHA") orElse
57-
sys.env.get("TRAVIS_COMMIT") orElse
58-
sys.env.get("DRONE_COMMIT") orElse
59-
sys.env.get("CIRCLE_SHA1") orElse
60-
sys.env.get("CI_COMMIT_ID") orElse
61-
sys.env.get("WERCKER_GIT_COMMIT")
62-
.filter(_.trim.nonEmpty)
63-
64-
FileHelper.withTokenAndCommit(codacyToken, commitUUID) {
57+
val commitUUIDOpt = sbtCodacyCommit orElse
58+
getNonEmptyEnv("CI_COMMIT") orElse
59+
getNonEmptyEnv("TRAVIS_PULL_REQUEST_SHA") orElse
60+
getNonEmptyEnv("TRAVIS_COMMIT") orElse
61+
getNonEmptyEnv("DRONE_COMMIT") orElse
62+
getNonEmptyEnv("CIRCLE_SHA1") orElse
63+
getNonEmptyEnv("CI_COMMIT_ID") orElse
64+
getNonEmptyEnv("WERCKER_GIT_COMMIT")
65+
66+
FileHelper.withTokenAndCommit(codacyToken, commitUUIDOpt) {
6567
case (projectToken, commitUUID) =>
6668

6769
val reader = new CoberturaParser(Language.Scala, rootProjectDir, coberturaFile)
@@ -91,12 +93,16 @@ object CodacyCoveragePlugin extends AutoPlugin {
9193
}
9294
}
9395

96+
private def getNonEmptyEnv(key: String): Option[String] = {
97+
sys.env.get(key).filter(_.trim.nonEmpty)
98+
}
99+
94100
private def apiBaseUrl(codacyApiBaseUrl: Option[String]): Option[String] = {
95101
// Check for an environment variable to override the API URL.
96102
// If it doesn't exist, try the build options or default to the public API.
97-
sys.env.get("CODACY_API_BASE_URL")
98-
.orElse(codacyApiBaseUrl)
99-
.orElse(Some(publicApiBaseUrl))
103+
codacyApiBaseUrl orElse
104+
getNonEmptyEnv("CODACY_API_BASE_URL") orElse
105+
Some(publicApiBaseUrl)
100106
}
101107

102108
}

0 commit comments

Comments
 (0)