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 a8cf4a7

Browse filesBrowse files
committed
Added watch API support.
Fixes issue hub4j#130
1 parent 60dce94 commit a8cf4a7
Copy full SHA for a8cf4a7

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+113
-0
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
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,30 @@ public List<GHDeployKey> getDeployKeys() throws IOException{
10691069
h.wrap(this);
10701070
return list;
10711071
}
1072+
1073+
/**
1074+
* Subscribes to this repository to get notifications.
1075+
*/
1076+
public GHSubscription subscribe(boolean subscribed, boolean ignored) throws IOException {
1077+
return new Requester(root)
1078+
.with("subscribed", subscribed)
1079+
.with("ignored", ignored)
1080+
.method("PUT").to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this);
1081+
}
1082+
1083+
/**
1084+
* Returns the current subscription.
1085+
*
1086+
* @return null if no subscription exists.
1087+
*/
1088+
public GHSubscription getSubscription() throws IOException {
1089+
try {
1090+
return new Requester(root).to(getApiTailUrl("subscription"), GHSubscription.class).wrapUp(this);
1091+
} catch (FileNotFoundException e) {
1092+
return null;
1093+
}
1094+
}
1095+
10721096

10731097

10741098

+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
import java.util.Date;
5+
6+
/**
7+
* Represents your subscribing to a repository.
8+
*
9+
* @author Kohsuke Kawaguchi
10+
*/
11+
public class GHSubscription {
12+
private String created_at, url, repository_url, reason;
13+
private boolean subscribed, ignored;
14+
15+
private GitHub root;
16+
private GHRepository repo;
17+
18+
public Date getCreatedAt() {
19+
return GitHub.parseDate(created_at);
20+
}
21+
22+
public String getUrl() {
23+
return url;
24+
}
25+
26+
public String getRepositoryUrl() {
27+
return repository_url;
28+
}
29+
30+
public String getReason() {
31+
return reason;
32+
}
33+
34+
public boolean isSubscribed() {
35+
return subscribed;
36+
}
37+
38+
public boolean isIgnored() {
39+
return ignored;
40+
}
41+
42+
public GHRepository getRepository() {
43+
return repo;
44+
}
45+
46+
/**
47+
* Removes this subscription.
48+
*/
49+
public void delete() throws IOException {
50+
new Requester(root).method("DELETE").to(url);
51+
}
52+
53+
GHSubscription wrapUp(GHRepository repo) {
54+
this.repo = repo;
55+
return wrapUp(repo.root);
56+
}
57+
58+
GHSubscription wrapUp(GitHub root) {
59+
this.root = root;
60+
return this;
61+
}
62+
}
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.kohsuke.github;
2+
3+
import org.junit.Test;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* @author Kohsuke Kawaguchi
9+
*/
10+
public class RepositoryTest extends AbstractGitHubApiTestBase {
11+
@Test
12+
public void subscription() throws Exception {
13+
GHRepository r = getRepository();
14+
assertNull(r.getSubscription());
15+
16+
GHSubscription s = r.subscribe(true, false);
17+
assertEquals(s.getRepository(), r);
18+
19+
s.delete();
20+
21+
assertNull(r.getSubscription());
22+
}
23+
24+
private GHRepository getRepository() throws IOException {
25+
return gitHub.getOrganization("github-api-test-org").getRepository("jenkins");
26+
}
27+
}

0 commit comments

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