-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pipeline support #7
Changes from 19 commits
4554ac6
4021e61
da26987
143d3fe
30bf5f4
61c0c04
3dfead1
10181d3
df506b4
ef35458
f2104d5
d2d77da
32c685f
72b71ed
863ad53
8b40659
fe6a4e8
6df7598
c2643e4
463e1c1
f981ea8
16a3d3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
package io.jenkins.plugins.checks.steps; | ||
|
||
import edu.hm.hafner.util.VisibleForTesting; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.util.ListBoxModel; | ||
import io.jenkins.plugins.checks.api.*; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.jenkinsci.plugins.workflow.steps.*; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.*; | ||
|
||
/** | ||
* Pipeline step to publish customized checks. | ||
*/ | ||
@SuppressWarnings("PMD.DataClass") | ||
public class PublishChecksStep extends Step implements Serializable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
private String name = StringUtils.EMPTY; | ||
private String summary = StringUtils.EMPTY; | ||
private String title = StringUtils.EMPTY; | ||
private String text = StringUtils.EMPTY; | ||
private String detailsURL = StringUtils.EMPTY; | ||
private ChecksStatus status = ChecksStatus.COMPLETED; | ||
private ChecksConclusion conclusion = ChecksConclusion.SUCCESS; | ||
|
||
/** | ||
* Constructor used for pipeline by Stapler. | ||
*/ | ||
@DataBoundConstructor | ||
public PublishChecksStep() { | ||
super(); | ||
} | ||
|
||
@DataBoundSetter | ||
public void setName(final String name) { | ||
this.name = name; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setSummary(final String summary) { | ||
this.summary = summary; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setTitle(final String title) { | ||
this.title = title; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setText(final String text) { | ||
this.text = text; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setDetailsURL(final String detailsURL) { | ||
uhafner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.detailsURL = detailsURL; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setStatus(final ChecksStatus status) { | ||
this.status = status; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setConclusion(final ChecksConclusion conclusion) { | ||
this.conclusion = conclusion; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getSummary() { | ||
return summary; | ||
} | ||
|
||
public String getTitle() { | ||
return StringUtils.defaultIfEmpty(title, name); | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public String getDetailsURL() { | ||
return detailsURL; | ||
} | ||
|
||
public ChecksStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public ChecksConclusion getConclusion() { | ||
return conclusion; | ||
} | ||
|
||
@Override | ||
public StepExecution start(final StepContext stepContext) { | ||
return new PublishChecksStepExecution(stepContext, this); | ||
} | ||
|
||
/** | ||
* This step's descriptor which defines function name, display name, and context. | ||
*/ | ||
@Extension | ||
public static class PublishChecksStepDescriptor extends StepDescriptor { | ||
@Override | ||
public String getFunctionName() { | ||
return "publishChecks"; | ||
} | ||
|
||
@Override | ||
public Set<? extends Class<?>> getRequiredContext() { | ||
return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(Run.class, TaskListener.class))); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return "Publish customized checks to SCM platforms"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The text is shown in the Snippet Generator and Online Reference (and should be part of Messages) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional (since we have no I18n yet in the whole project): it would make sense to create a But we can postpone that part to the after GSoC work. |
||
} | ||
|
||
/** | ||
* Fill the dropdown list model with all {@link ChecksStatus}es. | ||
* | ||
* @return a model with all {@link ChecksStatus}es. | ||
*/ | ||
public ListBoxModel doFillStatusItems() { | ||
ListBoxModel options = new ListBoxModel(); | ||
for (ChecksStatus status : ChecksStatus.values()) { | ||
options.add(StringUtils.capitalize(status.name().toLowerCase(Locale.ENGLISH).replace("_", " ")), | ||
XiongKezhi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
status.name()); | ||
} | ||
|
||
return options; | ||
} | ||
|
||
/** | ||
* Fill the dropdown list model with all {@link ChecksConclusion}s. | ||
* | ||
* @return a model with all {@link ChecksConclusion}s. | ||
*/ | ||
public ListBoxModel doFillConclusionItems() { | ||
ListBoxModel options = new ListBoxModel(); | ||
for (ChecksConclusion conclusion : ChecksConclusion.values()) { | ||
options.add(StringUtils.capitalize(conclusion.name().toLowerCase(Locale.ENGLISH).replace("_", " ")), | ||
conclusion.name()); | ||
} | ||
|
||
return options; | ||
} | ||
} | ||
|
||
/** | ||
* This step's execution to actually publish checks. | ||
*/ | ||
static class PublishChecksStepExecution extends SynchronousNonBlockingStepExecution<Void> { | ||
private static final long serialVersionUID = 1L; | ||
private final PublishChecksStep step; | ||
|
||
PublishChecksStepExecution(final StepContext context, final PublishChecksStep step) { | ||
super(context); | ||
this.step = step; | ||
} | ||
|
||
@Override | ||
protected Void run() throws IOException, InterruptedException { | ||
ChecksPublisherFactory.fromRun(getContext().get(Run.class), getContext().get(TaskListener.class)) | ||
.publish(extractChecksDetails()); | ||
|
||
return null; | ||
} | ||
|
||
@VisibleForTesting | ||
ChecksDetails extractChecksDetails() { | ||
return new ChecksDetails.ChecksDetailsBuilder() | ||
.withName(step.getName()) | ||
.withStatus(step.getStatus()) | ||
.withConclusion(step.getConclusion()) | ||
.withDetailsURL(step.getDetailsURL()) | ||
.withOutput(new ChecksOutput.ChecksOutputBuilder() | ||
.withTitle(step.getTitle()) | ||
.withSummary(step.getSummary()) | ||
.withText(step.getText()) | ||
.build()) | ||
.build(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div> | ||
XiongKezhi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The conclusion of the check, can be "ACTION_REQUIRED", "SKIPPED", "CANCELED", "TIME_OUT", "FAILURE", "NEUTRAL", | ||
"SUCCESS" or "NONE". By default, "SUCCESS" will be used. When providing the conclusion other than "NONE", please | ||
make sure the status is "COMPLETED". | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to add
config.jelly
and*-help.html
files for the fields (you already have the text in the JavaDoc of theChecksOutput
classes). Then the online documentation (Snippet Generator and Online Reference) has some more details. You can open the Snippet Generator using the "Pipeline Syntax" link on a job page.