Skip to content

Commit

Permalink
Merge pull request #1532 from ShalomGottesman/master
Browse files Browse the repository at this point in the history
add collaborator with permissions
  • Loading branch information
amihaiemil authored May 28, 2020
2 parents 81e4681 + 2ce2bd2 commit 287c236
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/java/com/jcabi/github/Collaborators.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,24 @@ public interface Collaborators {
*/
void add(String user) throws IOException;

/**
* Permission levels a user can be granted in an organization repository.
*
* @see <a href="https://developer.github.com/v3/repos/collaborators/#parameters-1">Add user with permissions</a>
*/
static enum Permission { PULL, PUSH, ADMIN, MAINTAIN, TRIAGE };

/**
* Add user with permissions. Only works on an organization repository
*
* @param user User to add
* @param permission Permission level to grant
* @throws IOException if there is an I/O problem
* @see <a href=https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator">Add user as a collaborator</a>
*/
void addWithPermission(
String user, Permission permission) throws IOException;

/**
* Remove user as a collaborator.
*
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/jcabi/github/RtCollaborators.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.jcabi.http.response.RestResponse;
import java.io.IOException;
import java.net.HttpURLConnection;
import javax.json.Json;
import javax.json.JsonObject;
import lombok.EqualsAndHashCode;
import org.hamcrest.Matchers;
Expand Down Expand Up @@ -122,6 +123,20 @@ public void add(
);
}

@Override
public void addWithPermission(
final String user, final Permission permission
) throws IOException {
final JsonObject obj = Json.createObjectBuilder()
.add("permission", permission.toString().toLowerCase())
.build();
this.request.method(Request.PUT)
.body().set(obj).back()
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_CREATED);
}

@Override
public void remove(
final String user
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/jcabi/github/mock/MkCollaborators.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.jcabi.github.User;
import com.jcabi.xml.XML;
import java.io.IOException;
import org.apache.commons.lang3.NotImplementedException;
import org.xembly.Directives;

/**
Expand Down Expand Up @@ -146,6 +147,13 @@ public User map(final XML xml) {
);
}

@Override
public void addWithPermission(
final String user, final Permission permission
) throws IOException {
throw new NotImplementedException("");
}

/**
* Gets a mocked User.
* @param login User login
Expand Down

0 comments on commit 287c236

Please sign in to comment.