mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 15:49:57 +00:00
458 lines
16 KiB
HTML
458 lines
16 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>GHWorkflowRun.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">GitHub API for Java</a> > <a href="index.source.html" class="el_package">org.kohsuke.github</a> > <span class="el_source">GHWorkflowRun.java</span></div><h1>GHWorkflowRun.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.kohsuke.github.function.InputStreamFunction;
|
|
import org.kohsuke.github.internal.EnumUtils;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Objects;
|
|
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
/**
|
|
* A workflow run.
|
|
*
|
|
* @author Guillaume Smet
|
|
* @see GHRepository#getWorkflowRun(long)
|
|
*/
|
|
<span class="fc" id="L25">public class GHWorkflowRun extends GHObject {</span>
|
|
|
|
@JsonProperty("repository")
|
|
private GHRepository owner;
|
|
|
|
private String name;
|
|
private long runNumber;
|
|
private long workflowId;
|
|
|
|
private String htmlUrl;
|
|
private String jobsUrl;
|
|
private String logsUrl;
|
|
private String checkSuiteUrl;
|
|
private String artifactsUrl;
|
|
private String cancelUrl;
|
|
private String rerunUrl;
|
|
private String workflowUrl;
|
|
|
|
private String headBranch;
|
|
private String headSha;
|
|
private GHRepository headRepository;
|
|
private HeadCommit headCommit;
|
|
|
|
private String event;
|
|
private String status;
|
|
private String conclusion;
|
|
|
|
private GHPullRequest[] pullRequests;
|
|
|
|
/**
|
|
* The name of the workflow run.
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L60"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* The run number.
|
|
*
|
|
* @return the run number
|
|
*/
|
|
public long getRunNumber() {
|
|
<span class="fc" id="L69"> return runNumber;</span>
|
|
}
|
|
|
|
/**
|
|
* The workflow id.
|
|
*
|
|
* @return the workflow id
|
|
*/
|
|
public long getWorkflowId() {
|
|
<span class="fc" id="L78"> return workflowId;</span>
|
|
}
|
|
|
|
@Override
|
|
public URL getHtmlUrl() throws IOException {
|
|
<span class="fc" id="L83"> return GitHubClient.parseURL(htmlUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The jobs URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/jobs
|
|
*
|
|
* @return the jobs url
|
|
*/
|
|
public URL getJobsUrl() {
|
|
<span class="fc" id="L92"> return GitHubClient.parseURL(jobsUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The logs URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/logs
|
|
*
|
|
* @return the logs url
|
|
*/
|
|
public URL getLogsUrl() {
|
|
<span class="fc" id="L101"> return GitHubClient.parseURL(logsUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The check suite URL, like https://api.github.com/repos/octo-org/octo-repo/check-suites/414944374
|
|
*
|
|
* @return the check suite url
|
|
*/
|
|
public URL getCheckSuiteUrl() {
|
|
<span class="fc" id="L110"> return GitHubClient.parseURL(checkSuiteUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The artifacts URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/artifacts
|
|
*
|
|
* @return the artifacts url
|
|
*/
|
|
public URL getArtifactsUrl() {
|
|
<span class="fc" id="L119"> return GitHubClient.parseURL(artifactsUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The cancel URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/cancel
|
|
*
|
|
* @return the cancel url
|
|
*/
|
|
public URL getCancelUrl() {
|
|
<span class="fc" id="L128"> return GitHubClient.parseURL(cancelUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The rerun URL, like https://api.github.com/repos/octo-org/octo-repo/actions/runs/30433642/rerun
|
|
*
|
|
* @return the rerun url
|
|
*/
|
|
public URL getRerunUrl() {
|
|
<span class="fc" id="L137"> return GitHubClient.parseURL(rerunUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The workflow URL, like https://api.github.com/repos/octo-org/octo-repo/actions/workflows/159038
|
|
*
|
|
* @return the workflow url
|
|
*/
|
|
public URL getWorkflowUrl() {
|
|
<span class="fc" id="L146"> return GitHubClient.parseURL(workflowUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The head branch name the changes are on.
|
|
*
|
|
* @return head branch name
|
|
*/
|
|
public String getHeadBranch() {
|
|
<span class="fc" id="L155"> return headBranch;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the HEAD SHA.
|
|
*
|
|
* @return sha for the HEAD commit
|
|
*/
|
|
public String getHeadSha() {
|
|
<span class="fc" id="L164"> return headSha;</span>
|
|
}
|
|
|
|
/**
|
|
* The commit of current head.
|
|
*
|
|
* @return head commit
|
|
*/
|
|
public HeadCommit getHeadCommit() {
|
|
<span class="fc" id="L173"> return headCommit;</span>
|
|
}
|
|
|
|
/**
|
|
* The repository of current head.
|
|
*
|
|
* @return head repository
|
|
*/
|
|
public GHRepository getHeadRepository() {
|
|
<span class="fc" id="L182"> return headRepository;</span>
|
|
}
|
|
|
|
/**
|
|
* The type of event that triggered the build.
|
|
*
|
|
* @return type of event
|
|
*/
|
|
public GHEvent getEvent() {
|
|
<span class="fc" id="L191"> return EnumUtils.getNullableEnumOrDefault(GHEvent.class, event, GHEvent.UNKNOWN);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets status of the workflow run.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return status of the workflow run
|
|
*/
|
|
public Status getStatus() {
|
|
<span class="fc" id="L202"> return Status.from(status);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the conclusion of the workflow run.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return conclusion of the workflow run
|
|
*/
|
|
public Conclusion getConclusion() {
|
|
<span class="fc" id="L213"> return Conclusion.from(conclusion);</span>
|
|
}
|
|
|
|
/**
|
|
* Repository to which the workflow run belongs.
|
|
*
|
|
* @return the repository
|
|
*/
|
|
public GHRepository getRepository() {
|
|
<span class="fc" id="L222"> return owner;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the pull requests participated in this workflow run.
|
|
*
|
|
* Note this field is only populated for events. When getting a {@link GHWorkflowRun} outside of an event, this is
|
|
* always empty.
|
|
*
|
|
* @return the list of {@link GHPullRequest}s for this workflow run. Only populated for events.
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public List<GHPullRequest> getPullRequests() throws IOException {
|
|
<span class="pc bpc" id="L236" title="2 of 4 branches missed."> if (pullRequests != null && pullRequests.length != 0) {</span>
|
|
<span class="fc bfc" id="L237" title="All 2 branches covered."> for (GHPullRequest pullRequest : pullRequests) {</span>
|
|
// Only refresh if we haven't do so before
|
|
<span class="fc" id="L239"> pullRequest.refresh(pullRequest.getTitle());</span>
|
|
}
|
|
<span class="fc" id="L241"> return Collections.unmodifiableList(Arrays.asList(pullRequests));</span>
|
|
}
|
|
<span class="nc" id="L243"> return Collections.emptyList();</span>
|
|
}
|
|
|
|
/**
|
|
* Cancel the workflow run.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void cancel() throws IOException {
|
|
<span class="fc" id="L253"> root.createRequest().method("POST").withUrlPath(getApiRoute(), "cancel").fetchHttpStatusCode();</span>
|
|
<span class="fc" id="L254"> }</span>
|
|
|
|
/**
|
|
* Delete the workflow run.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void delete() throws IOException {
|
|
<span class="fc" id="L263"> root.createRequest().method("DELETE").withUrlPath(getApiRoute()).fetchHttpStatusCode();</span>
|
|
<span class="fc" id="L264"> }</span>
|
|
|
|
/**
|
|
* Rerun the workflow run.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void rerun() throws IOException {
|
|
<span class="fc" id="L273"> root.createRequest().method("POST").withUrlPath(getApiRoute(), "rerun").fetchHttpStatusCode();</span>
|
|
<span class="fc" id="L274"> }</span>
|
|
|
|
/**
|
|
* Lists the artifacts attached to this workflow run.
|
|
*
|
|
* @return the paged iterable
|
|
*/
|
|
public PagedIterable<GHArtifact> listArtifacts() {
|
|
<span class="fc" id="L282"> return new GHArtifactsIterable(owner, root.createRequest().withUrlPath(getApiRoute(), "artifacts"));</span>
|
|
}
|
|
|
|
/**
|
|
* Downloads the logs.
|
|
* <p>
|
|
* The logs are in the form of a zip archive.
|
|
* <p>
|
|
* Note that the archive is the same as the one downloaded from a workflow run so it contains the logs for all jobs.
|
|
*
|
|
* @param <T>
|
|
* the type of result
|
|
* @param streamFunction
|
|
* The {@link InputStreamFunction} that will process the stream
|
|
* @throws IOException
|
|
* The IO exception.
|
|
* @return the result of reading the stream.
|
|
*/
|
|
public <T> T downloadLogs(InputStreamFunction<T> streamFunction) throws IOException {
|
|
<span class="fc" id="L301"> requireNonNull(streamFunction, "Stream function must not be null");</span>
|
|
|
|
<span class="fc" id="L303"> return root.createRequest().method("GET").withUrlPath(getApiRoute(), "logs").fetchStream(streamFunction);</span>
|
|
}
|
|
|
|
/**
|
|
* Delete the logs.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void deleteLogs() throws IOException {
|
|
<span class="fc" id="L313"> root.createRequest().method("DELETE").withUrlPath(getApiRoute(), "logs").fetchHttpStatusCode();</span>
|
|
<span class="fc" id="L314"> }</span>
|
|
|
|
/**
|
|
* Returns the list of jobs of this workflow run for the last execution.
|
|
*
|
|
* @return list of jobs from the last execution
|
|
*/
|
|
public PagedIterable<GHWorkflowJob> listJobs() {
|
|
<span class="fc" id="L322"> return new GHWorkflowJobQueryBuilder(this).latest().list();</span>
|
|
}
|
|
|
|
/**
|
|
* Returns the list of jobs from all the executions of this workflow run.
|
|
*
|
|
* @return list of jobs from all the executions
|
|
*/
|
|
public PagedIterable<GHWorkflowJob> listAllJobs() {
|
|
<span class="fc" id="L331"> return new GHWorkflowJobQueryBuilder(this).all().list();</span>
|
|
}
|
|
|
|
private String getApiRoute() {
|
|
<span class="pc bpc" id="L335" title="1 of 2 branches missed."> if (owner == null) {</span>
|
|
// Workflow runs returned from search to do not have an owner. Attempt to use url.
|
|
<span class="nc" id="L337"> final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");</span>
|
|
<span class="nc" id="L338"> return StringUtils.prependIfMissing(url.toString().replace(root.getApiUrl(), ""), "/");</span>
|
|
|
|
}
|
|
<span class="fc" id="L341"> return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/runs/" + getId();</span>
|
|
}
|
|
|
|
GHWorkflowRun wrapUp(GHRepository owner) {
|
|
<span class="fc" id="L345"> this.owner = owner;</span>
|
|
<span class="fc" id="L346"> return wrapUp(owner.root);</span>
|
|
}
|
|
|
|
GHWorkflowRun wrapUp(GitHub root) {
|
|
<span class="fc" id="L350"> this.root = root;</span>
|
|
<span class="pc bpc" id="L351" title="1 of 2 branches missed."> if (owner != null) {</span>
|
|
<span class="fc" id="L352"> owner.wrap(root);</span>
|
|
<span class="pc bpc" id="L353" title="1 of 2 branches missed."> if (pullRequests != null) {</span>
|
|
<span class="fc bfc" id="L354" title="All 2 branches covered."> for (GHPullRequest singlePull : pullRequests) {</span>
|
|
<span class="fc" id="L355"> singlePull.wrap(owner);</span>
|
|
}
|
|
}
|
|
<span class="nc bnc" id="L358" title="All 2 branches missed."> } else if (pullRequests != null) {</span>
|
|
<span class="nc bnc" id="L359" title="All 2 branches missed."> for (GHPullRequest singlePull : pullRequests) {</span>
|
|
<span class="nc" id="L360"> singlePull.wrap(root);</span>
|
|
}
|
|
}
|
|
<span class="pc bpc" id="L363" title="1 of 2 branches missed."> if (headRepository != null) {</span>
|
|
<span class="fc" id="L364"> headRepository.wrap(root);</span>
|
|
}
|
|
<span class="fc" id="L366"> return this;</span>
|
|
}
|
|
|
|
<span class="fc" id="L369"> public static class HeadCommit {</span>
|
|
private String id;
|
|
private String treeId;
|
|
private String message;
|
|
private String timestamp;
|
|
private GitUser author;
|
|
private GitUser committer;
|
|
|
|
/**
|
|
* Gets id of the commit
|
|
*
|
|
* @return id of the commit
|
|
*/
|
|
public String getId() {
|
|
<span class="fc" id="L383"> return id;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets id of the tree.
|
|
*
|
|
* @return id of the tree
|
|
*/
|
|
public String getTreeId() {
|
|
<span class="fc" id="L392"> return treeId;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets message.
|
|
*
|
|
* @return commit message.
|
|
*/
|
|
public String getMessage() {
|
|
<span class="fc" id="L401"> return message;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets timestamp of the commit.
|
|
*
|
|
* @return timestamp of the commit
|
|
*/
|
|
public Date getTimestamp() {
|
|
<span class="fc" id="L410"> return GitHubClient.parseDate(timestamp);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets author.
|
|
*
|
|
* @return the author
|
|
*/
|
|
public GitUser getAuthor() {
|
|
<span class="fc" id="L419"> return author;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets committer.
|
|
*
|
|
* @return the committer
|
|
*/
|
|
public GitUser getCommitter() {
|
|
<span class="fc" id="L428"> return committer;</span>
|
|
}
|
|
}
|
|
|
|
<span class="fc" id="L432"> public static enum Status {</span>
|
|
<span class="fc" id="L433"> QUEUED, IN_PROGRESS, COMPLETED, UNKNOWN;</span>
|
|
|
|
public static Status from(String value) {
|
|
<span class="fc" id="L436"> return EnumUtils.getNullableEnumOrDefault(Status.class, value, Status.UNKNOWN);</span>
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
<span class="fc" id="L441"> return name().toLowerCase(Locale.ROOT);</span>
|
|
}
|
|
}
|
|
|
|
<span class="fc" id="L445"> public static enum Conclusion {</span>
|
|
<span class="fc" id="L446"> ACTION_REQUIRED, CANCELLED, FAILURE, NEUTRAL, SUCCESS, SKIPPED, STALE, TIMED_OUT, UNKNOWN;</span>
|
|
|
|
public static Conclusion from(String value) {
|
|
<span class="fc" id="L449"> return EnumUtils.getNullableEnumOrDefault(Conclusion.class, value, Conclusion.UNKNOWN);</span>
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
<span class="nc" id="L454"> return name().toLowerCase(Locale.ROOT);</span>
|
|
}
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html> |