Skip to content

Commit 0467f0a

Browse files
committed
Further cleanup
1 parent b779d25 commit 0467f0a

File tree

86 files changed

+2314
-476
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2314
-476
lines changed

src/test/java/org/kohsuke/github/GHAppTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Map;
1111

1212
import static org.hamcrest.Matchers.*;
13+
import static org.junit.Assert.assertThrows;
1314

1415
/**
1516
* Tests for the GitHub App API methods
@@ -40,6 +41,15 @@ public void getGitHubApp() throws IOException {
4041
assertThat(app.getPermissions().size(), is(4));
4142
assertThat(app.getEvents().size(), is(2));
4243
assertThat(app.getInstallationsCount(), is((long) 1));
44+
45+
// Deprecated methods
46+
assertThrows(RuntimeException.class, () -> app.setDescription(""));
47+
assertThrows(RuntimeException.class, () -> app.setEvents(null));
48+
assertThrows(RuntimeException.class, () -> app.setExternalUrl(""));
49+
assertThrows(RuntimeException.class, () -> app.setInstallationsCount(1));
50+
assertThrows(RuntimeException.class, () -> app.setName(""));
51+
assertThrows(RuntimeException.class, () -> app.setOwner(null));
52+
assertThrows(RuntimeException.class, () -> app.setPermissions(null));
4353
}
4454

4555
@Test
@@ -113,6 +123,13 @@ public void createToken() throws IOException {
113123
assertThat(installationToken.getRepositorySelection(), is(GHRepositorySelection.SELECTED));
114124
assertThat(installationToken.getExpiresAt(), is(GitHubClient.parseDate("2019-08-10T05:54:58Z")));
115125

126+
// Deprecated methods
127+
assertThrows(RuntimeException.class, () -> installationToken.setPermissions(null));
128+
assertThrows(RuntimeException.class, () -> installationToken.setRoot(null));
129+
assertThrows(RuntimeException.class, () -> installationToken.setRepositorySelection(null));
130+
assertThrows(RuntimeException.class, () -> installationToken.setRepositories(null));
131+
assertThrows(RuntimeException.class, () -> installationToken.setPermissions(null));
132+
116133
GHRepository repository = installationToken.getRepositories().get(0);
117134
assertThat(installationToken.getRepositories().size(), is(1));
118135
assertThat(repository.getId(), is((long) 111111111));
@@ -143,6 +160,19 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc
143160
assertThat(appInstallation.getTargetId(), is((long) 111111111));
144161
assertThat(appInstallation.getTargetType(), is(GHTargetType.ORGANIZATION));
145162

163+
// Deprecated methods
164+
assertThrows(RuntimeException.class, () -> appInstallation.setAccessTokenUrl(""));
165+
assertThrows(RuntimeException.class, () -> appInstallation.setAccount(null));
166+
assertThrows(RuntimeException.class, () -> appInstallation.setAppId(0));
167+
assertThrows(RuntimeException.class, () -> appInstallation.setEvents(null));
168+
assertThrows(RuntimeException.class, () -> appInstallation.setPermissions(null));
169+
assertThrows(RuntimeException.class, () -> appInstallation.setRepositorySelection(null));
170+
assertThrows(RuntimeException.class, () -> appInstallation.setRepositoriesUrl(null));
171+
assertThrows(RuntimeException.class, () -> appInstallation.setRoot(null));
172+
assertThrows(RuntimeException.class, () -> appInstallation.setSingleFileName(""));
173+
assertThrows(RuntimeException.class, () -> appInstallation.setTargetId(0));
174+
assertThrows(RuntimeException.class, () -> appInstallation.setTargetType(null));
175+
146176
Map<String, GHPermissionType> permissionsMap = new HashMap<String, GHPermissionType>();
147177
permissionsMap.put("checks", GHPermissionType.WRITE);
148178
permissionsMap.put("pull_requests", GHPermissionType.WRITE);

src/test/java/org/kohsuke/github/GHBranchTest.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.junit.Test;
44

5-
import java.io.IOException;
6-
75
import static org.hamcrest.Matchers.*;
86

97
public class GHBranchTest extends AbstractGitHubWireMockTest {
@@ -17,10 +15,31 @@ public void testMergeBranch() throws Exception {
1715
repository = getTempRepository();
1816

1917
String mainHead = repository.getRef("heads/main").getObject().getSha();
20-
createRefAndPostContent(BRANCH_1, mainHead);
21-
createRefAndPostContent(BRANCH_2, mainHead);
22-
18+
String branchName1 = "refs/heads/" + BRANCH_1;
19+
repository.createRef(branchName1, mainHead);
20+
repository.createContent()
21+
.content(branchName1)
22+
.message(branchName1)
23+
.path(branchName1)
24+
.branch(branchName1)
25+
.commit();
26+
27+
String branchName2 = "refs/heads/" + BRANCH_2;
28+
repository.createRef(branchName2, mainHead);
2329
GHBranch otherBranch = repository.getBranch(BRANCH_2);
30+
assertThat(otherBranch.getSHA1(), equalTo(mainHead));
31+
repository.createContent()
32+
.content(branchName2)
33+
.message(branchName2)
34+
.path(branchName2)
35+
.branch(branchName2)
36+
.commit();
37+
38+
otherBranch = repository.getBranch(BRANCH_2);
39+
assertThat(otherBranch.getSHA1(), not(equalTo(mainHead)));
40+
assertThat(otherBranch.getOwner(), notNullValue());
41+
assertThat(otherBranch.getOwner().getFullName(), equalTo(repository.getFullName()));
42+
2443
String commitMessage = "merging " + BRANCH_2;
2544
GHCommit mergeCommit = repository.getBranch(BRANCH_1).merge(otherBranch, commitMessage);
2645
assertThat(mergeCommit, notNullValue());
@@ -38,10 +57,4 @@ public void testMergeBranch() throws Exception {
3857
// Should be null since all changes already merged
3958
assertThat(mergeCommit, nullValue());
4059
}
41-
42-
private void createRefAndPostContent(String branchName, String sha) throws IOException {
43-
String refName = "refs/heads/" + branchName;
44-
repository.createRef(refName, sha);
45-
repository.createContent().content(branchName).message(branchName).path(branchName).branch(branchName).commit();
46-
}
4760
}

src/test/java/org/kohsuke/github/GHGistTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public void lifecycleTest() throws Exception {
2828
assertThat(gist.getUpdatedAt(), notNullValue());
2929
assertThat(gist.getCommentsUrl(), notNullValue());
3030
assertThat(gist.getCommitsUrl(), notNullValue());
31+
assertThat(gist.getForksUrl(), notNullValue());
3132
assertThat(gist.getGitPullUrl(), notNullValue());
3233
assertThat(gist.getGitPushUrl(), notNullValue());
3334
assertThat(gist.getHtmlUrl(), notNullValue());
35+
assertThat(gist.getHtmlUrl(), notNullValue());
3436

3537
String id = gist.getGistId();
3638

@@ -99,6 +101,9 @@ public void starTest() throws Exception {
99101
GHGist gist = gitHub.getGist("9903708");
100102
assertThat(gist.getOwner().getLogin(), equalTo("rtyler"));
101103

104+
// Random: test that comment count works
105+
assertThat(gist.getCommentCount(), equalTo(1));
106+
102107
gist.star();
103108
assertThat(gist.isStarred(), is(true));
104109

src/test/java/org/kohsuke/github/GHLicenseTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void getLicense() throws IOException {
8686
assertThat(license.getBody(), startsWith("MIT License\n" + "\n" + "Copyright (c) [year] [fullname]\n\n"));
8787
assertThat(license.getForbidden(), is(empty()));
8888
assertThat(license.getPermitted(), is(empty()));
89+
assertThat(license.getRequired(), is(empty()));
8990
assertThat(license.getImplementation(),
9091
equalTo("Create a text file (typically named LICENSE or LICENSE.txt) in the root of your source code and copy the text of the license into the file. Replace [year] with the current year and [fullname] with the name (or names) of the copyright holders."));
9192
assertThat(license.getCategory(), nullValue());

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,9 @@ public void getRef() throws Exception {
736736
assertThat(ghRef, notNullValue());
737737
assertThat(ghRef.getRef(), equalTo("refs/heads/gh-pages"));
738738
assertThat(ghRefWithPrefix.getRef(), equalTo(ghRef.getRef()));
739+
assertThat(ghRefWithPrefix.getObject().getType(), equalTo("commit"));
740+
assertThat(ghRefWithPrefix.getObject().getUrl().toString(),
741+
containsString("/repos/hub4j-test-org/github-api/git/commits/"));
739742

740743
// git/refs/heads/gh-pages
741744
ghRef = repo.getRef("heads/gh-pages");

src/test/java/org/kohsuke/github/GHTeamTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public void testSetDescription() throws IOException {
1919

2020
// Set the description.
2121
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
22+
assertThat(team.getHtmlUrl(), notNullValue());
2223
team.setDescription(description);
2324

2425
// Check that it was set correctly.
@@ -36,7 +37,35 @@ public void testSetDescription() throws IOException {
3637
}
3738

3839
@Test
39-
public void testlistMembersAdmin() throws IOException {
40+
public void getMembers() throws IOException {
41+
String teamSlug = "dummy-team";
42+
43+
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
44+
45+
Set<GHUser> admins = team.getMembers();
46+
47+
assertThat(admins, notNullValue());
48+
assertThat("One admin in dummy team", admins.size(), equalTo(1));
49+
assertThat("Specific user in admin team",
50+
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
51+
}
52+
53+
@Test
54+
public void listMembers() throws IOException {
55+
String teamSlug = "dummy-team";
56+
57+
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
58+
59+
List<GHUser> admins = team.listMembers().toList();
60+
61+
assertThat(admins, notNullValue());
62+
assertThat("One admin in dummy team", admins.size(), equalTo(1));
63+
assertThat("Specific user in admin team",
64+
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
65+
}
66+
67+
@Test
68+
public void listMembersAdmin() throws IOException {
4069
String teamSlug = "dummy-team";
4170

4271
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
@@ -50,7 +79,7 @@ public void testlistMembersAdmin() throws IOException {
5079
}
5180

5281
@Test
53-
public void testlistMembersNoMatch() throws IOException {
82+
public void listMembersNoMatch() throws IOException {
5483
String teamSlug = "dummy-team";
5584

5685
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);

src/test/java/org/kohsuke/github/GHUserTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
import static org.hamcrest.Matchers.notNullValue;
1414

1515
public class GHUserTest extends AbstractGitHubWireMockTest {
16+
17+
@Test
18+
public void isMemberOf() throws IOException {
19+
GHUser u = gitHub.getUser("bitwiseman");
20+
String teamSlug = "dummy-team";
21+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
22+
GHTeam team = org.getTeamBySlug(teamSlug);
23+
24+
assertThat(u.isMemberOf(org), is(true));
25+
assertThat(u.isMemberOf(team), is(true));
26+
assertThat(u.isPublicMemberOf(org), is(false));
27+
28+
org = gitHub.getOrganization("hub4j");
29+
assertThat(u.isMemberOf(org), is(true));
30+
assertThat(u.isPublicMemberOf(org), is(true));
31+
32+
u = gitHub.getUser("rtyler");
33+
assertThat(u.isMemberOf(org), is(false));
34+
assertThat(u.isMemberOf(team), is(false));
35+
assertThat(u.isPublicMemberOf(org), is(false));
36+
}
37+
1638
@Test
1739
public void listFollowsAndFollowers() throws IOException {
1840
GHUser u = gitHub.getUser("rtyler");

src/test/java/org/kohsuke/github/GitHubStaticTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ public void testMappingReaderWriter() throws Exception {
329329
// This should never happen if the internal method isn't used
330330
final GHRepository readRepoFinal = readRepo;
331331
assertThrows(NullPointerException.class, () -> readRepoFinal.getRoot());
332+
assertThrows(NullPointerException.class, () -> readRepoFinal.root());
333+
assertThat(readRepoFinal.isOffline(), is(true));
332334
assertThat(readRepo.getResponseHeaderFields(), nullValue());
333335

334336
readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);

src/test/resources/org/kohsuke/github/GHBranchTest/wiremock/testMergeBranch/__files/repos_hub4j-test-org_temp-testmergebranch-2.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
2-
"id": 283313593,
3-
"node_id": "MDEwOlJlcG9zaXRvcnkyODMzMTM1OTM=",
2+
"id": 406515622,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk0MDY1MTU2MjI=",
44
"name": "temp-testMergeBranch",
55
"full_name": "hub4j-test-org/temp-testMergeBranch",
66
"private": false,
77
"owner": {
88
"login": "hub4j-test-org",
99
"id": 7544739,
1010
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
11-
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
1212
"gravatar_id": "",
1313
"url": "https://api.github.com/users/hub4j-test-org",
1414
"html_url": "https://github.com/hub4j-test-org",
@@ -64,9 +64,9 @@
6464
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/labels{/name}",
6565
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/releases{/id}",
6666
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/deployments",
67-
"created_at": "2020-07-28T19:54:49Z",
68-
"updated_at": "2020-07-28T19:54:53Z",
69-
"pushed_at": "2020-07-28T19:54:51Z",
67+
"created_at": "2021-09-14T20:43:07Z",
68+
"updated_at": "2021-09-14T20:43:11Z",
69+
"pushed_at": "2021-09-14T20:43:08Z",
7070
"git_url": "git://github.com/hub4j-test-org/temp-testMergeBranch.git",
7171
"ssh_url": "[email protected]:hub4j-test-org/temp-testMergeBranch.git",
7272
"clone_url": "https://github.com/hub4j-test-org/temp-testMergeBranch.git",
@@ -87,25 +87,29 @@
8787
"disabled": false,
8888
"open_issues_count": 0,
8989
"license": null,
90+
"allow_forking": true,
9091
"forks": 0,
9192
"open_issues": 0,
9293
"watchers": 0,
9394
"default_branch": "main",
9495
"permissions": {
9596
"admin": true,
97+
"maintain": true,
9698
"push": true,
99+
"triage": true,
97100
"pull": true
98101
},
99102
"temp_clone_token": "",
100103
"allow_squash_merge": true,
101104
"allow_merge_commit": true,
102105
"allow_rebase_merge": true,
106+
"allow_auto_merge": false,
103107
"delete_branch_on_merge": false,
104108
"organization": {
105109
"login": "hub4j-test-org",
106110
"id": 7544739,
107111
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
108-
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
112+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
109113
"gravatar_id": "",
110114
"url": "https://api.github.com/users/hub4j-test-org",
111115
"html_url": "https://github.com/hub4j-test-org",
@@ -122,5 +126,5 @@
122126
"site_admin": false
123127
},
124128
"network_count": 0,
125-
"subscribers_count": 8
129+
"subscribers_count": 14
126130
}
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
{
22
"name": "main",
33
"commit": {
4-
"sha": "688a1c3f8bc67deb767f68560ed8c7350d70d50f",
5-
"node_id": "MDY6Q29tbWl0MjgzMzEzNTkzOjY4OGExYzNmOGJjNjdkZWI3NjdmNjg1NjBlZDhjNzM1MGQ3MGQ1MGY=",
4+
"sha": "90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
5+
"node_id": "MDY6Q29tbWl0NDA2NTE1NjIyOjkwYmJmY2IwM2U5ZGRjZDljY2I0ODk0YTQxN2U0YTFjZjNjOGZiZDU=",
66
"commit": {
77
"author": {
88
"name": "Liam Newman",
99
"email": "[email protected]",
10-
"date": "2020-07-28T19:54:50Z"
10+
"date": "2021-09-14T20:43:08Z"
1111
},
1212
"committer": {
1313
"name": "GitHub",
1414
"email": "[email protected]",
15-
"date": "2020-07-28T19:54:50Z"
15+
"date": "2021-09-14T20:43:08Z"
1616
},
1717
"message": "Initial commit",
1818
"tree": {
1919
"sha": "c6da5eb430eb876e5a03323a62ea01365a753d3b",
2020
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/trees/c6da5eb430eb876e5a03323a62ea01365a753d3b"
2121
},
22-
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
22+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
2323
"comment_count": 0,
2424
"verification": {
2525
"verified": true,
2626
"reason": "valid",
27-
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJfIIKKCRBK7hj4Ov3rIwAAdHIIAH1NiSMFO1907U4QdfRgdqCP\nQHgc6KsflfLPxeP/Tt02Q+BJQeN8e1/IMXziwOp5dt5+CSuGFLN9U41fsBOxIRk6\nagqX5q4KleZaUEjOik2PfmXkwO+mQU64CX2QdpfHuqZNvCl6H1G4dnEAWdM1E3oA\nvLMIOHdjy6Fc1VJzmcc8+RVzUvKv/9Fq0uU6WR9Jl6TfMnfGqtVwQ1USuerhnIs0\nPSI9Yo12Wy8b+8psD3bwBcjbX8r6ItM//DjzU3XcKRZxv54u7tgQuLELqxh9dQSu\nCDSV9/LyHpMC3WMRAupusGsb4rMKeN+C7NYC4ZMmoRmwvWAhRKjTtCHBP8Ksapo=\n=OLMl\n-----END PGP SIGNATURE-----\n",
28-
"payload": "tree c6da5eb430eb876e5a03323a62ea01365a753d3b\nauthor Liam Newman <[email protected]> 1595966090 -0700\ncommitter GitHub <[email protected]> 1595966090 -0700\n\nInitial commit"
27+
"signature": "-----BEGIN PGP SIGNATURE-----\n\nwsBcBAABCAAQBQJhQQlcCRBK7hj4Ov3rIwAA67AIAG/C1HDKhPe1hHt+rrF91od+\nWACymBdue0wdC0mF/KMVc7lCl3S0lpd9H46efXUaejKDhjizckILxUFBUyEykx+y\n1bygYKkgpnopqwS+CnRiV1Xya3axCATxGK2AU0zE9JPmOy+rynSXP36EjJbBlQmU\nHMidBjn4QMlII3fmLGHHdPnUe1j/WiwZDiATX6w5nlzapO+zSG3hmbxyhWcNL8bA\nUGt5XiHTc7AUL1cjhofb99qHQCLXgOISPLrPpfghP622PjoC/pBBTr/WIjPlyuHj\nCmIkh+XS4lPaCqipbg4lv0E5rjMgrsoC4t3ewRCzDdrb+212YuQFDaxzOSN0D4s=\n=z/jP\n-----END PGP SIGNATURE-----\n",
28+
"payload": "tree c6da5eb430eb876e5a03323a62ea01365a753d3b\nauthor Liam Newman <[email protected]> 1631652188 -0700\ncommitter GitHub <[email protected]> 1631652188 -0700\n\nInitial commit"
2929
}
3030
},
31-
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
32-
"html_url": "https://github.com/hub4j-test-org/temp-testMergeBranch/commit/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
33-
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f/comments",
31+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
32+
"html_url": "https://github.com/hub4j-test-org/temp-testMergeBranch/commit/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
33+
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5/comments",
3434
"author": {
3535
"login": "bitwiseman",
3636
"id": 1958953,
3737
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
38-
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
38+
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
3939
"gravatar_id": "",
4040
"url": "https://api.github.com/users/bitwiseman",
4141
"html_url": "https://github.com/bitwiseman",
@@ -55,7 +55,7 @@
5555
"login": "web-flow",
5656
"id": 19864447,
5757
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
58-
"avatar_url": "https://avatars3.githubusercontent.com/u/19864447?v=4",
58+
"avatar_url": "https://avatars.githubusercontent.com/u/19864447?v=4",
5959
"gravatar_id": "",
6060
"url": "https://api.github.com/users/web-flow",
6161
"html_url": "https://github.com/web-flow",

0 commit comments

Comments
 (0)