Skip to content
Permalink
Browse files

Add workflow support (#8)

* 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 31dca10e324e6fbd0c7cab0b422b387263f32329
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/main/java/org/jenkinsci/plugins/githubissues/GitHubIssueNotifier.java
@@ -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());
@@ -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) {

0 comments on commit 31dca10

Please sign in to comment.
You can’t perform that action at this time.