From 251aa3a310b9f129344cfe466f9653c1d131912a Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 23 Nov 2016 11:58:29 +0100 Subject: [PATCH] add field for setting context for pending step (#159) * add field for setting context for pending step * add readResolve method this to handle null-serialization * add @since tags --- .../jenkins/GitHubSetCommitStatusBuilder.java | 28 ++++++++++++++++++- .../config.groovy | 2 ++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java index c5a746ee7..b52ed1adc 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java @@ -11,6 +11,7 @@ import hudson.tasks.Builder; import jenkins.tasks.SimpleBuildStep; import org.jenkinsci.plugins.github.common.ExpandableMessage; +import org.jenkinsci.plugins.github.extension.status.GitHubStatusContextSource; import org.jenkinsci.plugins.github.extension.status.StatusErrorHandler; import org.jenkinsci.plugins.github.extension.status.misc.ConditionalResult; import org.jenkinsci.plugins.github.status.GitHubCommitStatusSetter; @@ -35,6 +36,7 @@ public class GitHubSetCommitStatusBuilder extends Builder implements SimpleBuild private static final ExpandableMessage DEFAULT_MESSAGE = new ExpandableMessage(""); private ExpandableMessage statusMessage = DEFAULT_MESSAGE; + private GitHubStatusContextSource contextSource = new DefaultCommitContextSource(); @DataBoundConstructor public GitHubSetCommitStatusBuilder() { @@ -47,6 +49,14 @@ public ExpandableMessage getStatusMessage() { return statusMessage; } + /** + * @return Context provider + * @since FIXME + */ + public GitHubStatusContextSource getContextSource() { + return contextSource; + } + /** * @since 1.14.1 */ @@ -55,6 +65,14 @@ public void setStatusMessage(ExpandableMessage statusMessage) { this.statusMessage = statusMessage; } + /** + * @since FIXME + */ + @DataBoundSetter + public void setContextSource(GitHubStatusContextSource contextSource) { + this.contextSource = contextSource; + } + @Override public void perform(@NonNull Run build, @NonNull FilePath workspace, @@ -64,7 +82,7 @@ public void perform(@NonNull Run build, GitHubCommitStatusSetter setter = new GitHubCommitStatusSetter(); setter.setReposSource(new AnyDefinedRepositorySource()); setter.setCommitShaSource(new BuildDataRevisionShaSource()); - setter.setContextSource(new DefaultCommitContextSource()); + setter.setContextSource(contextSource); setter.setErrorHandlers(Collections.singletonList(new ShallowAnyErrorHandler())); setter.setStatusResultSource(new ConditionalStatusResultSource( @@ -79,6 +97,14 @@ public void perform(@NonNull Run build, setter.perform(build, workspace, launcher, listener); } + + public Object readResolve() { + if (getContextSource() == null) { + setContextSource(new DefaultCommitContextSource()); + } + return this; + } + @Extension public static class Descriptor extends BuildStepDescriptor { @Override diff --git a/src/main/resources/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder/config.groovy b/src/main/resources/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder/config.groovy index 297388577..0e5ff7150 100644 --- a/src/main/resources/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder/config.groovy +++ b/src/main/resources/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder/config.groovy @@ -9,6 +9,8 @@ if (instance == null) { instance = new GitHubSetCommitStatusBuilder() } +f.dropdownDescriptorSelector(title: _('Commit context: '), field: 'contextSource') + f.advanced() { f.entry(title: _('Build status message'), field: 'statusMessage') { f.property()