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 762a32e

Browse filesBrowse files
committed
Added repository watch listing
1 parent 541dac1 commit 762a32e
Copy full SHA for 762a32e

File tree

Expand file treeCollapse file tree

4 files changed

+63
-5
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+63
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+21-3Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public List<GHHook> getHooks() throws IOException {
585585
}
586586

587587
public GHHook getHook(int id) throws IOException {
588-
return root.retrieve().to(getApiTailUrl("hooks/"+id), GHHook.class).wrap(this);
588+
return root.retrieve().to(getApiTailUrl("hooks/" + id), GHHook.class).wrap(this);
589589
}
590590

591591
/**
@@ -790,6 +790,24 @@ public GHLabel createLabel(String name, String color) throws IOException {
790790
.to(getApiTailUrl("labels"), GHLabel.class).wrapUp(this);
791791
}
792792

793+
/**
794+
* Lists all the subscribers (aka watchers.)
795+
*
796+
* https://developer.github.com/v3/activity/watching/
797+
*/
798+
public PagedIterable<GHUser> listSubscribers() {
799+
return new PagedIterable<GHUser>() {
800+
public PagedIterator<GHUser> iterator() {
801+
return new PagedIterator<GHUser>(root.retrieve().asIterator(getApiTailUrl("subscribers"), GHUser[].class)) {
802+
protected void wrapUp(GHUser[] page) {
803+
for (GHUser c : page)
804+
c.wrapUp(root);
805+
}
806+
};
807+
}
808+
};
809+
}
810+
793811
/**
794812
*
795813
* See https://api.github.com/hooks for possible names and their configuration scheme.
@@ -968,7 +986,7 @@ public GHContent getFileContent(String path) throws IOException {
968986

969987
public GHContent getFileContent(String path, String ref) throws IOException {
970988
Requester requester = root.retrieve();
971-
String target = getApiTailUrl("contents/"+path);
989+
String target = getApiTailUrl("contents/" + path);
972990

973991
if (ref != null)
974992
target = target + "?ref=" + ref;
@@ -982,7 +1000,7 @@ public List<GHContent> getDirectoryContent(String path) throws IOException {
9821000

9831001
public List<GHContent> getDirectoryContent(String path, String ref) throws IOException {
9841002
Requester requester = root.retrieve();
985-
String target = getApiTailUrl("contents/"+path);
1003+
String target = getApiTailUrl("contents/" + path);
9861004

9871005
if (ref != null)
9881006
target = target + "?ref=" + ref;

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHUser.java
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ public GHPersonSet<GHUser> getFollowers() throws IOException {
6969
return new GHPersonSet<GHUser>(Arrays.asList(wrap(followers,root)));
7070
}
7171

72+
/**
73+
* Lists all the subscribed (aka watched) repositories.
74+
*
75+
* https://developer.github.com/v3/activity/watching/
76+
*/
77+
public PagedIterable<GHRepository> listSubscriptions() {
78+
return new PagedIterable<GHRepository>() {
79+
public PagedIterator<GHRepository> iterator() {
80+
return new PagedIterator<GHRepository>(root.retrieve().asIterator(getApiTailUrl("subscriptions"), GHRepository[].class)) {
81+
protected void wrapUp(GHRepository[] page) {
82+
for (GHRepository c : page)
83+
c.wrap(root);
84+
}
85+
};
86+
}
87+
};
88+
}
89+
7290
/**
7391
* Returns true if this user belongs to the specified organization.
7492
*/
@@ -162,4 +180,9 @@ public boolean equals(Object obj) {
162180
}
163181
return false;
164182
}
183+
184+
String getApiTailUrl(String tail) {
185+
if (tail.length()>0 && !tail.startsWith("/")) tail='/'+tail;
186+
return "/users/" + login + tail;
187+
}
165188
}

‎src/test/java/org/kohsuke/github/AppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/AppTest.java
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,25 @@ public void testRepoLabel() throws IOException {
690690
}
691691
}
692692

693+
@Test
694+
public void testSubscribers() throws IOException {
695+
boolean kohsuke = false;
696+
GHRepository mr = gitHub.getRepository("kohsuke/github-api");
697+
for (GHUser u : mr.listSubscribers()) {
698+
System.out.println(u.getLogin());
699+
kohsuke |= u.getLogin().equals("kohsuke");
700+
}
701+
assertTrue(kohsuke);
702+
System.out.println("---");
703+
704+
boolean githubApi = false;
705+
for (GHRepository r : gitHub.getUser("kohsuke").listRepositories()) {
706+
System.out.println(r.getName());
707+
githubApi |= r.equals(mr);
708+
}
709+
assertTrue(githubApi);
710+
}
711+
693712
private void kohsuke() {
694713
String login = getUser().getLogin();
695714
Assume.assumeTrue(login.equals("kohsuke") || login.equals("kohsuke2"));

‎src/test/java/org/kohsuke/github/RepositoryTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/RepositoryTest.java
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,5 @@ protected void wrapUp(GHUser[] page) {
8585
Assert.assertTrue(returnIterator2.hasNext());
8686
user = returnIterator1.next();
8787
Assert.assertEquals(user, user2);
88-
89-
9088
}
9189
}

0 commit comments

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