Skip to content

Commit

Permalink
Merge pull request #1372 from antrix190/main
Browse files Browse the repository at this point in the history
Adding Star/Unstar Methods
  • Loading branch information
bitwiseman authored Feb 26, 2023
2 parents 1dcedba + b898bdb commit 44b184a
Show file tree
Hide file tree
Showing 13 changed files with 737 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,26 @@ protected Updater(@Nonnull GHRepository repository) {
}
}

/**
* Star a repository.
*
* @throws IOException
* the io exception
*/
public void star() throws IOException {
root().createRequest().method("PUT").withUrlPath(String.format("/user/starred/%s", full_name)).send();
}

/**
* Unstar a repository.
*
* @throws IOException
* the io exception
*/
public void unstar() throws IOException {
root().createRequest().method("DELETE").withUrlPath(String.format("/user/starred/%s", full_name)).send();
}

/**
* A {@link GHRepositoryBuilder} that allows multiple properties to be updated per request.
*
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1563,4 +1563,22 @@ public void createSecret() throws Exception {
GHRepository repo = getTempRepository();
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();
assertThat(repository.getOwner().getLogin(), equalTo(owner));
assertThat(repository.getStargazersCount(), is(0));
repository.star();
assertThat(repository.listStargazers2().toList().size(), is(1));
repository.unstar();
assertThat(repository.listStargazers().toList().size(), is(0));
}
}
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
]

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
"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"
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit 44b184a

Please sign in to comment.