Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
90301ae
Added ability to specify permissions for collaborators
Jan 23, 2020
9ab8bdf
formatted file
Jan 23, 2020
8792213
tried formatting the file once again.
Jan 23, 2020
3bf8bae
format fixed and validation passed
jimmysombrero Jan 24, 2020
ad683fe
Merge branch 'master' into collaborator-permissions
bitwiseman Jan 24, 2020
3e4f160
ran mvn clean install then the build commmand and build was successful
jimmysombrero Jan 25, 2020
7916600
updating local branch
jimmysombrero Jan 25, 2020
58c069e
Merge branch 'master' into collaborator-permissions
jimmysombrero Jan 25, 2020
0e310fa
Merge branch 'master' into collaborator-permissions
jimmysombrero Jan 28, 2020
c5cb16a
Merge branch 'master' into collaborator-permissions
bitwiseman Jan 31, 2020
6576bea
Added missing methods to keep the API from breaking
jimmysombrero Feb 2, 2020
205e5ab
Merge branch 'collaborator-permissions' of https://github.com/jimmyso…
jimmysombrero Feb 2, 2020
7214c7d
Merge branch 'master' into collaborator-permissions
jimmysombrero Feb 2, 2020
d767575
Added test for addCollaborators
jimmysombrero Feb 3, 2020
8bcad7b
Merge branch 'collaborator-permissions' of https://github.com/jimmyso…
jimmysombrero Feb 3, 2020
76919a8
Merge branch 'master' into collaborator-permissions
bitwiseman Feb 3, 2020
5a79940
fixed minor formatting issues
jimmysombrero Feb 5, 2020
b33fe9f
Merge branch 'collaborator-permissions' of https://github.com/jimmyso…
jimmysombrero Feb 5, 2020
dddcf62
finished suggested formatting changes
jimmysombrero Feb 6, 2020
54a059f
updated signatures for addCollaborators methods
jimmysombrero Feb 8, 2020
edc697d
fixed javadoc isues
jimmysombrero Feb 8, 2020
ab96596
Merge branch 'master' into collaborator-permissions
bitwiseman Feb 13, 2020
0400032
Merge branch 'master' into collaborator-permissions
bitwiseman Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ target
.DS_Store

dependency-reduced-pom.xml
.factorypath
.vscode/settings.json
48 changes: 43 additions & 5 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -813,7 +815,7 @@ public GHPermissionType getPermission(String user) throws IOException {
* Obtain permission for a given user in this repository.
*
* @param u
* the u
* the user
* @return the permission
* @throws IOException
* the io exception
Expand All @@ -835,6 +837,20 @@ public Set<GHTeam> getTeams() throws IOException {
root.getOrganization(getOwnerName())))));
}

/**
* Add collaborators.
*
* @param users
* the users
* @param permission
* the permission level
* @throws IOException
* the io exception
*/
public void addCollaborators(GHOrganization.Permission permission, GHUser... users) throws IOException {
addCollaborators(asList(users), permission);
}

/**
* Add collaborators.
*
Expand All @@ -856,7 +872,21 @@ public void addCollaborators(GHUser... users) throws IOException {
* the io exception
*/
public void addCollaborators(Collection<GHUser> users) throws IOException {
modifyCollaborators(users, "PUT");
modifyCollaborators(users, "PUT", null);
}

/**
* Add collaborators.
*
* @param users
* the users
* @param permission
* the permission level
* @throws IOException
* the io exception
*/
public void addCollaborators(Collection<GHUser> users, GHOrganization.Permission permission) throws IOException {
modifyCollaborators(users, "PUT", permission);
}

/**
Expand All @@ -880,12 +910,20 @@ public void removeCollaborators(GHUser... users) throws IOException {
* the io exception
*/
public void removeCollaborators(Collection<GHUser> users) throws IOException {
modifyCollaborators(users, "DELETE");
modifyCollaborators(users, "DELETE", null);
}

private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
private void modifyCollaborators(@NonNull Collection<GHUser> users,
@NonNull String method,
@CheckForNull GHOrganization.Permission permission) throws IOException {
Requester requester = root.createRequest().method(method);

if (permission != null) {
requester = requester.with("permission", permission).inBody();
}

for (GHUser user : users) {
root.createRequest().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ public void LatestRepositoryExist() {
}
}

@Test
public void addCollaborators() throws Exception {
GHRepository repo = getRepository();
GHUser user = getUser();
List<GHUser> users = new ArrayList<GHUser>();

users.add(user);
repo.addCollaborators(users, GHOrganization.Permission.PUSH);

GHPersonSet<GHUser> collabs = repo.getCollaborators();

GHUser colabUser = collabs.byLogin("jimmysombrero");

assertEquals(colabUser.getName(), user.getName());
}

@Test
public void LatestRepositoryNotExist() {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"login": "github-api-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/github-api-test-org",
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 10,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/github-api-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization"
}
Loading