Skip to content
Permalink
Browse files
[FIXES JENKINS-32132] Check status message is null (in case of wrong …
…deserialization)
  • Loading branch information
lanwen committed Dec 20, 2015
1 parent c8af6ec commit 57d7870f7a170f9b7ae772b3ccc107554cbf6269
@@ -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;
@@ -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};
@@ -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())) {
@@ -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() {
@@ -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());

0 comments on commit 57d7870

Please sign in to comment.