Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jberglund-BSFT authored Oct 7, 2019
2 parents 88b006e + f0dc7d5 commit b163e68
Show file tree
Hide file tree
Showing 333 changed files with 317,978 additions and 1,171 deletions.
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
</properties>

<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/wiremock/**</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/org/kohsuke/github/GHLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import java.util.List;
import java.util.Objects;

import static org.kohsuke.github.Previews.SYMMETRA;
/**
* @author Kohsuke Kawaguchi
* @see GHIssue#getLabels()
* @see GHRepository#listLabels()
*/
public class GHLabel {
private String url, name, color;
private String url, name, color, description;
private GHRepository repo;

public String getUrl() {
Expand All @@ -30,6 +31,14 @@ public String getColor() {
return color;
}

/**
* Purpose of Label
*/
@Preview @Deprecated
public String getDescription() {
return description;
}

/*package*/ GHLabel wrapUp(GHRepository repo) {
this.repo = repo;
return this;
Expand All @@ -44,7 +53,26 @@ public void delete() throws IOException {
* 6-letter hex color code, like "f29513"
*/
public void setColor(String newColor) throws IOException {
repo.root.retrieve().method("PATCH").with("name", name).with("color", newColor).to(url);
repo.root.retrieve().method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", newColor)
.with("description", description)
.to(url);
}

/**
* @param newDescription
* Description of label
*/
@Preview @Deprecated
public void setDescription(String newDescription) throws IOException {
repo.root.retrieve().method("PATCH")
.withPreview(SYMMETRA)
.with("name", name)
.with("color", color)
.with("description", newDescription)
.to(url);
}

/*package*/ static Collection<String> toNames(Collection<GHLabel> labels) {
Expand Down
42 changes: 40 additions & 2 deletions src/main/java/org/kohsuke/github/GHOrganization.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static org.kohsuke.github.Previews.INERTIA;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -74,8 +75,7 @@ public PagedIterator<GHTeam> _iterator(int pageSize) {
return new PagedIterator<GHTeam>(root.retrieve().asIterator(String.format("/orgs/%s/teams", login), GHTeam[].class, pageSize)) {
@Override
protected void wrapUp(GHTeam[] page) {
for (GHTeam c : page)
c.wrapUp(GHOrganization.this);
GHTeam.wrapUp(page, GHOrganization.this);
}
};
}
Expand Down Expand Up @@ -193,6 +193,44 @@ public void conceal(GHUser u) throws IOException {
root.retrieve().method("DELETE").to("/orgs/" + login + "/public_members/" + u.getLogin(), null);
}

/**
* Returns the projects for this organization.
* @param status The status filter (all, open or closed).
*/
public PagedIterable<GHProject> listProjects(final GHProject.ProjectStateFilter status) throws IOException {
return new PagedIterable<GHProject>() {
public PagedIterator<GHProject> _iterator(int pageSize) {
return new PagedIterator<GHProject>(root.retrieve().withPreview(INERTIA)
.with("state", status)
.asIterator(String.format("/orgs/%s/projects", login), GHProject[].class, pageSize)) {
@Override
protected void wrapUp(GHProject[] page) {
for (GHProject c : page)
c.wrap(root);
}
};
}
};
}

/**
* Returns all open projects for the organization.
*/
public PagedIterable<GHProject> listProjects() throws IOException {
return listProjects(GHProject.ProjectStateFilter.OPEN);
}

/**
* Creates a project for the organization.
*/
public GHProject createProject(String name, String body) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("name", name)
.with("body", body)
.to(String.format("/orgs/%s/projects", login), GHProject.class).wrap(root);
}

public enum Permission { ADMIN, PUSH, PULL }

/**
Expand Down
189 changes: 189 additions & 0 deletions src/main/java/org/kohsuke/github/GHProject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/*
* 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.Previews.INERTIA;

/**
* A GitHub project.
* @see https://developer.github.com/v3/projects/
* @author Martin van Zijl
*/
public class GHProject extends GHObject {
protected GitHub root;
protected GHObject owner;

private String owner_url;
private String html_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 GHObject getOwner() throws IOException {
if(owner == null) {
try {
if(owner_url.contains("/orgs/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHOrganization.class).wrapUp(root);
} else if(owner_url.contains("/users/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHUser.class).wrapUp(root);
} else if(owner_url.contains("/repos/")) {
owner = root.retrieve().to(getOwnerUrl().getPath(), GHRepository.class).wrap(root);
}
} catch (FileNotFoundException e) {
return null;
}
}
return owner;
}

public URL getOwnerUrl() {
return GitHub.parseURL(owner_url);
}

public String getNode_id() {
return node_id;
}

public String getName() {
return name;
}

public String getBody() {
return body;
}

public int getNumber() {
return number;
}

public ProjectState getState() {
return Enum.valueOf(ProjectState.class, state.toUpperCase(Locale.ENGLISH));
}

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());
}

public PagedIterable<GHProjectColumn> listColumns() throws IOException {
final GHProject project = this;
return new PagedIterable<GHProjectColumn>() {
public PagedIterator<GHProjectColumn> _iterator(int pageSize) {
return new PagedIterator<GHProjectColumn>(root.retrieve().withPreview(INERTIA)
.asIterator(String.format("/projects/%d/columns", id), GHProjectColumn[].class, pageSize)) {
@Override
protected void wrapUp(GHProjectColumn[] page) {
for (GHProjectColumn c : page)
c.wrap(project);
}
};
}
};
}

public GHProjectColumn createColumn(String name) throws IOException {
return root.retrieve().method("POST")
.withPreview(INERTIA)
.with("name", name)
.to(String.format("/projects/%d/columns", id), GHProjectColumn.class).wrap(this);
}
}
Loading

0 comments on commit b163e68

Please sign in to comment.