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 9c8d73c

Browse filesBrowse files
authored
Merge branch 'master' into add-missing-org-permissions
2 parents ab68a59 + 5db97d9 commit 9c8d73c
Copy full SHA for 9c8d73c
Expand file treeCollapse file tree

27 files changed

+2311
-17
lines changed

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHIssue.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private void editNullable(String key, Object value) throws IOException {
239239
}
240240

241241
private void editIssue(String key, Object value) throws IOException {
242-
root.createRequest().with(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send();
242+
root.createRequest().withNullable(key, value).method("PATCH").withUrlPath(getIssuesApiRoute()).send();
243243
}
244244

245245
/**
@@ -296,9 +296,9 @@ public void setBody(String body) throws IOException {
296296
*/
297297
public void setMilestone(GHMilestone milestone) throws IOException {
298298
if (milestone == null) {
299-
editNullable("milestone", null);
299+
editIssue("milestone", null);
300300
} else {
301-
edit("milestone", milestone.getNumber());
301+
editIssue("milestone", milestone.getNumber());
302302
}
303303
}
304304

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHRepository.java
+23-7Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.HashMap;
4747
import java.util.HashSet;
4848
import java.util.Iterator;
49+
import java.util.LinkedHashSet;
4950
import java.util.List;
5051
import java.util.Map;
5152
import java.util.Objects;
@@ -68,7 +69,9 @@ public class GHRepository extends GHObject {
6869
/* package almost final */ transient GitHub root;
6970

7071
private String nodeId, description, homepage, name, full_name;
72+
7173
private String html_url; // this is the UI
74+
7275
/*
7376
* The license information makes use of the preview API.
7477
*
@@ -77,22 +80,30 @@ public class GHRepository extends GHObject {
7780
private GHLicense license;
7881

7982
private String git_url, ssh_url, clone_url, svn_url, mirror_url;
83+
8084
private GHUser owner; // not fully populated. beware.
85+
8186
private boolean has_issues, has_wiki, fork, has_downloads, has_pages, archived, has_projects;
8287

8388
private boolean allow_squash_merge;
89+
8490
private boolean allow_merge_commit;
91+
8592
private boolean allow_rebase_merge;
8693

8794
private boolean delete_branch_on_merge;
8895

8996
@JsonProperty("private")
9097
private boolean _private;
98+
9199
private int forks_count, stargazers_count, watchers_count, size, open_issues_count, subscribers_count;
100+
92101
private String pushed_at;
102+
93103
private Map<Integer, GHMilestone> milestones = new WeakHashMap<Integer, GHMilestone>();
94104

95105
private String default_branch, language;
106+
96107
private Map<String, GHCommit> commits = new WeakHashMap<String, GHCommit>();
97108

98109
@SkipFromToString
@@ -970,12 +981,12 @@ private void modifyCollaborators(@NonNull Collection<GHUser> users,
970981
@NonNull String method,
971982
@CheckForNull GHOrganization.Permission permission) throws IOException {
972983
Requester requester = root.createRequest().method(method);
973-
974984
if (permission != null) {
975985
requester = requester.with("permission", permission).inBody();
976986
}
977987

978-
for (GHUser user : users) {
988+
// Make sure that the users collection doesn't have any duplicates
989+
for (GHUser user : new LinkedHashSet<GHUser>(users)) {
979990
requester.withUrlPath(getApiTailUrl("collaborators/" + user.getLogin())).send();
980991
}
981992
}
@@ -1002,8 +1013,9 @@ public void setEmailServiceHook(String address) throws IOException {
10021013

10031014
private void edit(String key, String value) throws IOException {
10041015
Requester requester = root.createRequest();
1005-
if (!key.equals("name"))
1016+
if (!key.equals("name")) {
10061017
requester.with("name", name); // even when we don't change the name, we need to send it in
1018+
}
10071019
requester.with(key, value).method("PATCH").withUrlPath(getApiTailUrl("")).send();
10081020
}
10091021

@@ -1248,8 +1260,9 @@ public GHRepository fork() throws IOException {
12481260
// this API is asynchronous. we need to wait for a bit
12491261
for (int i = 0; i < 10; i++) {
12501262
GHRepository r = root.getMyself().getRepository(name);
1251-
if (r != null)
1263+
if (r != null) {
12521264
return r;
1265+
}
12531266
try {
12541267
Thread.sleep(3000);
12551268
} catch (InterruptedException e) {
@@ -1278,8 +1291,9 @@ public GHRepository forkTo(GHOrganization org) throws IOException {
12781291
// this API is asynchronous. we need to wait for a bit
12791292
for (int i = 0; i < 10; i++) {
12801293
GHRepository r = org.getRepository(name);
1281-
if (r != null)
1294+
if (r != null) {
12821295
return r;
1296+
}
12831297
try {
12841298
Thread.sleep(3000);
12851299
} catch (InterruptedException e) {
@@ -2721,8 +2735,9 @@ public boolean equals(Object obj) {
27212735
}
27222736

27232737
String getApiTailUrl(String tail) {
2724-
if (tail.length() > 0 && !tail.startsWith("/"))
2738+
if (tail.length() > 0 && !tail.startsWith("/")) {
27252739
tail = '/' + tail;
2740+
}
27262741
return "/repos/" + getOwnerName() + "/" + name + tail;
27272742
}
27282743

@@ -2829,8 +2844,9 @@ public GHTagObject createTag(String tag, String message, String object, String t
28292844
* The IO exception
28302845
*/
28312846
void populate() throws IOException {
2832-
if (root.isOffline())
2847+
if (root.isOffline()) {
28332848
return; // can't populate if the root is offline
2849+
}
28342850

28352851
final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!");
28362852

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHub.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ public PagedIterable<GHOrganization> listOrganizations(final String since) {
532532
}
533533

534534
/**
535-
* Gets the repository object from 'user/reponame' string that GitHub calls as "repository name"
535+
* Gets the repository object from 'owner/repo' string that GitHub calls as "repository name"
536536
*
537537
* @param name
538538
* the name
@@ -543,6 +543,9 @@ public PagedIterable<GHOrganization> listOrganizations(final String since) {
543543
*/
544544
public GHRepository getRepository(String name) throws IOException {
545545
String[] tokens = name.split("/");
546+
if (tokens.length < 2) {
547+
throw new IllegalArgumentException("Repository name must be in format owner/repo");
548+
}
546549
return createRequest().withUrlPath("/repos/" + tokens[0] + '/' + tokens[1])
547550
.fetch(GHRepository.class)
548551
.wrap(this);

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

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GitHubRequest.java
+2-6Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,13 +671,9 @@ public B withUrlPath(@Nonnull String urlPath, @Nonnull String... urlPathItems) {
671671
tailUrlPath += "/" + String.join("/", urlPathItems);
672672
}
673673

674-
if (this.urlPath.endsWith("/")) {
675-
tailUrlPath = StringUtils.stripStart(tailUrlPath, "/");
676-
} else {
677-
tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/");
678-
}
674+
tailUrlPath = StringUtils.prependIfMissing(tailUrlPath, "/");
679675

680-
this.urlPath += urlPathEncode(tailUrlPath);
676+
this.urlPath = urlPathEncode(tailUrlPath);
681677
return (B) this;
682678
}
683679

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHMilestoneTest.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ public void testUnsetMilestone() throws IOException {
7070
assertEquals(null, issue.getMilestone());
7171
}
7272

73+
@Test
74+
public void testUnsetMilestoneFromPullRequest() throws IOException {
75+
GHRepository repo = getRepository();
76+
GHMilestone milestone = repo.createMilestone("Unset Test Milestone", "For testUnsetMilestone");
77+
GHPullRequest p = repo.createPullRequest("testUnsetMilestoneFromPullRequest",
78+
"test/stable",
79+
"master",
80+
"## test pull request");
81+
82+
// set the milestone
83+
p.setMilestone(milestone);
84+
p = repo.getPullRequest(p.getNumber()); // force reload
85+
assertEquals(milestone.getNumber(), p.getMilestone().getNumber());
86+
87+
// remove the milestone
88+
p.setMilestone(null);
89+
p = repo.getPullRequest(p.getNumber()); // force reload
90+
assertNull(p.getMilestone());
91+
}
92+
7393
protected GHRepository getRepository() throws IOException {
7494
return getRepository(gitHub);
7595
}

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

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/github/GHRepositoryTest.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ public void addCollaborators() throws Exception {
191191
List<GHUser> users = new ArrayList<GHUser>();
192192

193193
users.add(user);
194+
users.add(gitHub.getUser("jimmysombrero2"));
194195
repo.addCollaborators(users, GHOrganization.Permission.PUSH);
195196

196197
GHPersonSet<GHUser> collabs = repo.getCollaborators();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "hub4jtestorgemail@could.be.null.com",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 12,
24+
"public_gists": 0,
25+
"followers": 0,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2020-06-04T05:56:10Z",
30+
"type": "Organization",
31+
"total_private_repos": 0,
32+
"owned_private_repos": 0,
33+
"private_gists": 0,
34+
"disk_usage": 148,
35+
"collaborators": 0,
36+
"billing_email": "kk@kohsuke.org",
37+
"default_repository_permission": "none",
38+
"members_can_create_repositories": false,
39+
"two_factor_requirement_enabled": false,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"private_repos": 10000,
44+
"filled_seats": 19,
45+
"seats": 3
46+
}
47+
}

0 commit comments

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