Skip to content

Commit

Permalink
Further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Sep 15, 2021
1 parent b779d25 commit 0467f0a
Show file tree
Hide file tree
Showing 86 changed files with 2,314 additions and 476 deletions.
30 changes: 30 additions & 0 deletions src/test/java/org/kohsuke/github/GHAppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows;

/**
* Tests for the GitHub App API methods
Expand Down Expand Up @@ -40,6 +41,15 @@ public void getGitHubApp() throws IOException {
assertThat(app.getPermissions().size(), is(4));
assertThat(app.getEvents().size(), is(2));
assertThat(app.getInstallationsCount(), is((long) 1));

// Deprecated methods
assertThrows(RuntimeException.class, () -> app.setDescription(""));
assertThrows(RuntimeException.class, () -> app.setEvents(null));
assertThrows(RuntimeException.class, () -> app.setExternalUrl(""));
assertThrows(RuntimeException.class, () -> app.setInstallationsCount(1));
assertThrows(RuntimeException.class, () -> app.setName(""));
assertThrows(RuntimeException.class, () -> app.setOwner(null));
assertThrows(RuntimeException.class, () -> app.setPermissions(null));
}

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

// Deprecated methods
assertThrows(RuntimeException.class, () -> installationToken.setPermissions(null));
assertThrows(RuntimeException.class, () -> installationToken.setRoot(null));
assertThrows(RuntimeException.class, () -> installationToken.setRepositorySelection(null));
assertThrows(RuntimeException.class, () -> installationToken.setRepositories(null));
assertThrows(RuntimeException.class, () -> installationToken.setPermissions(null));

GHRepository repository = installationToken.getRepositories().get(0);
assertThat(installationToken.getRepositories().size(), is(1));
assertThat(repository.getId(), is((long) 111111111));
Expand Down Expand Up @@ -143,6 +160,19 @@ private void testAppInstallation(GHAppInstallation appInstallation) throws IOExc
assertThat(appInstallation.getTargetId(), is((long) 111111111));
assertThat(appInstallation.getTargetType(), is(GHTargetType.ORGANIZATION));

// Deprecated methods
assertThrows(RuntimeException.class, () -> appInstallation.setAccessTokenUrl(""));
assertThrows(RuntimeException.class, () -> appInstallation.setAccount(null));
assertThrows(RuntimeException.class, () -> appInstallation.setAppId(0));
assertThrows(RuntimeException.class, () -> appInstallation.setEvents(null));
assertThrows(RuntimeException.class, () -> appInstallation.setPermissions(null));
assertThrows(RuntimeException.class, () -> appInstallation.setRepositorySelection(null));
assertThrows(RuntimeException.class, () -> appInstallation.setRepositoriesUrl(null));
assertThrows(RuntimeException.class, () -> appInstallation.setRoot(null));
assertThrows(RuntimeException.class, () -> appInstallation.setSingleFileName(""));
assertThrows(RuntimeException.class, () -> appInstallation.setTargetId(0));
assertThrows(RuntimeException.class, () -> appInstallation.setTargetType(null));

Map<String, GHPermissionType> permissionsMap = new HashMap<String, GHPermissionType>();
permissionsMap.put("checks", GHPermissionType.WRITE);
permissionsMap.put("pull_requests", GHPermissionType.WRITE);
Expand Down
35 changes: 24 additions & 11 deletions src/test/java/org/kohsuke/github/GHBranchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.junit.Test;

import java.io.IOException;

import static org.hamcrest.Matchers.*;

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

String mainHead = repository.getRef("heads/main").getObject().getSha();
createRefAndPostContent(BRANCH_1, mainHead);
createRefAndPostContent(BRANCH_2, mainHead);

String branchName1 = "refs/heads/" + BRANCH_1;
repository.createRef(branchName1, mainHead);
repository.createContent()
.content(branchName1)
.message(branchName1)
.path(branchName1)
.branch(branchName1)
.commit();

String branchName2 = "refs/heads/" + BRANCH_2;
repository.createRef(branchName2, mainHead);
GHBranch otherBranch = repository.getBranch(BRANCH_2);
assertThat(otherBranch.getSHA1(), equalTo(mainHead));
repository.createContent()
.content(branchName2)
.message(branchName2)
.path(branchName2)
.branch(branchName2)
.commit();

otherBranch = repository.getBranch(BRANCH_2);
assertThat(otherBranch.getSHA1(), not(equalTo(mainHead)));
assertThat(otherBranch.getOwner(), notNullValue());
assertThat(otherBranch.getOwner().getFullName(), equalTo(repository.getFullName()));

String commitMessage = "merging " + BRANCH_2;
GHCommit mergeCommit = repository.getBranch(BRANCH_1).merge(otherBranch, commitMessage);
assertThat(mergeCommit, notNullValue());
Expand All @@ -38,10 +57,4 @@ public void testMergeBranch() throws Exception {
// Should be null since all changes already merged
assertThat(mergeCommit, nullValue());
}

private void createRefAndPostContent(String branchName, String sha) throws IOException {
String refName = "refs/heads/" + branchName;
repository.createRef(refName, sha);
repository.createContent().content(branchName).message(branchName).path(branchName).branch(branchName).commit();
}
}
5 changes: 5 additions & 0 deletions src/test/java/org/kohsuke/github/GHGistTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ public void lifecycleTest() throws Exception {
assertThat(gist.getUpdatedAt(), notNullValue());
assertThat(gist.getCommentsUrl(), notNullValue());
assertThat(gist.getCommitsUrl(), notNullValue());
assertThat(gist.getForksUrl(), notNullValue());
assertThat(gist.getGitPullUrl(), notNullValue());
assertThat(gist.getGitPushUrl(), notNullValue());
assertThat(gist.getHtmlUrl(), notNullValue());
assertThat(gist.getHtmlUrl(), notNullValue());

String id = gist.getGistId();

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

// Random: test that comment count works
assertThat(gist.getCommentCount(), equalTo(1));

gist.star();
assertThat(gist.isStarred(), is(true));

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/kohsuke/github/GHLicenseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void getLicense() throws IOException {
assertThat(license.getBody(), startsWith("MIT License\n" + "\n" + "Copyright (c) [year] [fullname]\n\n"));
assertThat(license.getForbidden(), is(empty()));
assertThat(license.getPermitted(), is(empty()));
assertThat(license.getRequired(), is(empty()));
assertThat(license.getImplementation(),
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."));
assertThat(license.getCategory(), nullValue());
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,9 @@ public void getRef() throws Exception {
assertThat(ghRef, notNullValue());
assertThat(ghRef.getRef(), equalTo("refs/heads/gh-pages"));
assertThat(ghRefWithPrefix.getRef(), equalTo(ghRef.getRef()));
assertThat(ghRefWithPrefix.getObject().getType(), equalTo("commit"));
assertThat(ghRefWithPrefix.getObject().getUrl().toString(),
containsString("/repos/hub4j-test-org/github-api/git/commits/"));

// git/refs/heads/gh-pages
ghRef = repo.getRef("heads/gh-pages");
Expand Down
33 changes: 31 additions & 2 deletions src/test/java/org/kohsuke/github/GHTeamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void testSetDescription() throws IOException {

// Set the description.
GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
assertThat(team.getHtmlUrl(), notNullValue());
team.setDescription(description);

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

@Test
public void testlistMembersAdmin() throws IOException {
public void getMembers() throws IOException {
String teamSlug = "dummy-team";

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

Set<GHUser> admins = team.getMembers();

assertThat(admins, notNullValue());
assertThat("One admin in dummy team", admins.size(), equalTo(1));
assertThat("Specific user in admin team",
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
}

@Test
public void listMembers() throws IOException {
String teamSlug = "dummy-team";

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

List<GHUser> admins = team.listMembers().toList();

assertThat(admins, notNullValue());
assertThat("One admin in dummy team", admins.size(), equalTo(1));
assertThat("Specific user in admin team",
admins.stream().anyMatch(ghUser -> ghUser.getLogin().equals("bitwiseman")));
}

@Test
public void listMembersAdmin() throws IOException {
String teamSlug = "dummy-team";

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

@Test
public void testlistMembersNoMatch() throws IOException {
public void listMembersNoMatch() throws IOException {
String teamSlug = "dummy-team";

GHTeam team = gitHub.getOrganization(GITHUB_API_TEST_ORG).getTeamBySlug(teamSlug);
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/kohsuke/github/GHUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@
import static org.hamcrest.Matchers.notNullValue;

public class GHUserTest extends AbstractGitHubWireMockTest {

@Test
public void isMemberOf() throws IOException {
GHUser u = gitHub.getUser("bitwiseman");
String teamSlug = "dummy-team";
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHTeam team = org.getTeamBySlug(teamSlug);

assertThat(u.isMemberOf(org), is(true));
assertThat(u.isMemberOf(team), is(true));
assertThat(u.isPublicMemberOf(org), is(false));

org = gitHub.getOrganization("hub4j");
assertThat(u.isMemberOf(org), is(true));
assertThat(u.isPublicMemberOf(org), is(true));

u = gitHub.getUser("rtyler");
assertThat(u.isMemberOf(org), is(false));
assertThat(u.isMemberOf(team), is(false));
assertThat(u.isPublicMemberOf(org), is(false));
}

@Test
public void listFollowsAndFollowers() throws IOException {
GHUser u = gitHub.getUser("rtyler");
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/kohsuke/github/GitHubStaticTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ public void testMappingReaderWriter() throws Exception {
// This should never happen if the internal method isn't used
final GHRepository readRepoFinal = readRepo;
assertThrows(NullPointerException.class, () -> readRepoFinal.getRoot());
assertThrows(NullPointerException.class, () -> readRepoFinal.root());
assertThat(readRepoFinal.isOffline(), is(true));
assertThat(readRepo.getResponseHeaderFields(), nullValue());

readRepo = GitHub.getMappingObjectReader().forType(GHRepository.class).readValue(repoString);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": 283313593,
"node_id": "MDEwOlJlcG9zaXRvcnkyODMzMTM1OTM=",
"id": 406515622,
"node_id": "MDEwOlJlcG9zaXRvcnk0MDY1MTU2MjI=",
"name": "temp-testMergeBranch",
"full_name": "hub4j-test-org/temp-testMergeBranch",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
Expand Down Expand Up @@ -64,9 +64,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/deployments",
"created_at": "2020-07-28T19:54:49Z",
"updated_at": "2020-07-28T19:54:53Z",
"pushed_at": "2020-07-28T19:54:51Z",
"created_at": "2021-09-14T20:43:07Z",
"updated_at": "2021-09-14T20:43:11Z",
"pushed_at": "2021-09-14T20:43:08Z",
"git_url": "git://github.com/hub4j-test-org/temp-testMergeBranch.git",
"ssh_url": "git@github.com:hub4j-test-org/temp-testMergeBranch.git",
"clone_url": "https://github.com/hub4j-test-org/temp-testMergeBranch.git",
Expand All @@ -87,25 +87,29 @@
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
Expand All @@ -122,5 +126,5 @@
"site_admin": false
},
"network_count": 0,
"subscribers_count": 8
"subscribers_count": 14
}
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"name": "main",
"commit": {
"sha": "688a1c3f8bc67deb767f68560ed8c7350d70d50f",
"node_id": "MDY6Q29tbWl0MjgzMzEzNTkzOjY4OGExYzNmOGJjNjdkZWI3NjdmNjg1NjBlZDhjNzM1MGQ3MGQ1MGY=",
"sha": "90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
"node_id": "MDY6Q29tbWl0NDA2NTE1NjIyOjkwYmJmY2IwM2U5ZGRjZDljY2I0ODk0YTQxN2U0YTFjZjNjOGZiZDU=",
"commit": {
"author": {
"name": "Liam Newman",
"email": "bitwiseman@gmail.com",
"date": "2020-07-28T19:54:50Z"
"date": "2021-09-14T20:43:08Z"
},
"committer": {
"name": "GitHub",
"email": "noreply@github.com",
"date": "2020-07-28T19:54:50Z"
"date": "2021-09-14T20:43:08Z"
},
"message": "Initial commit",
"tree": {
"sha": "c6da5eb430eb876e5a03323a62ea01365a753d3b",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/trees/c6da5eb430eb876e5a03323a62ea01365a753d3b"
},
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/git/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
"comment_count": 0,
"verification": {
"verified": true,
"reason": "valid",
"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",
"payload": "tree c6da5eb430eb876e5a03323a62ea01365a753d3b\nauthor Liam Newman <bitwiseman@gmail.com> 1595966090 -0700\ncommitter GitHub <noreply@github.com> 1595966090 -0700\n\nInitial commit"
"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",
"payload": "tree c6da5eb430eb876e5a03323a62ea01365a753d3b\nauthor Liam Newman <bitwiseman@gmail.com> 1631652188 -0700\ncommitter GitHub <noreply@github.com> 1631652188 -0700\n\nInitial commit"
}
},
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
"html_url": "https://github.com/hub4j-test-org/temp-testMergeBranch/commit/688a1c3f8bc67deb767f68560ed8c7350d70d50f",
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/688a1c3f8bc67deb767f68560ed8c7350d70d50f/comments",
"url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
"html_url": "https://github.com/hub4j-test-org/temp-testMergeBranch/commit/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5",
"comments_url": "https://api.github.com/repos/hub4j-test-org/temp-testMergeBranch/commits/90bbfcb03e9ddcd9ccb4894a417e4a1cf3c8fbd5/comments",
"author": {
"login": "bitwiseman",
"id": 1958953,
"node_id": "MDQ6VXNlcjE5NTg5NTM=",
"avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/1958953?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/bitwiseman",
"html_url": "https://github.com/bitwiseman",
Expand All @@ -55,7 +55,7 @@
"login": "web-flow",
"id": 19864447,
"node_id": "MDQ6VXNlcjE5ODY0NDQ3",
"avatar_url": "https://avatars3.githubusercontent.com/u/19864447?v=4",
"avatar_url": "https://avatars.githubusercontent.com/u/19864447?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/web-flow",
"html_url": "https://github.com/web-flow",
Expand Down
Loading

0 comments on commit 0467f0a

Please sign in to comment.