mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-14 08:21:22 +00:00
314 lines
12 KiB
HTML
314 lines
12 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>GHProject.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">GHProject.java</span></div><h1>GHProject.java</h1><pre class="source lang-java linenums">/*
|
|
* The MIT License
|
|
*
|
|
* Copyright 2018 Martin van Zijl.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
package org.kohsuke.github;
|
|
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import java.util.Locale;
|
|
|
|
import static org.kohsuke.github.internal.Previews.INERTIA;
|
|
|
|
/**
|
|
* A GitHub project.
|
|
*
|
|
* @author Martin van Zijl
|
|
* @see <a href="https://developer.github.com/v3/projects/">Projects</a>
|
|
*/
|
|
<span class="fc" id="L39">public class GHProject extends GHObject {</span>
|
|
protected GHObject owner;
|
|
|
|
private String owner_url;
|
|
private String html_url;
|
|
private String name;
|
|
private String body;
|
|
private int number;
|
|
private String state;
|
|
private GHUser creator;
|
|
|
|
@Override
|
|
public URL getHtmlUrl() throws IOException {
|
|
<span class="nc" id="L52"> return GitHubClient.parseURL(html_url);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets root.
|
|
*
|
|
* @return the root
|
|
*/
|
|
public GitHub getRoot() {
|
|
<span class="nc" id="L61"> return root;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets owner.
|
|
*
|
|
* @return the owner
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHObject getOwner() throws IOException {
|
|
<span class="nc bnc" id="L72" title="All 2 branches missed."> if (owner == null) {</span>
|
|
try {
|
|
<span class="nc bnc" id="L74" title="All 2 branches missed."> if (owner_url.contains("/orgs/")) {</span>
|
|
<span class="nc" id="L75"> owner = root.createRequest()</span>
|
|
<span class="nc" id="L76"> .withUrlPath(getOwnerUrl().getPath())</span>
|
|
<span class="nc" id="L77"> .fetch(GHOrganization.class)</span>
|
|
<span class="nc" id="L78"> .wrapUp(root);</span>
|
|
<span class="nc bnc" id="L79" title="All 2 branches missed."> } else if (owner_url.contains("/users/")) {</span>
|
|
<span class="nc" id="L80"> owner = root.createRequest().withUrlPath(getOwnerUrl().getPath()).fetch(GHUser.class).wrapUp(root);</span>
|
|
<span class="nc bnc" id="L81" title="All 2 branches missed."> } else if (owner_url.contains("/repos/")) {</span>
|
|
<span class="nc" id="L82"> String[] pathElements = getOwnerUrl().getPath().split("/");</span>
|
|
<span class="nc" id="L83"> owner = GHRepository.read(root, pathElements[1], pathElements[2]);</span>
|
|
}
|
|
<span class="nc" id="L85"> } catch (FileNotFoundException e) {</span>
|
|
<span class="nc" id="L86"> return null;</span>
|
|
<span class="nc" id="L87"> }</span>
|
|
}
|
|
<span class="nc" id="L89"> return owner;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets owner url.
|
|
*
|
|
* @return the owner url
|
|
*/
|
|
public URL getOwnerUrl() {
|
|
<span class="nc" id="L98"> return GitHubClient.parseURL(owner_url);</span>
|
|
}
|
|
|
|
/**
|
|
* Gets node id.
|
|
*
|
|
* @deprecated Use {@link GHObject#getNodeId()}
|
|
* @return the node id
|
|
*/
|
|
@Deprecated
|
|
public String getNode_id() {
|
|
<span class="nc" id="L109"> return getNodeId();</span>
|
|
}
|
|
|
|
/**
|
|
* Gets name.
|
|
*
|
|
* @return the name
|
|
*/
|
|
public String getName() {
|
|
<span class="fc" id="L118"> return name;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets body.
|
|
*
|
|
* @return the body
|
|
*/
|
|
public String getBody() {
|
|
<span class="fc" id="L127"> return body;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets number.
|
|
*
|
|
* @return the number
|
|
*/
|
|
public int getNumber() {
|
|
<span class="nc" id="L136"> return number;</span>
|
|
}
|
|
|
|
/**
|
|
* Gets state.
|
|
*
|
|
* @return the state
|
|
*/
|
|
public ProjectState getState() {
|
|
<span class="fc" id="L145"> return Enum.valueOf(ProjectState.class, state.toUpperCase(Locale.ENGLISH));</span>
|
|
}
|
|
|
|
/**
|
|
* Gets creator.
|
|
*
|
|
* @return the creator
|
|
*/
|
|
public GHUser getCreator() {
|
|
<span class="nc" id="L154"> return creator;</span>
|
|
}
|
|
|
|
/**
|
|
* Wrap gh project.
|
|
*
|
|
* @param repo
|
|
* the repo
|
|
* @return the gh project
|
|
*/
|
|
public GHProject wrap(GHRepository repo) {
|
|
<span class="nc" id="L165"> this.owner = repo;</span>
|
|
<span class="nc" id="L166"> this.root = repo.root;</span>
|
|
<span class="nc" id="L167"> return this;</span>
|
|
}
|
|
|
|
/**
|
|
* Wrap gh project.
|
|
*
|
|
* @param root
|
|
* the root
|
|
* @return the gh project
|
|
*/
|
|
public GHProject wrap(GitHub root) {
|
|
<span class="fc" id="L178"> this.root = root;</span>
|
|
<span class="fc" id="L179"> return this;</span>
|
|
}
|
|
|
|
private void edit(String key, Object value) throws IOException {
|
|
<span class="fc" id="L183"> root.createRequest().method("PATCH").withPreview(INERTIA).with(key, value).withUrlPath(getApiRoute()).send();</span>
|
|
<span class="fc" id="L184"> }</span>
|
|
|
|
/**
|
|
* Gets api route.
|
|
*
|
|
* @return the api route
|
|
*/
|
|
protected String getApiRoute() {
|
|
<span class="fc" id="L192"> return "/projects/" + getId();</span>
|
|
}
|
|
|
|
/**
|
|
* Sets name.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setName(String name) throws IOException {
|
|
<span class="fc" id="L204"> edit("name", name);</span>
|
|
<span class="fc" id="L205"> }</span>
|
|
|
|
/**
|
|
* Sets body.
|
|
*
|
|
* @param body
|
|
* the body
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setBody(String body) throws IOException {
|
|
<span class="fc" id="L216"> edit("body", body);</span>
|
|
<span class="fc" id="L217"> }</span>
|
|
|
|
/**
|
|
* The enum ProjectState.
|
|
*/
|
|
<span class="fc" id="L222"> public enum ProjectState {</span>
|
|
<span class="fc" id="L223"> OPEN, CLOSED</span>
|
|
}
|
|
|
|
/**
|
|
* Sets state.
|
|
*
|
|
* @param state
|
|
* the state
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setState(ProjectState state) throws IOException {
|
|
<span class="fc" id="L235"> edit("state", state.toString().toLowerCase());</span>
|
|
<span class="fc" id="L236"> }</span>
|
|
|
|
/**
|
|
* The enum ProjectStateFilter.
|
|
*/
|
|
<span class="fc" id="L241"> public static enum ProjectStateFilter {</span>
|
|
<span class="fc" id="L242"> ALL, OPEN, CLOSED</span>
|
|
}
|
|
|
|
/**
|
|
* Set the permission level that all members of the project's organization will have on this project. Only
|
|
* applicable for organization-owned projects.
|
|
*
|
|
* @param permission
|
|
* the permission
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setOrganizationPermission(GHPermissionType permission) throws IOException {
|
|
<span class="nc" id="L255"> edit("organization_permission", permission.toString().toLowerCase());</span>
|
|
<span class="nc" id="L256"> }</span>
|
|
|
|
/**
|
|
* Sets visibility of the project within the organization. Only applicable for organization-owned projects.
|
|
*
|
|
* @param isPublic
|
|
* the is public
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void setPublic(boolean isPublic) throws IOException {
|
|
<span class="nc" id="L267"> edit("public", isPublic);</span>
|
|
<span class="nc" id="L268"> }</span>
|
|
|
|
/**
|
|
* Delete.
|
|
*
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public void delete() throws IOException {
|
|
<span class="fc" id="L277"> root.createRequest().withPreview(INERTIA).method("DELETE").withUrlPath(getApiRoute()).send();</span>
|
|
<span class="fc" id="L278"> }</span>
|
|
|
|
/**
|
|
* List columns paged iterable.
|
|
*
|
|
* @return the paged iterable
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public PagedIterable<GHProjectColumn> listColumns() throws IOException {
|
|
<span class="nc" id="L288"> final GHProject project = this;</span>
|
|
<span class="nc" id="L289"> return root.createRequest()</span>
|
|
<span class="nc" id="L290"> .withPreview(INERTIA)</span>
|
|
<span class="nc" id="L291"> .withUrlPath(String.format("/projects/%d/columns", getId()))</span>
|
|
<span class="nc" id="L292"> .toIterable(GHProjectColumn[].class, item -> item.wrap(project));</span>
|
|
}
|
|
|
|
/**
|
|
* Create column gh project column.
|
|
*
|
|
* @param name
|
|
* the name
|
|
* @return the gh project column
|
|
* @throws IOException
|
|
* the io exception
|
|
*/
|
|
public GHProjectColumn createColumn(String name) throws IOException {
|
|
<span class="fc" id="L305"> return root.createRequest()</span>
|
|
<span class="fc" id="L306"> .method("POST")</span>
|
|
<span class="fc" id="L307"> .withPreview(INERTIA)</span>
|
|
<span class="fc" id="L308"> .with("name", name)</span>
|
|
<span class="fc" id="L309"> .withUrlPath(String.format("/projects/%d/columns", getId()))</span>
|
|
<span class="fc" id="L310"> .fetch(GHProjectColumn.class)</span>
|
|
<span class="fc" id="L311"> .wrap(this);</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> |