mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-20 08:21:21 +00:00
257 lines
8.3 KiB
HTML
257 lines
8.3 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>GHWorkflowJob.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">GHWorkflowJob.java</span></div><h1>GHWorkflowJob.java</h1><pre class="source lang-java linenums">package org.kohsuke.github;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.kohsuke.github.GHWorkflowRun.Conclusion;
|
|
import org.kohsuke.github.GHWorkflowRun.Status;
|
|
import org.kohsuke.github.function.InputStreamFunction;
|
|
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
|
|
import static java.util.Objects.requireNonNull;
|
|
|
|
/**
|
|
* A workflow run job.
|
|
*
|
|
* @author Guillaume Smet
|
|
*/
|
|
<span class="fc" id="L23">public class GHWorkflowJob extends GHObject {</span>
|
|
|
|
// Not provided by the API.
|
|
@JsonIgnore
|
|
private GHRepository owner;
|
|
|
|
private String name;
|
|
|
|
private String headSha;
|
|
|
|
private String startedAt;
|
|
private String completedAt;
|
|
|
|
private String status;
|
|
private String conclusion;
|
|
|
|
private long runId;
|
|
|
|
private String htmlUrl;
|
|
private String checkRunUrl;
|
|
|
|
<span class="fc" id="L44"> private List<Step> steps = new ArrayList<>();</span>
|
|
|
|
/**
|
|
* The name of the job.
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L52"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the HEAD SHA.
|
|
*
|
|
* @return sha for the HEAD commit
|
|
*/
|
|
public String getHeadSha() {
|
|
<span class="fc" id="L61"> return headSha;</span>
|
|
}
|
|
|
|
/**
|
|
* When was this job started?
|
|
*
|
|
* @return start date
|
|
*/
|
|
public Date getStartedAt() {
|
|
<span class="fc" id="L70"> return GitHubClient.parseDate(startedAt);</span>
|
|
}
|
|
|
|
/**
|
|
* When was this job completed?
|
|
*
|
|
* @return completion date
|
|
*/
|
|
public Date getCompletedAt() {
|
|
<span class="fc" id="L79"> return GitHubClient.parseDate(completedAt);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets status of the job.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return status of the job
|
|
*/
|
|
public Status getStatus() {
|
|
<span class="fc" id="L90"> return Status.from(status);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the conclusion of the job.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return conclusion of the job
|
|
*/
|
|
public Conclusion getConclusion() {
|
|
<span class="fc" id="L101"> return Conclusion.from(conclusion);</span>
|
|
}
|
|
|
|
/**
|
|
* The run id.
|
|
*
|
|
* @return the run id
|
|
*/
|
|
public long getRunId() {
|
|
<span class="fc" id="L110"> return runId;</span>
|
|
}
|
|
|
|
@Override
|
|
public URL getHtmlUrl() {
|
|
<span class="fc" id="L115"> return GitHubClient.parseURL(htmlUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* The check run URL.
|
|
*
|
|
* @return the check run url
|
|
*/
|
|
public URL getCheckRunUrl() {
|
|
<span class="fc" id="L124"> return GitHubClient.parseURL(checkRunUrl);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the execution steps of this job.
|
|
*
|
|
* @return the execution steps
|
|
*/
|
|
public List<Step> getSteps() {
|
|
<span class="fc" id="L133"> return steps;</span>
|
|
}
|
|
|
|
/**
|
|
* Repository to which the job belongs.
|
|
*
|
|
* @return the repository
|
|
*/
|
|
public GHRepository getRepository() {
|
|
<span class="fc" id="L142"> return owner;</span>
|
|
}
|
|
|
|
/**
|
|
* Downloads the logs.
|
|
* <p>
|
|
* The logs are returned as a text file.
|
|
*
|
|
* @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="L159"> requireNonNull(streamFunction, "Stream function must not be null");</span>
|
|
|
|
<span class="fc" id="L161"> return root.createRequest().method("GET").withUrlPath(getApiRoute(), "logs").fetchStream(streamFunction);</span>
|
|
}
|
|
|
|
private String getApiRoute() {
|
|
<span class="pc bpc" id="L165" 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="L167"> final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");</span>
|
|
<span class="nc" id="L168"> return StringUtils.prependIfMissing(url.toString().replace(root.getApiUrl(), ""), "/");</span>
|
|
|
|
}
|
|
<span class="fc" id="L171"> return "/repos/" + owner.getOwnerName() + "/" + owner.getName() + "/actions/jobs/" + getId();</span>
|
|
}
|
|
|
|
GHWorkflowJob wrapUp(GHRepository owner) {
|
|
<span class="fc" id="L175"> this.owner = owner;</span>
|
|
<span class="fc" id="L176"> return wrapUp(owner.root);</span>
|
|
}
|
|
|
|
GHWorkflowJob wrapUp(GitHub root) {
|
|
<span class="fc" id="L180"> this.root = root;</span>
|
|
<span class="pc bpc" id="L181" title="1 of 2 branches missed."> if (owner != null) {</span>
|
|
<span class="fc" id="L182"> owner.wrap(root);</span>
|
|
}
|
|
<span class="fc" id="L184"> return this;</span>
|
|
}
|
|
|
|
<span class="fc" id="L187"> public static class Step {</span>
|
|
|
|
private String name;
|
|
private int number;
|
|
|
|
private String startedAt;
|
|
private String completedAt;
|
|
|
|
private String status;
|
|
private String conclusion;
|
|
|
|
/**
|
|
* Gets the name of the step.
|
|
*
|
|
* @return name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L204"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the sequential number of the step.
|
|
*
|
|
* @return number
|
|
*/
|
|
public int getNumber() {
|
|
<span class="fc" id="L213"> return number;</span>
|
|
}
|
|
|
|
/**
|
|
* When was this step started?
|
|
*
|
|
* @return start date
|
|
*/
|
|
public Date getStartedAt() {
|
|
<span class="fc" id="L222"> return GitHubClient.parseDate(startedAt);</span>
|
|
}
|
|
|
|
/**
|
|
* When was this step completed?
|
|
*
|
|
* @return completion date
|
|
*/
|
|
public Date getCompletedAt() {
|
|
<span class="fc" id="L231"> return GitHubClient.parseDate(completedAt);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets status of the step.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return status of the step
|
|
*/
|
|
public Status getStatus() {
|
|
<span class="fc" id="L242"> return Status.from(status);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets the conclusion of the step.
|
|
* <p>
|
|
* Can be {@code UNKNOWN} if the value returned by GitHub is unknown from the API.
|
|
*
|
|
* @return conclusion of the step
|
|
*/
|
|
public Conclusion getConclusion() {
|
|
<span class="fc" id="L253"> return Conclusion.from(conclusion);</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> |