Skip to content

Commit

Permalink
Add workflow support (#8)
Browse files Browse the repository at this point in the history
* Add workflow support

Should resolve JENKINS-42629

* Run covers everything

* Treat null Result as success

In pipelines, Result is only set at the end. The common pattern is to
explicitly set it to failed/unstable. Thus, we can assume that null =>
success.

* Explain `result == null`
  • Loading branch information
Benjamin Gill authored and Daniel15 committed Jul 14, 2017
1 parent e57575a commit 31dca10
Showing 1 changed file with 7 additions and 3 deletions.
Expand Up @@ -136,7 +136,8 @@ public void perform(
}

Result result = run.getResult();
final GitHubIssueAction previousGitHubIssueAction = getLatestIssueAction((AbstractBuild) run.getPreviousBuild());

final GitHubIssueAction previousGitHubIssueAction = getLatestIssueAction((Run) run.getPreviousBuild());
GHIssue issue = null;
if (previousGitHubIssueAction != null) {
issue = repo.getIssue(previousGitHubIssueAction.getIssueNumber());
Expand Down Expand Up @@ -181,15 +182,18 @@ public void perform(
logger.format("GitHub Issue Notifier: Build has started failing, filed GitHub issue #%s%n", issue.getNumber());
run.addAction(new GitHubIssueAction(issue, GitHubIssueAction.TransitionAction.OPEN));
}
} else if (result == Result.SUCCESS && issue != null && issue.getState() == GHIssueState.OPEN) {
// In declarative pipelines, `result` can be null. The common pattern
// is to explicitly set the failure state, so we treat unset as
// implying success.
} else if ((result == Result.SUCCESS || result == null) && issue != null && issue.getState() == GHIssueState.OPEN) {
issue.comment("Build was fixed!");
issue.close();
logger.format("GitHub Issue Notifier: Build was fixed, closing GitHub issue #%s%n", issue.getNumber());
run.addAction(new GitHubIssueAction(issue, GitHubIssueAction.TransitionAction.CLOSE));
}
}

private GitHubIssueAction getLatestIssueAction(AbstractBuild previousBuild) {
private GitHubIssueAction getLatestIssueAction(Run previousBuild) {
if (previousBuild != null) {
GitHubIssueAction previousGitHubIssueAction = previousBuild.getAction(GitHubIssueAction.class);
if (previousGitHubIssueAction != null) {
Expand Down

0 comments on commit 31dca10

Please sign in to comment.