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 fe5ea52

Browse filesBrowse files
committed
[feature] implement Repository Invitations API
fixes hub4j#374
1 parent d61697a commit fe5ea52
Copy full SHA for fe5ea52

File tree

Expand file treeCollapse file tree

3 files changed

+70
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+70
-0
lines changed
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
import java.net.URL;
5+
import java.util.ArrayList;
6+
import java.util.Arrays;
7+
import java.util.Collection;
8+
import java.util.Collections;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.TreeMap;
12+
13+
public class GHInvitation extends GHObject {
14+
/*package almost final*/ GitHub root;
15+
16+
private int id;
17+
private GHRepository repository;
18+
private GHUser invitee, inviter;
19+
private String permissions;
20+
private String html_url;
21+
22+
/*package*/ GHInvitation wrapUp(GitHub root) {
23+
this.root = root;
24+
return this;
25+
}
26+
27+
/**
28+
* Accept a repository invitation.
29+
*/
30+
public void accept() throws IOException {
31+
root.retrieve().method("PATCH").to("/user/repository_invitations/" + id);
32+
}
33+
34+
/**
35+
* Decline a repository invitation.
36+
*/
37+
public void decline() throws IOException {
38+
root.retrieve().method("DELETE").to("/user/repository_invitations/" + id);
39+
}
40+
41+
@Override
42+
public URL getHtmlUrl() {
43+
return GitHub.parseURL(html_url);
44+
}
45+
}

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,22 @@ public GHLabel createLabel(String name, String color) throws IOException {
11371137
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
11381138
}
11391139

1140+
/**
1141+
* Lists all the invitations.
1142+
*/
1143+
public PagedIterable<GHInvitation> listInvitations() {
1144+
return new PagedIterable<GHInvitation>() {
1145+
public PagedIterator<GHInvitation> _iterator(int pageSize) {
1146+
return new PagedIterator<GHInvitation>(root.retrieve().asIterator(String.format("/repos/%s/%s/invitations", getOwnerName(), name), GHInvitation[].class, pageSize)) {
1147+
protected void wrapUp(GHInvitation[] page) {
1148+
for (GHInvitation c : page)
1149+
c.wrapUp(root);
1150+
}
1151+
};
1152+
}
1153+
};
1154+
}
1155+
11401156
/**
11411157
* Lists all the subscribers (aka watchers.)
11421158
*

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,15 @@ public GHLicense getLicense(String key) throws IOException {
530530
}
531531

532532
/**
533+
* Gets complete list of open invitations for current user.
534+
*/
535+
public List<GHInvitation> getMyInvitations() throws IOException {
536+
GHInvitation[] invitations = retrieve().to("/user/repository_invitations", GHInvitation[].class);
537+
for (GHInvitation i : invitations) {
538+
i.wrapUp(this);
539+
}
540+
return Arrays.asList(invitations);
541+
}
533542

534543
/**
535544
* This method returns a shallowly populated organizations.

0 commit comments

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