From db02161e11bb72f04781e1fd0948574224cef9ed Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Sun, 20 Nov 2016 16:34:43 +0100 Subject: [PATCH 1/3] add field for setting context for pending step --- .../jenkins/GitHubSetCommitStatusBuilder.java | 16 +++++++++++++++- .../GitHubSetCommitStatusBuilder/config.groovy | 2 ++ 2 files changed, 17 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..9e70a7149 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,13 @@ public ExpandableMessage getStatusMessage() { return statusMessage; } + /** + * @return Context provider + */ + public GitHubStatusContextSource getContextSource() { + return contextSource; + } + /** * @since 1.14.1 */ @@ -55,6 +64,11 @@ public void setStatusMessage(ExpandableMessage statusMessage) { this.statusMessage = statusMessage; } + @DataBoundSetter + public void setContextSource(GitHubStatusContextSource contextSource) { + this.contextSource = contextSource; + } + @Override public void perform(@NonNull Run build, @NonNull FilePath workspace, @@ -64,7 +78,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( 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() From ab5830c47865ad04f8d1f8e18f4315df7c7bce35 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Mon, 21 Nov 2016 20:02:10 +0100 Subject: [PATCH 2/3] add readResolve method this to handle null-serialization --- .../cloudbees/jenkins/GitHubSetCommitStatusBuilder.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java index 9e70a7149..1a01e6acd 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java @@ -93,6 +93,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 From d32c3ad8be6b2495652d77bc106712a393cf7320 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Mon, 21 Nov 2016 20:02:25 +0100 Subject: [PATCH 3/3] add @since tags --- .../com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java index 1a01e6acd..b52ed1adc 100644 --- a/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java +++ b/src/main/java/com/cloudbees/jenkins/GitHubSetCommitStatusBuilder.java @@ -51,6 +51,7 @@ public ExpandableMessage getStatusMessage() { /** * @return Context provider + * @since FIXME */ public GitHubStatusContextSource getContextSource() { return contextSource; @@ -64,6 +65,9 @@ public void setStatusMessage(ExpandableMessage statusMessage) { this.statusMessage = statusMessage; } + /** + * @since FIXME + */ @DataBoundSetter public void setContextSource(GitHubStatusContextSource contextSource) { this.contextSource = contextSource;