Skip to content

Commit

Permalink
Merge pull request #144 from florianmutter/add-support-for-travis-pro
Browse files Browse the repository at this point in the history
Fix support for travis pro
  • Loading branch information
ckipp01 authored Jun 17, 2021
2 parents d4758ec + 4b90d88 commit 466c7c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions src/main/scala/org/scoverage/coveralls/CIService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 466c7c3

Please sign in to comment.