forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* 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.IOException; | ||
import java.net.URL; | ||
import static org.kohsuke.github.Previews.INERTIA; | ||
|
||
/** | ||
* A GitHub project. | ||
* @see https://developer.github.com/v3/projects/ | ||
* @author Martin van Zijl | ||
*/ | ||
public class GHProject extends GHObject { | ||
private GitHub root; | ||
private GHRepository owner; | ||
|
||
private String owner_url; | ||
private String html_url; | ||
private String columns_url; | ||
private String node_id; | ||
private String name; | ||
private String body; | ||
private int number; | ||
private String state; | ||
private GHUser creator; | ||
|
||
@Override | ||
public URL getHtmlUrl() throws IOException { | ||
return GitHub.parseURL(html_url); | ||
} | ||
|
||
public GitHub getRoot() { | ||
return root; | ||
} | ||
|
||
public GHRepository getOwner() { | ||
return owner; | ||
} | ||
|
||
public String getOwner_url() { | ||
return owner_url; | ||
} | ||
|
||
public String getHtml_url() { | ||
return html_url; | ||
} | ||
|
||
public String getColumns_url() { | ||
return columns_url; | ||
} | ||
|
||
public String getNode_id() { | ||
return node_id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getBody() { | ||
return body; | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public GHUser getCreator() { | ||
return creator; | ||
} | ||
|
||
public GHProject wrap(GHRepository repo) { | ||
this.owner = repo; | ||
this.root = repo.root; | ||
return this; | ||
} | ||
|
||
public GHProject wrap(GitHub root) { | ||
this.root = root; | ||
return this; | ||
} | ||
|
||
private void edit(String key, Object value) throws IOException { | ||
new Requester(root).withPreview(INERTIA)._with(key, value).method("PATCH").to(getApiRoute()); | ||
} | ||
|
||
protected String getApiRoute() { | ||
return "/projects/" + id; | ||
} | ||
|
||
public void setName(String name) throws IOException { | ||
edit("name", name); | ||
} | ||
|
||
public void setBody(String body) throws IOException { | ||
edit("body", body); | ||
} | ||
|
||
public enum ProjectState { | ||
OPEN, | ||
CLOSED | ||
} | ||
|
||
public void setState(ProjectState state) throws IOException { | ||
edit("state", state.toString().toLowerCase()); | ||
} | ||
|
||
public static enum ProjectStateFilter { | ||
ALL, | ||
OPEN, | ||
CLOSED | ||
} | ||
|
||
/** | ||
* Set the permission level that all members of the project's organization will have on this project. | ||
* Only applicable for organization-owned projects. | ||
*/ | ||
public void setOrganizationPermission(GHPermissionType permission) throws IOException { | ||
edit("organization_permission", permission.toString().toLowerCase()); | ||
} | ||
|
||
/** | ||
* Sets visibility of the project within the organization. | ||
* Only applicable for organization-owned projects. | ||
*/ | ||
public void setPublic(boolean isPublic) throws IOException { | ||
edit("public", isPublic); | ||
} | ||
|
||
public void delete() throws IOException { | ||
new Requester(root).withPreview(INERTIA).method("DELETE").to(getApiRoute()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters