Skip to content

Commit

Permalink
Merge pull request #103 from lanwen/fix_JENKINS-32132
Browse files Browse the repository at this point in the history
[FIXES JENKINS-32132] Check status message is null (in case of wrong …
  • Loading branch information
lanwen committed Dec 20, 2015
2 parents c8af6ec + 57d7870 commit 2c193b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/cloudbees/jenkins/GitHubCommitNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_DisplayName;
import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_SettingCommitStatus;
import static com.coravy.hudson.plugins.github.GithubProjectProperty.displayNameFor;
import static com.google.common.base.Objects.firstNonNull;
import static hudson.model.Result.FAILURE;
import static hudson.model.Result.SUCCESS;
import static hudson.model.Result.UNSTABLE;
Expand All @@ -41,8 +42,9 @@
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
public class GitHubCommitNotifier extends Notifier {
private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage("");

private ExpandableMessage statusMessage = new ExpandableMessage("");
private ExpandableMessage statusMessage = DEFAULT_MESSAGE;

private final String resultOnFailure;
private static final Result[] SUPPORTED_RESULTS = {FAILURE, UNSTABLE, SUCCESS};
Expand Down Expand Up @@ -124,7 +126,8 @@ private void updateCommitStatus(@Nonnull AbstractBuild<?, ?> build,
final String sha1 = ObjectId.toString(BuildDataHelper.getCommitSHA1(build));

StatusResult status = statusFrom(build);
String message = defaultIfEmpty(statusMessage.expandAll(build, listener), status.getMsg());
String message = defaultIfEmpty(firstNonNull(statusMessage, DEFAULT_MESSAGE)
.expandAll(build, listener), status.getMsg());
String contextName = displayNameFor(build.getProject());

for (GitHubRepositoryName name : GitHubRepositoryNameContributor.parseAssociatedNames(build.getProject())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@

import static com.cloudbees.jenkins.Messages.GitHubCommitNotifier_SettingCommitStatus;
import static com.coravy.hudson.plugins.github.GithubProjectProperty.displayNameFor;
import static com.google.common.base.Objects.firstNonNull;
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;

@Extension
public class GitHubSetCommitStatusBuilder extends Builder {
private ExpandableMessage statusMessage = new ExpandableMessage("");
private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage("");

private ExpandableMessage statusMessage = DEFAULT_MESSAGE;

@DataBoundConstructor
public GitHubSetCommitStatusBuilder() {
Expand All @@ -50,7 +53,7 @@ public boolean perform(AbstractBuild<?, ?> build,
BuildListener listener) throws InterruptedException, IOException {
final String sha1 = ObjectId.toString(BuildDataHelper.getCommitSHA1(build));
String message = defaultIfEmpty(
statusMessage.expandAll(build, listener),
firstNonNull(statusMessage, DEFAULT_MESSAGE).expandAll(build, listener),
Messages.CommitNotifier_Pending(build.getDisplayName())
);
String contextName = displayNameFor(build.getProject());
Expand Down

0 comments on commit 2c193b4

Please sign in to comment.