From 4b56bcffd774248a38bc0bf1f5d71b5c183d03ff Mon Sep 17 00:00:00 2001 From: antrix190 Date: Sun, 6 Feb 2022 18:02:53 +0100 Subject: [PATCH 1/6] Added star/unstar method --- .../java/org/kohsuke/github/GHRepository.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index ca06de69ed..c01a35d9c5 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -2981,6 +2981,14 @@ String getApiTailUrl(String tail) { return "/repos/" + getOwnerName() + "/" + name + tail; } + String getApiHeadUrl(String...strings) { + String head = StringUtils.join(strings, "/"); + if (head.length() > 0 && !head.startsWith("/")) { + head = '/' + head; + } + return head + getOwnerName() + "/" + name; + } + /** * Get all issue events for this repository. See * https://developer.github.com/v3/issues/events/#list-events-for-a-repository @@ -3299,6 +3307,26 @@ protected Updater(@Nonnull GHRepository repository) { } } + /** + * Star a repository. + * + * @throws IOException + * the io exception + */ + public void star() throws IOException { + root().createRequest().method("PUT").withUrlPath(getApiHeadUrl("user","starred")).send(); + } + + /** + * Unstar a repository. + * + * @throws IOException + * the io exception + */ + public void unstar() throws IOException { + root().createRequest().method("DELETE").withUrlPath(getApiHeadUrl("user","starred")).send(); + } + /** * A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request. * From 621006fcf6e7ef86005ac10f6123328b347ebb64 Mon Sep 17 00:00:00 2001 From: antrix190 Date: Sun, 6 Feb 2022 21:21:54 +0100 Subject: [PATCH 2/6] Build fix --- .../java/org/kohsuke/github/GHRepository.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index c01a35d9c5..17efba6b09 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -2981,12 +2981,11 @@ String getApiTailUrl(String tail) { return "/repos/" + getOwnerName() + "/" + name + tail; } - String getApiHeadUrl(String...strings) { - String head = StringUtils.join(strings, "/"); - if (head.length() > 0 && !head.startsWith("/")) { + String getApiHeadUrl(String head) { + if (head.length() > 0 && !head.endsWith("/")) { head = '/' + head; } - return head + getOwnerName() + "/" + name; + return "/user/" + head + getOwnerName() + "/" + name; } /** @@ -3313,8 +3312,8 @@ protected Updater(@Nonnull GHRepository repository) { * @throws IOException * the io exception */ - public void star() throws IOException { - root().createRequest().method("PUT").withUrlPath(getApiHeadUrl("user","starred")).send(); + public void star() throws IOException { + root().createRequest().method("PUT").withUrlPath(getApiHeadUrl("starred")).send(); } /** @@ -3323,8 +3322,8 @@ public void star() throws IOException { * @throws IOException * the io exception */ - public void unstar() throws IOException { - root().createRequest().method("DELETE").withUrlPath(getApiHeadUrl("user","starred")).send(); + public void unstar() throws IOException { + root().createRequest().method("DELETE").withUrlPath(getApiHeadUrl("starred")).send(); } /** From d67f6dbd4928b0bfa0c8e017119f87fae05a183b Mon Sep 17 00:00:00 2001 From: antrix190 Date: Tue, 20 Dec 2022 15:47:35 +0530 Subject: [PATCH 3/6] Added test cases --- .../java/org/kohsuke/github/GHRepository.java | 2 +- .../org/kohsuke/github/GHRepositoryTest.java | 14 + .../starTest/__files/orgs_hub4j-test-org.json | 41 +++ ...b4j-test-org_github-api-starred-users.json | 25 ++ .../repos_hub4j-test-org_github-api.json | 330 ++++++++++++++++++ .../wiremock/starTest/__files/user.json | 33 ++ .../mappings/orgs_hub4j-test-org.json | 48 +++ ...pos_hub4j-test-org_github-api-starred.json | 16 + ...s_hub4j-test-org_github-api-unstarred.json | 16 + .../repos_hub4j-test-org_github-api.json | 48 +++ ...b4j-test-org_github-api_starred-users.json | 47 +++ ...j-test-org_github-api_unstarred-users.json | 47 +++ .../wiremock/starTest/mappings/user.json | 48 +++ 13 files changed, 714 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api-starred-users.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/user.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/orgs_hub4j-test-org.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-starred.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-unstarred.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_starred-users.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_unstarred-users.json create mode 100644 src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/user.json diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 35dcdfcd5e..70b904e1bd 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -3057,7 +3057,7 @@ String getApiHeadUrl(String head) { if (head.length() > 0 && !head.endsWith("/")) { head = '/' + head; } - return "/user/" + head + getOwnerName() + "/" + name; + return "/user" + head + "/" + getOwnerName() + "/" + name; } /** diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 35021925b1..5be5d703cb 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -20,8 +20,10 @@ import java.util.Set; import java.util.stream.Collectors; +import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.hamcrest.Matchers.*; import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.kohsuke.github.GHVerification.Reason.*; @@ -1113,4 +1115,16 @@ public void createSecret() throws Exception { GHRepository repo = getTempRepository(); repo.createSecret("secret", "encrypted", "public"); } + + @Test + public void starTest() throws Exception { + String owner = "hub4j-test-org"; + GHRepository repository = getRepository(); + assertEquals(owner, repository.getOwner().getLogin()); + assertEquals(0, repository.getStargazersCount()); + repository.star(); + assertEquals(1, repository.listStargazers2().toList().size()); + repository.unstar(); + assertEquals(0, repository.listStargazers().toList().size()); + } } diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/orgs_hub4j-test-org.json new file mode 100644 index 0000000000..54173e5a10 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/orgs_hub4j-test-org.json @@ -0,0 +1,41 @@ +{ + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "url": "https://api.github.com/orgs/hub4j-test-org", + "repos_url": "https://api.github.com/orgs/hub4j-test-org/repos", + "events_url": "https://api.github.com/orgs/hub4j-test-org/events", + "hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks", + "issues_url": "https://api.github.com/orgs/hub4j-test-org/issues", + "members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}", + "public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4", + "description": null, + "is_verified": false, + "has_organization_projects": true, + "has_repository_projects": true, + "public_repos": 9, + "public_gists": 0, + "followers": 0, + "following": 0, + "html_url": "https://github.com/hub4j-test-org", + "created_at": "2014-05-10T19:39:11Z", + "updated_at": "2015-04-20T00:42:30Z", + "type": "Organization", + "total_private_repos": 0, + "owned_private_repos": 0, + "private_gists": 0, + "disk_usage": 132, + "collaborators": 0, + "billing_email": "kk@kohsuke.org", + "default_repository_permission": "none", + "members_can_create_repositories": false, + "two_factor_requirement_enabled": false, + "plan": { + "name": "free", + "space": 976562499, + "private_repos": 0, + "filled_seats": 10, + "seats": 0 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api-starred-users.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api-starred-users.json new file mode 100644 index 0000000000..1155b5f6c8 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api-starred-users.json @@ -0,0 +1,25 @@ +[ + { + "starred_at": "2010-04-19T04:13:03Z", + "user": { + "login": "hub4j-test-org", + "id": 9799, + "node_id": "MDQ6VXNlcjk3OTk=", + "avatar_url": "https://avatars.githubusercontent.com/u/9799?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "User", + "site_admin": false + } + } +] \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api.json new file mode 100644 index 0000000000..312a26362c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/repos_hub4j-test-org_github-api.json @@ -0,0 +1,330 @@ +{ + "id": 206888201, + "node_id": "MDEwOlJlcG9zaXRvcnkyMDY4ODgyMDE=", + "name": "github-api", + "full_name": "hub4j-test-org/github-api", + "private": false, + "owner": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j-test-org/github-api", + "description": "Resetting", + "fork": true, + "url": "https://api.github.com/repos/hub4j-test-org/github-api", + "forks_url": "https://api.github.com/repos/hub4j-test-org/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j-test-org/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j-test-org/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j-test-org/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j-test-org/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j-test-org/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j-test-org/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j-test-org/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j-test-org/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j-test-org/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j-test-org/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j-test-org/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j-test-org/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j-test-org/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api/deployments", + "created_at": "2019-09-06T23:26:04Z", + "updated_at": "2019-11-07T22:27:11Z", + "pushed_at": "2019-10-21T22:34:49Z", + "git_url": "git://github.com/hub4j-test-org/github-api.git", + "ssh_url": "git@github.com:hub4j-test-org/github-api.git", + "clone_url": "https://github.com/hub4j-test-org/github-api.git", + "svn_url": "https://github.com/hub4j-test-org/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 11391, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "forks_count": 0, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 0, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 0, + "open_issues": 0, + "watchers": 0, + "default_branch": "main", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "allow_squash_merge": true, + "allow_merge_commit": true, + "allow_rebase_merge": true, + "organization": { + "login": "hub4j-test-org", + "id": 7544739, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=", + "avatar_url": "https://avatars3.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", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "Organization", + "site_admin": false + }, + "parent": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": false, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-12-04T10:56:12Z", + "pushed_at": "2019-12-04T14:15:10Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 17060, + "stargazers_count": 0, + "watchers_count": 0, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 443, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 56, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 443, + "open_issues": 56, + "watchers": 585, + "default_branch": "main" + }, + "source": { + "id": 617210, + "node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=", + "name": "github-api", + "full_name": "hub4j/github-api", + "private": false, + "owner": { + "login": "hub4j", + "id": 54909825, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1", + "avatar_url": "https://avatars3.githubusercontent.com/u/54909825?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j", + "html_url": "https://github.com/hub4j", + "followers_url": "https://api.github.com/users/hub4j/followers", + "following_url": "https://api.github.com/users/hub4j/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j/orgs", + "repos_url": "https://api.github.com/users/hub4j/repos", + "events_url": "https://api.github.com/users/hub4j/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/hub4j/github-api", + "description": "Java API for GitHub", + "fork": false, + "url": "https://api.github.com/repos/hub4j/github-api", + "forks_url": "https://api.github.com/repos/hub4j/github-api/forks", + "keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/hub4j/github-api/teams", + "hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks", + "issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}", + "events_url": "https://api.github.com/repos/hub4j/github-api/events", + "assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}", + "branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}", + "tags_url": "https://api.github.com/repos/hub4j/github-api/tags", + "blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}", + "languages_url": "https://api.github.com/repos/hub4j/github-api/languages", + "stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers", + "contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors", + "subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers", + "subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription", + "commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}", + "compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/hub4j/github-api/merges", + "archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads", + "issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}", + "pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}", + "milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}", + "notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}", + "releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}", + "deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments", + "created_at": "2010-04-19T04:13:03Z", + "updated_at": "2019-12-04T10:56:12Z", + "pushed_at": "2019-12-04T14:15:10Z", + "git_url": "git://github.com/hub4j/github-api.git", + "ssh_url": "git@github.com:hub4j/github-api.git", + "clone_url": "https://github.com/hub4j/github-api.git", + "svn_url": "https://github.com/hub4j/github-api", + "homepage": "http://github-api.kohsuke.org/", + "size": 17060, + "stargazers_count": 585, + "watchers_count": 585, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": true, + "forks_count": 443, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 56, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 443, + "open_issues": 56, + "watchers": 585, + "default_branch": "main" + }, + "network_count": 443, + "subscribers_count": 0 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/user.json new file mode 100644 index 0000000000..68c8dbe653 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/__files/user.json @@ -0,0 +1,33 @@ +{ + "login": "hub4j-test-org", + "id": 1958953, + "node_id": "MDQ6VXNlcjE5NTg5NTM=", + "avatar_url": "https://avatars3.githubusercontent.com/u/1958953?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/hub4j-test-org", + "html_url": "https://github.com/hub4j-test-org", + "followers_url": "https://api.github.com/users/hub4j-test-org/followers", + "following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}", + "gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}", + "starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions", + "organizations_url": "https://api.github.com/users/hub4j-test-org/orgs", + "repos_url": "https://api.github.com/users/hub4j-test-org/repos", + "events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}", + "received_events_url": "https://api.github.com/users/hub4j-test-org/received_events", + "type": "User", + "site_admin": false, + "name": "Liam Newman", + "company": "Cloudbees, Inc.", + "blog": "", + "location": "Seattle, WA, USA", + "email": "hub4j-test-org@gmail.com", + "hireable": null, + "bio": "https://twitter.com/hub4j-test-org", + "public_repos": 166, + "public_gists": 4, + "followers": 135, + "following": 9, + "created_at": "2012-07-11T20:38:33Z", + "updated_at": "2019-09-24T19:32:29Z" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/orgs_hub4j-test-org.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/orgs_hub4j-test-org.json new file mode 100644 index 0000000000..0c9eb0f7fa --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/orgs_hub4j-test-org.json @@ -0,0 +1,48 @@ +{ + "id": "d319a11c-9dce-4642-a18a-175f6cdbde6d", + "name": "orgs_hub4j-test-org", + "request": { + "url": "/orgs/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "orgs_hub4j-test-org.json", + "headers": { + "Date": "Wed, 04 Dec 2019 17:07:18 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4956", + "X-RateLimit-Reset": "1575482837", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"1de516fab0228945881043c1bc527c88\"", + "Last-Modified": "Mon, 20 Apr 2015 00:42:30 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "admin:org, read:org, repo, user, write:org", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "A585:3D530:D2A1AF3:FAB1EAD:5DE7E7C5" + } + }, + "uuid": "d319a11c-9dce-4642-a18a-175f6cdbde6d", + "persistent": true, + "insertionIndex": 2 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-starred.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-starred.json new file mode 100644 index 0000000000..e869cd0c6e --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-starred.json @@ -0,0 +1,16 @@ +{ + "id": "4c1e8c73-a989-4625-8582-5fa6a2f88f4d", + "name": "repos_hub4j-test-org_github-api-starred", + "request": { + "url": "/user/starred/hub4j-test-org/github-api", + "method": "PUT", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 204 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-unstarred.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-unstarred.json new file mode 100644 index 0000000000..86308c991c --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api-unstarred.json @@ -0,0 +1,16 @@ +{ + "id": "4c1e8c73-a989-4625-8582-5fa6a2f88f4d", + "name": "repos_hub4j-test-org_github-api-starred", + "request": { + "url": "/user/starred/hub4j-test-org/github-api", + "method": "DELETE", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 204 + } +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api.json new file mode 100644 index 0000000000..eebaac8b76 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api.json @@ -0,0 +1,48 @@ +{ + "id": "4c1e8c73-a989-4625-8582-5fa6a2f88f4d", + "name": "repos_hub4j-test-org_github-api", + "request": { + "url": "/repos/hub4j-test-org/github-api", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "repos_hub4j-test-org_github-api.json", + "headers": { + "Date": "Wed, 04 Dec 2019 17:07:19 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4955", + "X-RateLimit-Reset": "1575482837", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"bd13c31938217e87f61c9a08bd0fe01d\"", + "Last-Modified": "Thu, 07 Nov 2019 22:27:11 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "repo", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "A585:3D530:D2A1B48:FAB201E:5DE7E7C6" + } + }, + "uuid": "4c1e8c73-a989-4625-8582-5fa6a2f88f4d", + "persistent": true, + "insertionIndex": 3 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_starred-users.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_starred-users.json new file mode 100644 index 0000000000..3b6cf79f81 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_starred-users.json @@ -0,0 +1,47 @@ +{ + "id": "a8dd4fb9-0ec7-4a93-b642-193312795e64", + "name": "repos_hub4j-test-org_github-api_stargazers", + "request": { + "url": "/repos/hub4j-test-org/github-api/stargazers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3.star+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "repos_hub4j-test-org_github-api-starred-users.json", + "headers": { + "Date": "Mon, 25 Jan 2021 01:00:35 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With", + "Accept-Encoding" + ], + "ETag": "\"c0ae8d4e2de626e3c17a734d124e620264c64895ab868c0914ace984cce8cef8\"", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "github.v3; param=star; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4943", + "X-RateLimit-Reset": "1611538431", + "x-ratelimit-used": "57", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "FEDB:9997:871A4E:9D45ED:600E1833" + } + }, + "uuid": "a8dd4fb9-0ec7-4a93-b642-193312795e64", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_unstarred-users.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_unstarred-users.json new file mode 100644 index 0000000000..67eef7a242 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/repos_hub4j-test-org_github-api_unstarred-users.json @@ -0,0 +1,47 @@ +{ + "id": "a8dd4fb9-0ec7-4a93-b642-193312795e64", + "name": "repos_hub4j-test-org_github-api_stargazers", + "request": { + "url": "/repos/hub4j-test-org/github-api/stargazers", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "body": "[]", + "headers": { + "Date": "Mon, 25 Jan 2021 01:00:35 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding, Accept, X-Requested-With", + "Accept-Encoding" + ], + "ETag": "\"c0ae8d4e2de626e3c17a734d124e620264c64895ab868c0914ace984cce8cef8\"", + "X-OAuth-Scopes": "admin:org, admin:org_hook, admin:public_key, admin:repo_hook, delete_repo, gist, notifications, repo, user, workflow, write:discussion", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "github.v3; param=star; format=json", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4943", + "X-RateLimit-Reset": "1611538431", + "x-ratelimit-used": "57", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "FEDB:9997:871A4E:9D45ED:600E1833" + } + }, + "uuid": "a8dd4fb9-0ec7-4a93-b642-193312795e64", + "persistent": true, + "insertionIndex": 4 +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/user.json b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/user.json new file mode 100644 index 0000000000..1a514ad25a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHRepositoryTest/wiremock/starTest/mappings/user.json @@ -0,0 +1,48 @@ +{ + "id": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "name": "user", + "request": { + "url": "/users/hub4j-test-org", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github.v3+json" + } + } + }, + "response": { + "status": 200, + "bodyFileName": "user.json", + "headers": { + "Date": "Wed, 25 Sep 2019 23:35:33 GMT", + "Content-Type": "application/json; charset=utf-8", + "Server": "GitHub.com", + "Status": "200 OK", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4992", + "X-RateLimit-Reset": "1569457884", + "Cache-Control": "private, max-age=60, s-maxage=60", + "Vary": [ + "Accept, Authorization, Cookie, X-GitHub-OTP", + "Accept-Encoding" + ], + "ETag": "W/\"14ffd29009ddc2209c450bb29a5a8330\"", + "Last-Modified": "Tue, 24 Sep 2019 19:32:29 GMT", + "X-OAuth-Scopes": "gist, notifications, read:org, read:public_key, read:repo_hook, repo", + "X-Accepted-OAuth-Scopes": "", + "X-GitHub-Media-Type": "unknown, github.v3", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "1; mode=block", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "X-GitHub-Request-Id": "F845:5D1D:FFA88A:12FE539:5D8BF9C5" + } + }, + "uuid": "7f6e9a01-5bfa-4f72-9947-07df902f56c3", + "persistent": true, + "insertionIndex": 1 +} \ No newline at end of file From c25e1d5bcd5619a46f243c79087fde75ec215ded Mon Sep 17 00:00:00 2001 From: antrix190 Date: Tue, 20 Dec 2022 18:00:32 +0530 Subject: [PATCH 4/6] Addressing review comments. --- src/main/java/org/kohsuke/github/GHRepository.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 9b187b7b1f..6aae09e305 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -3146,13 +3146,6 @@ String getApiTailUrl(String tail) { return "/repos/" + full_name + tail; } - String getApiHeadUrl(String head) { - if (head.length() > 0 && !head.endsWith("/")) { - head = '/' + head; - } - return "/user" + head + "/" + getOwnerName() + "/" + name; - } - /** * Get all issue events for this repository. See * https://developer.github.com/v3/issues/events/#list-events-for-a-repository @@ -3505,7 +3498,8 @@ protected Updater(@Nonnull GHRepository repository) { * the io exception */ public void star() throws IOException { - root().createRequest().method("PUT").withUrlPath(getApiHeadUrl("starred")).send(); + root().createRequest().method("PUT") + .withUrlPath(String.format("/user/starred/%s",full_name)).send(); } /** @@ -3515,7 +3509,8 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - root().createRequest().method("DELETE").withUrlPath(getApiHeadUrl("starred")).send(); + root().createRequest().method("DELETE") + .withUrlPath(String.format("/user/starred/%s",full_name)).send(); } /** From f170c97336000b5aef4c8884b32f497d37f7dd74 Mon Sep 17 00:00:00 2001 From: antrix190 Date: Wed, 21 Dec 2022 12:58:35 +0530 Subject: [PATCH 5/6] Format voilation fix --- src/main/java/org/kohsuke/github/GHRepository.java | 6 ++---- src/test/java/org/kohsuke/github/GHRepositoryTest.java | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index 6aae09e305..cff85d8a03 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -3498,8 +3498,7 @@ protected Updater(@Nonnull GHRepository repository) { * the io exception */ public void star() throws IOException { - root().createRequest().method("PUT") - .withUrlPath(String.format("/user/starred/%s",full_name)).send(); + root().createRequest().method("PUT").withUrlPath(String.format("/user/starred/%s", full_name)).send(); } /** @@ -3509,8 +3508,7 @@ public void star() throws IOException { * the io exception */ public void unstar() throws IOException { - root().createRequest().method("DELETE") - .withUrlPath(String.format("/user/starred/%s",full_name)).send(); + root().createRequest().method("DELETE").withUrlPath(String.format("/user/starred/%s", full_name)).send(); } /** diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index e4b48d8cac..50269013fe 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -20,7 +20,6 @@ import java.util.Set; import java.util.stream.Collectors; -import static org.apache.commons.lang3.ObjectUtils.isNotEmpty; import static org.hamcrest.Matchers.*; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.Assert.assertEquals; From e46b3b5603ed7029df1ef6461f03c0b2c4a82a58 Mon Sep 17 00:00:00 2001 From: antrix190 Date: Wed, 21 Dec 2022 23:23:19 +0530 Subject: [PATCH 6/6] Javadoc addition --- .../java/org/kohsuke/github/GHRepositoryTest.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/kohsuke/github/GHRepositoryTest.java b/src/test/java/org/kohsuke/github/GHRepositoryTest.java index 50269013fe..bd168f432e 100644 --- a/src/test/java/org/kohsuke/github/GHRepositoryTest.java +++ b/src/test/java/org/kohsuke/github/GHRepositoryTest.java @@ -22,7 +22,6 @@ import static org.hamcrest.Matchers.*; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.kohsuke.github.GHVerification.Reason.*; @@ -1540,15 +1539,21 @@ public void createSecret() throws Exception { repo.createSecret("secret", "encrypted", "public"); } + /** + * Test to check star method by verifying stargarzer count. + * + * @throws Exception + * the exception + */ @Test public void starTest() throws Exception { String owner = "hub4j-test-org"; GHRepository repository = getRepository(); - assertEquals(owner, repository.getOwner().getLogin()); - assertEquals(0, repository.getStargazersCount()); + assertThat(repository.getOwner().getLogin(), equalTo(owner)); + assertThat(repository.getStargazersCount(), is(0)); repository.star(); - assertEquals(1, repository.listStargazers2().toList().size()); + assertThat(repository.listStargazers2().toList().size(), is(1)); repository.unstar(); - assertEquals(0, repository.listStargazers().toList().size()); + assertThat(repository.listStargazers().toList().size(), is(0)); } }