Skip to content

Commit

Permalink
add field for setting context for pending step (#159)
Browse files Browse the repository at this point in the history
* add field for setting context for pending step

* add readResolve method

this to handle null-serialization

* add @SInCE tags
  • Loading branch information
koenpunt authored and lanwen committed Nov 23, 2016
1 parent d046eaa commit 251aa3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -47,6 +49,14 @@ public ExpandableMessage getStatusMessage() {
return statusMessage;
}

/**
* @return Context provider
* @since FIXME
*/
public GitHubStatusContextSource getContextSource() {
return contextSource;
}

/**
* @since 1.14.1
*/
Expand All @@ -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,
Expand All @@ -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.<StatusErrorHandler>singletonList(new ShallowAnyErrorHandler()));

setter.setStatusResultSource(new ConditionalStatusResultSource(
Expand All @@ -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<Builder> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 251aa3a

Please sign in to comment.