Skip to content

Commit 6bfeb54

Browse files
committed
Just exposing permission type enum until there's more to this relation than one property
1 parent ccb42d3 commit 6bfeb54

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/main/java/org/kohsuke/github/GHPermission.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424

2525
package org.kohsuke.github;
2626

27+
import java.util.Locale;
28+
2729
/**
2830
* Permission for a user in a repository.
2931
* @see <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API</a>
3032
*/
31-
public class GHPermission {
33+
/*package*/ class GHPermission {
3234

3335
private String permission;
3436
private GHUser user;
@@ -40,6 +42,10 @@ public String getPermission() {
4042
return permission;
4143
}
4244

45+
public GHPermissionType getPermissionType() {
46+
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
47+
}
48+
4349
public GHUser getUser() {
4450
return user;
4551
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.kohsuke.github;
2+
3+
/**
4+
* @author Kohsuke Kawaguchi
5+
*/
6+
public enum GHPermissionType {
7+
ADMIN,
8+
WRITE,
9+
READ,
10+
NONE
11+
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,19 @@ public Set<String> getCollaboratorNames() throws IOException {
486486
* @throws FileNotFoundException under some conditions (e.g., private repo you can see but are not an admin of); treat as unknown
487487
* @throws HttpException with a 403 under other conditions (e.g., public repo you have no special rights to); treat as unknown
488488
*/
489-
public GHPermission getPermission(String user) throws IOException {
489+
public GHPermissionType getPermission(String user) throws IOException {
490490
GHPermission perm = root.retrieve().withHeader("Accept", "application/vnd.github.korra-preview").to(getApiTailUrl("collaborators/" + user + "/permission"), GHPermission.class);
491491
perm.wrapUp(root);
492-
return perm;
492+
return perm.getPermissionType();
493+
}
494+
495+
/**
496+
* Obtain permission for a given user in this repository.
497+
* @throws FileNotFoundException under some conditions (e.g., private repo you can see but are not an admin of); treat as unknown
498+
* @throws HttpException with a 403 under other conditions (e.g., public repo you have no special rights to); treat as unknown
499+
*/
500+
public GHPermissionType getPermission(GHUser u) throws IOException {
501+
return getPermission(u.getLogin());
493502
}
494503

495504
/**

0 commit comments

Comments
 (0)