Skip to content

Commit 16d01a7

Browse files
committed
Add git info to coveralls
1 parent dc3ded0 commit 16d01a7

File tree

7 files changed

+192
-28
lines changed

7 files changed

+192
-28
lines changed

build.sbt

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name := "sbt-jacoco"
22
organization := "com.github.sbt"
33

4-
version in ThisBuild := "3.1.0-M2"
4+
version in ThisBuild := "3.1.0-M3"
55

66
sbtPlugin := true
77
crossSbtVersions := Seq("0.13.16", "1.0.2")
@@ -15,7 +15,8 @@ libraryDependencies ++= Seq(
1515
"com.jsuereth" %% "scala-arm" % "2.0",
1616
"com.fasterxml.jackson.core" % "jackson-core" % "2.9.2",
1717
"org.scalaj" %% "scalaj-http" % "2.3.0",
18-
"commons-codec" % "commons-codec" % "1.11",
18+
"commons-codec" % "commons-codec" % "1.11",
19+
"org.eclipse.jgit" % "org.eclipse.jgit" % "3.7.1.201504261725-r",
1920
"org.scalatest" %% "scalatest" % "3.0.4" % Test,
2021
"org.mockito" % "mockito-all" % "1.10.19" % Test
2122
)
@@ -51,11 +52,6 @@ headerLicense := Some(HeaderLicense.Custom(
5152
|""".stripMargin
5253
))
5354

54-
5555
enablePlugins(ParadoxSitePlugin, GhpagesPlugin)
5656
paradoxNavigationDepth in Paradox := 3
5757
git.remoteRepo := "[email protected]:sbt/sbt-jacoco.git"
58-
59-
addCompilerPlugin(
60-
"org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full
61-
)

src/main/scala/com/github/sbt/jacoco/coveralls/CoverallsClient.scala

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
113
package com.github.sbt.jacoco.coveralls
214

315
import java.io.{File, FileInputStream}
@@ -19,8 +31,9 @@ object CoverallsClient {
1931
new FileInputStream(reportFile),
2032
reportFile.length(),
2133
_ => ())
22-
).asString
23-
34+
)
35+
.asString
36+
2437
if (response.isSuccess) {
2538
streams.log.info("Upload complete")
2639
} else {

src/main/scala/com/github/sbt/jacoco/coveralls/CoverallsReportFormat.scala

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
113
package com.github.sbt.jacoco.coveralls
214

315
import java.io.File

src/main/scala/com/github/sbt/jacoco/coveralls/CoverallsReportVisitor.scala

+64-18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
113
package com.github.sbt.jacoco.coveralls
214

315
import java.io.File
@@ -29,24 +41,7 @@ class CoverallsReportVisitor(
2941
private val jsonFactory = new JsonFactory()
3042
private val json = jsonFactory.createGenerator(output, JsonEncoding.UTF8)
3143

32-
json.writeStartObject()
33-
34-
repoToken foreach { token =>
35-
json.writeStringField("repo_token", token)
36-
}
37-
38-
json.writeStringField("service_name", serviceName)
39-
jobId foreach { id =>
40-
json.writeStringField("service_job_id", id)
41-
}
42-
pullRequest foreach { pr =>
43-
json.writeStringField("service_pull_request", pr)
44-
}
45-
buildNumber foreach { build =>
46-
json.writeStringField("service_number", build)
47-
}
48-
49-
json.writeArrayFieldStart("source_files")
44+
writeBasicInfo()
5045

5146
override def visitInfo(sessionInfos: ju.List[SessionInfo], executionData: ju.Collection[ExecutionData]): Unit = {}
5247

@@ -99,4 +94,55 @@ class CoverallsReportVisitor(
9994
// TODO make common with source file locator
10095
sourceDirs.map(d => d / packageName / fileName).find(_.exists())
10196
}
97+
98+
private def writeBasicInfo(): Unit = {
99+
json.writeStartObject()
100+
101+
repoToken foreach { token =>
102+
json.writeStringField("repo_token", token)
103+
}
104+
105+
json.writeStringField("service_name", serviceName)
106+
jobId foreach { id =>
107+
json.writeStringField("service_job_id", id)
108+
}
109+
pullRequest foreach { pr =>
110+
json.writeStringField("service_pull_request", pr)
111+
}
112+
buildNumber foreach { build =>
113+
json.writeStringField("service_number", build)
114+
}
115+
116+
writeGitInfo()
117+
118+
json.writeArrayFieldStart("source_files")
119+
}
120+
121+
private def writeGitInfo(): Unit = {
122+
GitInfo(projectRootDir) foreach { info =>
123+
json.writeObjectFieldStart("git")
124+
125+
json.writeStringField("branch", info.branch)
126+
127+
json.writeObjectFieldStart("head")
128+
json.writeStringField("id", info.hash)
129+
json.writeStringField("author_name", info.authorName)
130+
json.writeStringField("author_email", info.authorEmail)
131+
json.writeStringField("committer_name", info.committerName)
132+
json.writeStringField("committer_email", info.committerEmail)
133+
json.writeStringField("message", info.message)
134+
json.writeEndObject()
135+
136+
json.writeArrayFieldStart("remotes")
137+
info.remotes foreach { remote =>
138+
json.writeStartObject()
139+
json.writeStringField("name", remote.name)
140+
json.writeStringField("url", remote.url)
141+
json.writeEndObject()
142+
}
143+
json.writeEndArray()
144+
145+
json.writeEndObject()
146+
}
147+
}
102148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
13+
package com.github.sbt.jacoco.coveralls
14+
15+
import java.io.{File, IOException}
16+
17+
import org.eclipse.jgit.lib.{Constants, ObjectId}
18+
import org.eclipse.jgit.revwalk.RevWalk
19+
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
20+
21+
import scala.collection.JavaConverters._
22+
23+
case class GitInfo(
24+
hash: String,
25+
authorName: String,
26+
authorEmail: String,
27+
committerName: String,
28+
committerEmail: String,
29+
message: String,
30+
branch: String,
31+
remotes: Seq[GitRemote])
32+
33+
case class GitRemote(name: String, url: String)
34+
35+
object GitInfo {
36+
def apply(basedir: File): Option[GitInfo] = {
37+
try {
38+
val gitDir = new File(basedir, ".git")
39+
40+
if (gitDir.isDirectory) {
41+
val repo = FileRepositoryBuilder.create(gitDir)
42+
val config = repo.getConfig
43+
val head = repo.getRef(Constants.HEAD)
44+
val walk = new RevWalk(repo)
45+
val commit = walk.parseCommit(head.getObjectId)
46+
47+
val remotes = config.getSubsections("remote").asScala map { name =>
48+
GitRemote(name, config.getString("remote", name, "url"))
49+
}
50+
51+
val info = GitInfo(
52+
ObjectId.toString(head.getObjectId),
53+
commit.getAuthorIdent.getName,
54+
commit.getAuthorIdent.getEmailAddress,
55+
commit.getCommitterIdent.getName,
56+
commit.getCommitterIdent.getEmailAddress,
57+
commit.getShortMessage,
58+
repo.getBranch,
59+
remotes.toSeq
60+
)
61+
62+
Some(info)
63+
} else {
64+
None
65+
}
66+
} catch {
67+
case _: IOException =>
68+
// don't have a git repo
69+
None
70+
}
71+
}
72+
}

src/main/scala/com/github/sbt/jacoco/coveralls/JacocoCoverallsPlugin.scala

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
113
package com.github.sbt.jacoco.coveralls
214

315
import java.io.File
@@ -41,7 +53,8 @@ object JacocoCoverallsPlugin extends BaseJacocoPlugin {
4153
jacocoCoverallsJobId.value,
4254
jacocoCoverallsBuildNumber.value,
4355
jacocoCoverallsPullRequest.value,
44-
jacocoCoverallsRepoToken.value)
56+
jacocoCoverallsRepoToken.value
57+
)
4558

4659
ReportUtils.generateReport(
4760
jacocoCoverallsOutput.value,

src/main/scala/com/github/sbt/jacoco/package.scala

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
* This file is part of sbt-jacoco.
3+
*
4+
* Copyright (c) Joachim Hofer & contributors
5+
* All rights reserved.
6+
*
7+
* This program and the accompanying materials
8+
* are made available under the terms of the Eclipse Public License v1.0
9+
* which accompanies this distribution, and is available at
10+
* http://www.eclipse.org/legal/epl-v10.html
11+
*/
12+
113
package com.github.sbt
214

315
import com.github.sbt.jacoco.data.ProjectData

0 commit comments

Comments
 (0)