Skip to content

Commit 6e04dcf

Browse files
author
Kelly Johnson
committed
Report coverage as separate build thing
1 parent fdaf167 commit 6e04dcf

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/main/java/org/jenkinsci/plugins/ghprb/extensions/status/GhprbSimpleStatus.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,24 @@ public void onBuildComplete(Run<?, ?> build,
224224
sb.append(buildManager.getOneLineTestResults());
225225
}
226226
if (getAddCoverageResults()) {
227-
if (getAddTestResults()) {
228-
sb.append(" ");
229-
}
230227
listener.getLogger().println("Adding coverage results to commit status...");
228+
229+
String coverageResultString;
230+
GHCommitState coverageState;
231231
Map<String, String> envVars = Ghprb.getEnvVars(build, listener);
232232
if (!envVars.containsKey("newCodeCoveragePercentage")) {
233-
sb.append("No coverage results found.");
233+
coverageResultString = "No coverage results found.";
234+
coverageState = GHCommitState.SUCCESS;
234235
} else {
235-
sb.append(Integer.parseInt(envVars.get("newCodeCoveragePercentage")));
236-
sb.append("% line coverage on new code.");
236+
String newCodeCoveragePercentage = envVars.get("newCodeCoveragePercentage");
237+
coverageResultString = newCodeCoveragePercentage + "% line coverage on new code.";
238+
int coveragePercent = Integer.parseInt(newCodeCoveragePercentage);
239+
coverageState = coveragePercent > 1 ? GHCommitState.SUCCESS : GHCommitState.ERROR;
237240
}
241+
242+
String context = Util.fixEmpty(commitStatusContext);
243+
context = Ghprb.replaceMacros(build, listener, context) + " Coverage";
244+
createCommitStatus(build, listener, coverageResultString, repo, coverageState, context);
238245
}
239246
}
240247

@@ -245,7 +252,8 @@ private void createCommitStatus(Run<?, ?> build,
245252
TaskListener listener,
246253
String message,
247254
GHRepository repo,
248-
GHCommitState state) throws GhprbCommitStatusException {
255+
GHCommitState state,
256+
String context) throws GhprbCommitStatusException {
249257

250258
Map<String, String> envVars = Ghprb.getEnvVars(build, listener);
251259

@@ -266,9 +274,6 @@ private void createCommitStatus(Run<?, ?> build,
266274
url = Ghprb.replaceMacros(build, listener, statusUrl);
267275
}
268276

269-
String context = Util.fixEmpty(commitStatusContext);
270-
context = Ghprb.replaceMacros(build, listener, context);
271-
272277
listener.getLogger().println(String.format("Setting status of %s to %s with url %s and message: '%s'",
273278
sha1,
274279
state,
@@ -286,6 +291,16 @@ private void createCommitStatus(Run<?, ?> build,
286291
}
287292
}
288293

294+
private void createCommitStatus(Run<?, ?> build,
295+
TaskListener listener,
296+
String message,
297+
GHRepository repo,
298+
GHCommitState state) throws GhprbCommitStatusException {
299+
String context = Util.fixEmpty(commitStatusContext);
300+
context = Ghprb.replaceMacros(build, listener, context);
301+
createCommitStatus(build, listener, message, repo, state, context);
302+
}
303+
289304
public void createCommitStatus(Job<?, ?> project,
290305
int prId,
291306
String commitSha,

0 commit comments

Comments
 (0)