Just exposing permission type enum until there's more to this relation than one property

This commit is contained in:
Kohsuke Kawaguchi
2017-01-09 16:14:30 -08:00
parent ccb42d3249
commit 6bfeb54f3c
3 changed files with 29 additions and 3 deletions

View File

@@ -24,11 +24,13 @@
package org.kohsuke.github;
import java.util.Locale;
/**
* Permission for a user in a repository.
* @see <a href="https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level">API</a>
*/
public class GHPermission {
/*package*/ class GHPermission {
private String permission;
private GHUser user;
@@ -40,6 +42,10 @@ public class GHPermission {
return permission;
}
public GHPermissionType getPermissionType() {
return Enum.valueOf(GHPermissionType.class, permission.toUpperCase(Locale.ENGLISH));
}
public GHUser getUser() {
return user;
}

View File

@@ -0,0 +1,11 @@
package org.kohsuke.github;
/**
* @author Kohsuke Kawaguchi
*/
public enum GHPermissionType {
ADMIN,
WRITE,
READ,
NONE
}

View File

@@ -486,10 +486,19 @@ public class GHRepository extends GHObject {
* @throws FileNotFoundException under some conditions (e.g., private repo you can see but are not an admin of); treat as unknown
* @throws HttpException with a 403 under other conditions (e.g., public repo you have no special rights to); treat as unknown
*/
public GHPermission getPermission(String user) throws IOException {
public GHPermissionType getPermission(String user) throws IOException {
GHPermission perm = root.retrieve().withHeader("Accept", "application/vnd.github.korra-preview").to(getApiTailUrl("collaborators/" + user + "/permission"), GHPermission.class);
perm.wrapUp(root);
return perm;
return perm.getPermissionType();
}
/**
* Obtain permission for a given user in this repository.
* @throws FileNotFoundException under some conditions (e.g., private repo you can see but are not an admin of); treat as unknown
* @throws HttpException with a 403 under other conditions (e.g., public repo you have no special rights to); treat as unknown
*/
public GHPermissionType getPermission(GHUser u) throws IOException {
return getPermission(u.getLogin());
}
/**