Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#690]Implement the ability to read total_private_repos for GHPerson #691

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/org/kohsuke/github/GHPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;

/**
Expand All @@ -28,6 +29,9 @@ public abstract class GHPerson extends GHObject {
protected int followers, following, public_repos, public_gists;
protected boolean site_admin;

// other fields (that only show up in full data) that require privileged scope
protected Integer total_private_repos;

GHPerson wrapUp(GitHub root) {
this.root = root;
return this;
Expand Down Expand Up @@ -346,4 +350,16 @@ public boolean isSiteAdmin() throws IOException {
populate();
return site_admin;
}

/**
* Gets total private repo count.
*
* @return the total private repo count
* @throws IOException
* the io exception
*/
public Optional<Integer> getTotalPrivateRepoCount() throws IOException {
populate();
return Optional.ofNullable(total_private_repos);
}
}
23 changes: 18 additions & 5 deletions src/test/java/org/kohsuke/github/GHUserTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.kohsuke.github;

import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.util.*;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.Matchers.greaterThan;

public class GHUserTest extends AbstractGitHubWireMockTest {
@Test
Expand Down Expand Up @@ -87,4 +84,20 @@ public void listPublicRepositoriesPageSize62() throws IOException {
assertThat(i, equalTo(115));
}

@Test
public void createAndCountPrivateRepos() throws IOException {
String login = gitHub.getMyself().getLogin();

GHRepository repository = gitHub.createRepository("github-user-test-private-repo")
.description("a test private repository used to test kohsuke's github-api")
.homepage("http://github-api.kohsuke.org/").private_(true).create();

try {
Assert.assertNotNull(repository);
GHUser ghUser = gitHub.getUser(login);
assertThat(ghUser.getTotalPrivateRepoCount().orElse(-1), greaterThan(0));
} finally {
repository.delete();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"login": "kohsuke",
"id": 5396306,
"node_id": "MDQ6VXNlcjUzOTYzMDY=",
"avatar_url": "https://avatars3.githubusercontent.com/u/5396306?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kohsuke",
"html_url": "https://github.com/kohsuke",
"followers_url": "https://api.github.com/users/kohsuke/followers",
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
"repos_url": "https://api.github.com/users/kohsuke/repos",
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
"type": "User",
"site_admin": false,
"name": "Sage Pierce",
"company": "@Vrbo @ExpediaGroup",
"blog": "",
"location": null,
"email": "[email protected]",
"hireable": true,
"bio": "Software engineer with a Masters of Science in Electrical and Computer Engineering out of The University of Texas at Austin.",
"public_repos": 9,
"public_gists": 0,
"followers": 4,
"following": 0,
"created_at": "2013-09-06T02:22:48Z",
"updated_at": "2020-01-31T17:19:20Z",
"private_gists": 0,
"total_private_repos": 0,
"owned_private_repos": 0,
"disk_usage": 1816,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"id": 237495575,
"node_id": "MDEwOlJlcG9zaXRvcnkyMzc0OTU1NzU=",
"name": "github-user-test-private-repo",
"full_name": "kohsuke/github-user-test-private-repo",
"private": true,
"owner": {
"login": "kohsuke",
"id": 5396306,
"node_id": "MDQ6VXNlcjUzOTYzMDY=",
"avatar_url": "https://avatars3.githubusercontent.com/u/5396306?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kohsuke",
"html_url": "https://github.com/kohsuke",
"followers_url": "https://api.github.com/users/kohsuke/followers",
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
"repos_url": "https://api.github.com/users/kohsuke/repos",
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/kohsuke/github-user-test-private-repo",
"description": "a test private repository used to test kohsuke's github-api",
"fork": false,
"url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo",
"forks_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/forks",
"keys_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/teams",
"hooks_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/hooks",
"issue_events_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/issues/events{/number}",
"events_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/events",
"assignees_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/assignees{/user}",
"branches_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/branches{/branch}",
"tags_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/tags",
"blobs_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/statuses/{sha}",
"languages_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/languages",
"stargazers_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/stargazers",
"contributors_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/contributors",
"subscribers_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/subscribers",
"subscription_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/subscription",
"commits_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/contents/{+path}",
"compare_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/merges",
"archive_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/downloads",
"issues_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/issues{/number}",
"pulls_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/pulls{/number}",
"milestones_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/milestones{/number}",
"notifications_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/labels{/name}",
"releases_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/releases{/id}",
"deployments_url": "https://api.github.com/repos/kohsuke/github-user-test-private-repo/deployments",
"created_at": "2020-01-31T18:52:44Z",
"updated_at": "2020-01-31T18:52:44Z",
"pushed_at": "2020-01-31T18:52:45Z",
"git_url": "git://github.com/kohsuke/github-user-test-private-repo.git",
"ssh_url": "[email protected]:kohsuke/github-user-test-private-repo.git",
"clone_url": "https://github.com/kohsuke/github-user-test-private-repo.git",
"svn_url": "https://github.com/kohsuke/github-user-test-private-repo",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"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": null,
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master",
"permissions": {
"admin": true,
"push": true,
"pull": true
},
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"delete_branch_on_merge": false,
"network_count": 0,
"subscribers_count": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"login": "kohsuke",
"id": 5396306,
"node_id": "MDQ6VXNlcjUzOTYzMDY=",
"avatar_url": "https://avatars3.githubusercontent.com/u/5396306?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/kohsuke",
"html_url": "https://github.com/kohsuke",
"followers_url": "https://api.github.com/users/kohsuke/followers",
"following_url": "https://api.github.com/users/kohsuke/following{/other_user}",
"gists_url": "https://api.github.com/users/kohsuke/gists{/gist_id}",
"starred_url": "https://api.github.com/users/kohsuke/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/kohsuke/subscriptions",
"organizations_url": "https://api.github.com/users/kohsuke/orgs",
"repos_url": "https://api.github.com/users/kohsuke/repos",
"events_url": "https://api.github.com/users/kohsuke/events{/privacy}",
"received_events_url": "https://api.github.com/users/kohsuke/received_events",
"type": "User",
"site_admin": false,
"name": "Sage Pierce",
"company": "@Vrbo @ExpediaGroup",
"blog": "",
"location": null,
"email": "[email protected]",
"hireable": true,
"bio": "Software engineer with a Masters of Science in Electrical and Computer Engineering out of The University of Texas at Austin.",
"public_repos": 9,
"public_gists": 0,
"followers": 4,
"following": 0,
"created_at": "2013-09-06T02:22:48Z",
"updated_at": "2020-01-31T17:19:20Z",
"private_gists": 0,
"total_private_repos": 1,
"owned_private_repos": 1,
"disk_usage": 1816,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"id": "666cac17-c8fc-49b9-a2eb-b9667c2ea446",
"name": "repos_kohsuke_github-user-test-private-repo",
"request": {
"url": "/repos/kohsuke/github-user-test-private-repo",
"method": "DELETE",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 204,
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 31 Jan 2020 18:52:46 GMT",
"Status": "204 No Content",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4950",
"X-RateLimit-Reset": "1580498839",
"X-OAuth-Scopes": "delete_repo, repo, user",
"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": "3123:3DD0:725FE2:11566AB:5E34777E"
}
},
"uuid": "666cac17-c8fc-49b9-a2eb-b9667c2ea446",
"persistent": true,
"insertionIndex": 4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"id": "9c77ca90-ac6b-4375-8c32-7669b7dec98d",
"name": "user",
"request": {
"url": "/user",
"method": "GET",
"headers": {
"Accept": {
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
}
}
},
"response": {
"status": 200,
"bodyFileName": "user-9c77ca90-ac6b-4375-8c32-7669b7dec98d.json",
"headers": {
"Server": "GitHub.com",
"Date": "Fri, 31 Jan 2020 18:52:44 GMT",
"Content-Type": "application/json; charset=utf-8",
"Status": "200 OK",
"X-RateLimit-Limit": "5000",
"X-RateLimit-Remaining": "4954",
"X-RateLimit-Reset": "1580498839",
"Cache-Control": "private, max-age=60, s-maxage=60",
"Vary": "Accept, Authorization, Cookie, X-GitHub-OTP",
"ETag": "W/\"444582ac6464d28b8a4c8914fb11b2ea\"",
"Last-Modified": "Fri, 31 Jan 2020 17:19:20 GMT",
"X-OAuth-Scopes": "delete_repo, repo, user",
"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": "3123:3DD0:725F2C:115653E:5E34777B"
}
},
"uuid": "9c77ca90-ac6b-4375-8c32-7669b7dec98d",
"persistent": true,
"insertionIndex": 1
}
Loading