Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] implement Repository Invitations API #437

Merged
merged 1 commit into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 45 additions & 0 deletions src/main/java/org/kohsuke/github/GHInvitation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.kohsuke.github;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class GHInvitation extends GHObject {
/*package almost final*/ GitHub root;

private int id;
private GHRepository repository;
private GHUser invitee, inviter;
private String permissions;
private String html_url;

/*package*/ GHInvitation wrapUp(GitHub root) {
this.root = root;
return this;
}

/**
* Accept a repository invitation.
*/
public void accept() throws IOException {
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
}

/**
* Decline a repository invitation.
*/
public void decline() throws IOException {
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
}

@Override
public URL getHtmlUrl() {
return GitHub.parseURL(html_url);
}
}
16 changes: 16 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,22 @@ public GHLabel createLabel(String name, String color) throws IOException {
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
}

/**
* Lists all the invitations.
*/
public PagedIterable<GHInvitation> listInvitations() {
return new PagedIterable<GHInvitation>() {
public PagedIterator<GHInvitation> _iterator(int pageSize) {
return new PagedIterator<GHInvitation>(root.retrieve().asIterator(String.format("/repos/%s/%s/invitations", getOwnerName(), name), GHInvitation[].class, pageSize)) {
protected void wrapUp(GHInvitation[] page) {
for (GHInvitation c : page)
c.wrapUp(root);
}
};
}
};
}

/**
* Lists all the subscribers (aka watchers.)
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/kohsuke/github/GitHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,15 @@ public GHLicense getLicense(String key) throws IOException {
}

/**
* Gets complete list of open invitations for current user.
*/
public List<GHInvitation> getMyInvitations() throws IOException {
GHInvitation[] invitations = retrieve().to("/user/repository_invitations", GHInvitation[].class);
for (GHInvitation i : invitations) {
i.wrapUp(this);
}
return Arrays.asList(invitations);
}

/**
* This method returns a shallowly populated organizations.
Expand Down