diff --git a/README.md b/README.md index 9639340..1ea4149 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ For example output [click here](https://coveralls.io/r/scoverage/scoverage-sampl ```scala -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2") -addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7") +addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1") ``` 2) Setup coveralls configuration options (such as [Specifying Your Repo Token](#specifying-your-repo-token)) @@ -161,12 +161,13 @@ scalacOptions += Seq("-encoding", "UTF-8") ## Using Travis-Pro -It is important to set the correct `service_name` when using Travis-Pro. The default is to use `travis-ci`. To override this value, add the following to your `build.sbt` +It is important to set the correct `service` when using Travis-Pro. The default is to use `travis-ci`. To override this value, add the following to your `build.sbt` ```scala import org.scoverage.coveralls.Imports.CoverallsKeys._ +import org.scoverage.coveralls.TravisPro -coverallsServiceName := Some("travis-pro") +coverallsService := Some(TravisPro) ``` # License diff --git a/src/main/scala/org/scoverage/coveralls/CIService.scala b/src/main/scala/org/scoverage/coveralls/CIService.scala index a3fae6f..e1e7351 100644 --- a/src/main/scala/org/scoverage/coveralls/CIService.scala +++ b/src/main/scala/org/scoverage/coveralls/CIService.scala @@ -11,24 +11,32 @@ trait CIService { } case object TravisCI extends CIService { - def name = "travis-ci" - def jobId = sys.env.get("TRAVIS_JOB_ID") - def pullRequest = sys.env.get("CI_PULL_REQUEST") + val name = "travis-ci" + val jobId: Option[String] = sys.env.get("TRAVIS_JOB_ID") + val pullRequest: Option[String] = sys.env.get("CI_PULL_REQUEST") + val currentBranch: Option[String] = sys.env.get("CI_BRANCH") +} - def currentBranch = sys.env.get("CI_BRANCH") +case object TravisPro extends CIService { + val name = "travis-pro" + val jobId: Option[String] = sys.env.get("TRAVIS_JOB_ID") + val pullRequest: Option[String] = sys.env.get("CI_PULL_REQUEST") + val currentBranch: Option[String] = sys.env.get("CI_BRANCH") } case object GitHubActions extends CIService { - def name = "github" - def jobId = sys.env.get("GITHUB_RUN_ID") + val name = "github" + val jobId: Option[String] = sys.env.get("GITHUB_RUN_ID") // https://github.com/coverallsapp/github-action/blob/master/src/run.ts#L31-L40 - def pullRequest = for { + val pullRequest: Option[String] = for { eventName <- sys.env.get("GITHUB_EVENT_NAME") if eventName == "pull_request" payloadPath <- sys.env.get("GITHUB_EVENT_PATH") - payload <- JSON.parseRaw(Source.fromFile(payloadPath, "utf-8").mkString) + source = Source.fromFile(payloadPath, "utf-8") + lines = try source.mkString finally source.close() + payload <- JSON.parseRaw(lines) prNumber <- payload.asInstanceOf[JSONObject].obj.get("number") } yield prNumber.toString - def currentBranch = sys.env.get("GITHUB_REF") + val currentBranch: Option[String] = sys.env.get("GITHUB_REF") }