Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c6959c

Browse filesBrowse files
committed
Merge remote-tracking branch 'github-api/master' into tast/response-info
2 parents 90489e4 + ff3136d commit 0c6959c
Copy full SHA for 0c6959c
Expand file treeCollapse file tree

17 files changed

+891
-6
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ target
99
.DS_Store
1010

1111
dependency-reduced-pom.xml
12+
.factorypath
13+
.vscode/settings.json

‎pom.xml

Copy file name to clipboardExpand all lines: pom.xml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<plugin>
8383
<groupId>org.apache.maven.plugins</groupId>
8484
<artifactId>maven-shade-plugin</artifactId>
85-
<version>3.2.1</version>
85+
<version>3.2.2</version>
8686
<executions>
8787
<execution>
8888
<id>shaded-jar</id>

‎src/main/java/org/kohsuke/github/GHRepository.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+43-5Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
import com.fasterxml.jackson.annotation.JsonProperty;
2727
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
28+
import edu.umd.cs.findbugs.annotations.CheckForNull;
29+
import edu.umd.cs.findbugs.annotations.NonNull;
2830
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2931
import org.apache.commons.lang3.StringUtils;
3032

@@ -813,7 +815,7 @@ public GHPermissionType getPermission(String user) throws IOException {
813815
* Obtain permission for a given user in this repository.
814816
*
815817
* @param u
816-
* the u
818+
* the user
817819
* @return the permission
818820
* @throws IOException
819821
* the io exception
@@ -835,6 +837,20 @@ public Set<GHTeam> getTeams() throws IOException {
835837
root.getOrganization(getOwnerName())))));
836838
}
837839

840+
/**
841+
* Add collaborators.
842+
*
843+
* @param users
844+
* the users
845+
* @param permission
846+
* the permission level
847+
* @throws IOException
848+
* the io exception
849+
*/
850+
public void addCollaborators(GHOrganization.Permission permission, GHUser... users) throws IOException {
851+
addCollaborators(asList(users), permission);
852+
}
853+
838854
/**
839855
* Add collaborators.
840856
*
@@ -856,7 +872,21 @@ public void addCollaborators(GHUser... users) throws IOException {
856872
* the io exception
857873
*/
858874
public void addCollaborators(Collection<GHUser> users) throws IOException {
859-
modifyCollaborators(users, "PUT");
875+
modifyCollaborators(users, "PUT", null);
876+
}
877+
878+
/**
879+
* Add collaborators.
880+
*
881+
* @param users
882+
* the users
883+
* @param permission
884+
* the permission level
885+
* @throws IOException
886+
* the io exception
887+
*/
888+
public void addCollaborators(Collection<GHUser> users, GHOrganization.Permission permission) throws IOException {
889+
modifyCollaborators(users, "PUT", permission);
860890
}
861891

862892
/**
@@ -880,12 +910,20 @@ public void removeCollaborators(GHUser... users) throws IOException {
880910
* the io exception
881911
*/
882912
public void removeCollaborators(Collection<GHUser> users) throws IOException {
883-
modifyCollaborators(users, "DELETE");
913+
modifyCollaborators(users, "DELETE", null);
884914
}
885915

886-
private void modifyCollaborators(Collection<GHUser> users, String method) throws IOException {
916+
private void modifyCollaborators(@NonNull Collection<GHUser> users,
917+
@NonNull String method,
918+
@CheckForNull GHOrganization.Permission permission) throws IOException {
919+
Requester requester = root.createRequest().method(method);
920+
921+
if (permission != null) {
922+
requester = requester.with("permission", permission).inBody();
923+
}
924+
887925
for (GHUser user : users) {
888-
root.createRequest().method(method).withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
926+
requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
889927
}
890928
}
891929

‎src/test/java/org/kohsuke/github/GHRepositoryTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHRepositoryTest.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ public void LatestRepositoryExist() {
158158
}
159159
}
160160

161+
@Test
162+
public void addCollaborators() throws Exception {
163+
GHRepository repo = getRepository();
164+
GHUser user = getUser();
165+
List<GHUser> users = new ArrayList<GHUser>();
166+
167+
users.add(user);
168+
repo.addCollaborators(users, GHOrganization.Permission.PUSH);
169+
170+
GHPersonSet<GHUser> collabs = repo.getCollaborators();
171+
172+
GHUser colabUser = collabs.byLogin("jimmysombrero");
173+
174+
assertEquals(colabUser.getName(), user.getName());
175+
}
176+
161177
@Test
162178
public void LatestRepositoryNotExist() {
163179
try {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"login": "github-api-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/github-api-test-org",
6+
"repos_url": "https://api.github.com/orgs/github-api-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/github-api-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/github-api-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/github-api-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/github-api-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/github-api-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 10,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/github-api-test-org",
22+
"created_at": "2014-05-10T19:39:11Z",
23+
"updated_at": "2015-04-20T00:42:30Z",
24+
"type": "Organization"
25+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.