Skip to content

Commit 4d77d9e

Browse files
committed
added a method to enable/disable the issue tracker.
1 parent bb3bfe4 commit 4d77d9e

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class GHRepository {
5959

6060
private String description, homepage, url, name, owner;
6161
private boolean has_issues, has_wiki, fork, _private, has_downloads;
62-
private int watchers,forks;
62+
private int watchers,forks,open_issues;
6363
private String created_at, pushed_at;
6464

6565
public String getDescription() {
@@ -121,6 +121,10 @@ public int getWatchers() {
121121
return watchers;
122122
}
123123

124+
public int getOpenIssueCount() {
125+
return open_issues;
126+
}
127+
124128
public Date getPushedAt() {
125129
return GitHub.parseDate(pushed_at);
126130
}
@@ -176,6 +180,14 @@ public void setEmailServiceHook(String address) throws IOException {
176180
f.submit((HtmlButton) f.getElementsByTagName("button").get(0));
177181
}
178182

183+
/**
184+
* Enables or disables the issue tracker for this repository.
185+
*/
186+
public void enableIssueTracker(boolean v) throws IOException {
187+
new Poster(root).withCredential().with("values[has_issues]",String.valueOf(v))
188+
.to("/repos/show/" + owner + "/" + name);
189+
}
190+
179191
/**
180192
* Deletes this repository.
181193
*/

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,13 @@
33
import junit.framework.TestCase;
44
import org.kohsuke.github.GHOrganization;
55
import org.kohsuke.github.GHOrganization.Permission;
6-
import org.kohsuke.github.GHPullRequest;
7-
import org.kohsuke.github.GHPullRequest.State;
86
import org.kohsuke.github.GHRepository;
97
import org.kohsuke.github.GHTeam;
108
import org.kohsuke.github.GitHub;
119

1210
import java.io.IOException;
1311
import java.net.URL;
14-
import java.util.Collections;
15-
import java.util.Comparator;
16-
import java.util.Date;
17-
import java.util.List;
1812
import java.util.Set;
19-
import java.util.concurrent.TimeUnit;
2013

2114
/**
2215
* Unit test for simple App.
@@ -55,6 +48,26 @@ public void testApp() throws IOException {
5548
// System.out.println(hub.getUser("kohsuke").getRepository("hudson").getCollaborators());
5649
}
5750

51+
private void tryDisablingIssueTrackers(GitHub gitHub) throws IOException {
52+
for (GHRepository r : gitHub.getOrganization("jenkinsci").getRepositories().values()) {
53+
if (r.hasIssues()) {
54+
if (r.getOpenIssueCount()==0) {
55+
System.out.println("DISABLED "+r.getName());
56+
r.enableIssueTracker(false);
57+
} else {
58+
System.out.println("UNTOUCHED "+r.getName());
59+
}
60+
}
61+
}
62+
}
63+
64+
private void tryUpdatingIssueTracker(GitHub gitHub) throws IOException {
65+
GHRepository r = gitHub.getOrganization("jenkinsci").getRepository("lib-task-reactor");
66+
System.out.println(r.hasIssues());
67+
System.out.println(r.getOpenIssueCount());
68+
r.enableIssueTracker(false);
69+
}
70+
5871
private void tryRenaming(GitHub gitHub) throws IOException {
5972
gitHub.getUser("kohsuke").getRepository("test").renameTo("test2");
6073
}

0 commit comments

Comments
 (0)