Skip to content

Commit 68cabc7

Browse files
authored
Merge pull request #1183 from t0m4uk1991/add_get_projects_method
Add list projects method for GHUser
2 parents fb69457 + 7dbccd2 commit 68cabc7

File tree

8 files changed

+365
-0
lines changed

8 files changed

+365
-0
lines changed

src/main/java/org/kohsuke/github/GHUser.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.io.IOException;
2929
import java.util.*;
3030

31+
import static org.kohsuke.github.internal.Previews.INERTIA;
32+
3133
/**
3234
* Represents an user of GitHub.
3335
*
@@ -134,6 +136,22 @@ public PagedIterable<GHRepository> listStarredRepositories() {
134136
return listRepositories("starred");
135137
}
136138

139+
/**
140+
* Lists all the projects.
141+
* <p>
142+
* https://docs.github.com/en/rest/reference/projects#list-user-projects
143+
*
144+
* @return the paged iterable
145+
*/
146+
@Deprecated
147+
@Preview(INERTIA)
148+
public PagedIterable<GHProject> listProjects() {
149+
return root.createRequest()
150+
.withPreview(INERTIA)
151+
.withUrlPath(getApiTailUrl("projects"))
152+
.toIterable(GHProject[].class, item -> item.wrap(root));
153+
}
154+
137155
private PagedIterable<GHRepository> listRepositories(final String suffix) {
138156
return root.createRequest()
139157
.withUrlPath(getApiTailUrl(suffix))

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ public void listPublicRepositories() throws IOException {
8181
assertThat(i, equalTo(115));
8282
}
8383

84+
@Test
85+
public void listProjects() throws IOException {
86+
GHUser user = gitHub.getUser("t0m4uk1991");
87+
List<GHProject> projects = user.listProjects().toList();
88+
assertThat(projects, notNullValue());
89+
assertThat(projects.size(), is(3));
90+
assertThat(projects.get(0).getName(), is("Project 1"));
91+
assertThat(projects.get(1).getName(), is("Project 2"));
92+
assertThat(projects.get(2).getName(), is("Project 3"));
93+
}
94+
8495
@Test
8596
public void listPublicRepositoriesPageSize62() throws IOException {
8697
GHUser user = gitHub.getUser("kohsuke");
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "t0m4uk1991",
3+
"id": 6698785,
4+
"node_id": "MDQ6VXNlcjY2OTg3ODU=",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/6698785?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/t0m4uk1991",
8+
"html_url": "https://github.com/t0m4uk1991",
9+
"followers_url": "https://api.github.com/users/t0m4uk1991/followers",
10+
"following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions",
14+
"organizations_url": "https://api.github.com/users/t0m4uk1991/orgs",
15+
"repos_url": "https://api.github.com/users/t0m4uk1991/repos",
16+
"events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/t0m4uk1991/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": null,
21+
"company": null,
22+
"blog": "https://t0m4uk1991.github.io",
23+
"location": "Ukraine",
24+
"email": "[email protected]",
25+
"hireable": true,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 14,
29+
"public_gists": 10,
30+
"followers": 2,
31+
"following": 2,
32+
"created_at": "2014-02-16T20:43:03Z",
33+
"updated_at": "2021-06-05T08:38:35Z",
34+
"private_gists": 2,
35+
"total_private_repos": 16,
36+
"owned_private_repos": 16,
37+
"disk_usage": 23717,
38+
"collaborators": 0,
39+
"two_factor_authentication": false,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "t0m4uk1991",
3+
"id": 6698785,
4+
"node_id": "MDQ6VXNlcjY2OTg3ODU=",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/6698785?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/t0m4uk1991",
8+
"html_url": "https://github.com/t0m4uk1991",
9+
"followers_url": "https://api.github.com/users/t0m4uk1991/followers",
10+
"following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions",
14+
"organizations_url": "https://api.github.com/users/t0m4uk1991/orgs",
15+
"repos_url": "https://api.github.com/users/t0m4uk1991/repos",
16+
"events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/t0m4uk1991/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": null,
21+
"company": null,
22+
"blog": "https://t0m4uk1991.github.io",
23+
"location": "Ukraine",
24+
"email": "[email protected]",
25+
"hireable": true,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 14,
29+
"public_gists": 10,
30+
"followers": 2,
31+
"following": 2,
32+
"created_at": "2014-02-16T20:43:03Z",
33+
"updated_at": "2021-06-05T08:38:35Z",
34+
"private_gists": 2,
35+
"total_private_repos": 16,
36+
"owned_private_repos": 16,
37+
"disk_usage": 23717,
38+
"collaborators": 0,
39+
"two_factor_authentication": false,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
[
2+
{
3+
"owner_url": "https://api.github.com/users/t0m4uk1991",
4+
"url": "https://api.github.com/projects/12651120",
5+
"html_url": "https://github.com/users/t0m4uk1991/projects/3",
6+
"columns_url": "https://api.github.com/projects/12651120/columns",
7+
"id": 12651120,
8+
"node_id": "MDc6UHJvamVjdDEyNjUxMTIw",
9+
"name": "Project 1",
10+
"body": "Project 1",
11+
"number": 3,
12+
"state": "open",
13+
"creator": {
14+
"login": "t0m4uk1991",
15+
"id": 6698785,
16+
"node_id": "MDQ6VXNlcjY2OTg3ODU=",
17+
"avatar_url": "https://avatars.githubusercontent.com/u/6698785?u=dcfcdb0aa9e86943f3783dfdbe83be39de599a5d&v=4",
18+
"gravatar_id": "",
19+
"url": "https://api.github.com/users/t0m4uk1991",
20+
"html_url": "https://github.com/t0m4uk1991",
21+
"followers_url": "https://api.github.com/users/t0m4uk1991/followers",
22+
"following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}",
23+
"gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}",
24+
"starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}",
25+
"subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions",
26+
"organizations_url": "https://api.github.com/users/t0m4uk1991/orgs",
27+
"repos_url": "https://api.github.com/users/t0m4uk1991/repos",
28+
"events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}",
29+
"received_events_url": "https://api.github.com/users/t0m4uk1991/received_events",
30+
"type": "User",
31+
"site_admin": false
32+
},
33+
"created_at": "2021-06-10T17:58:40Z",
34+
"updated_at": "2021-06-10T17:58:40Z"
35+
},
36+
{
37+
"owner_url": "https://api.github.com/users/t0m4uk1991",
38+
"url": "https://api.github.com/projects/12651122",
39+
"html_url": "https://github.com/users/t0m4uk1991/projects/4",
40+
"columns_url": "https://api.github.com/projects/12651122/columns",
41+
"id": 12651122,
42+
"node_id": "MDc6UHJvamVjdDEyNjUxMTIy",
43+
"name": "Project 2",
44+
"body": "Project 2",
45+
"number": 4,
46+
"state": "open",
47+
"creator": {
48+
"login": "t0m4uk1991",
49+
"id": 6698785,
50+
"node_id": "MDQ6VXNlcjY2OTg3ODU=",
51+
"avatar_url": "https://avatars.githubusercontent.com/u/6698785?u=dcfcdb0aa9e86943f3783dfdbe83be39de599a5d&v=4",
52+
"gravatar_id": "",
53+
"url": "https://api.github.com/users/t0m4uk1991",
54+
"html_url": "https://github.com/t0m4uk1991",
55+
"followers_url": "https://api.github.com/users/t0m4uk1991/followers",
56+
"following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}",
57+
"gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}",
58+
"starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}",
59+
"subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions",
60+
"organizations_url": "https://api.github.com/users/t0m4uk1991/orgs",
61+
"repos_url": "https://api.github.com/users/t0m4uk1991/repos",
62+
"events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}",
63+
"received_events_url": "https://api.github.com/users/t0m4uk1991/received_events",
64+
"type": "User",
65+
"site_admin": false
66+
},
67+
"created_at": "2021-06-10T17:58:59Z",
68+
"updated_at": "2021-06-10T17:58:59Z"
69+
},
70+
{
71+
"owner_url": "https://api.github.com/users/t0m4uk1991",
72+
"url": "https://api.github.com/projects/12651123",
73+
"html_url": "https://github.com/users/t0m4uk1991/projects/5",
74+
"columns_url": "https://api.github.com/projects/12651123/columns",
75+
"id": 12651123,
76+
"node_id": "MDc6UHJvamVjdDEyNjUxMTIz",
77+
"name": "Project 3",
78+
"body": "Project 3",
79+
"number": 5,
80+
"state": "open",
81+
"creator": {
82+
"login": "t0m4uk1991",
83+
"id": 6698785,
84+
"node_id": "MDQ6VXNlcjY2OTg3ODU=",
85+
"avatar_url": "https://avatars.githubusercontent.com/u/6698785?u=dcfcdb0aa9e86943f3783dfdbe83be39de599a5d&v=4",
86+
"gravatar_id": "",
87+
"url": "https://api.github.com/users/t0m4uk1991",
88+
"html_url": "https://github.com/t0m4uk1991",
89+
"followers_url": "https://api.github.com/users/t0m4uk1991/followers",
90+
"following_url": "https://api.github.com/users/t0m4uk1991/following{/other_user}",
91+
"gists_url": "https://api.github.com/users/t0m4uk1991/gists{/gist_id}",
92+
"starred_url": "https://api.github.com/users/t0m4uk1991/starred{/owner}{/repo}",
93+
"subscriptions_url": "https://api.github.com/users/t0m4uk1991/subscriptions",
94+
"organizations_url": "https://api.github.com/users/t0m4uk1991/orgs",
95+
"repos_url": "https://api.github.com/users/t0m4uk1991/repos",
96+
"events_url": "https://api.github.com/users/t0m4uk1991/events{/privacy}",
97+
"received_events_url": "https://api.github.com/users/t0m4uk1991/received_events",
98+
"type": "User",
99+
"site_admin": false
100+
},
101+
"created_at": "2021-06-10T17:59:15Z",
102+
"updated_at": "2021-06-10T17:59:15Z"
103+
}
104+
]
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "a20bf0ec-d676-4f9e-aaa0-b64e16887305",
3+
"name": "user",
4+
"request": {
5+
"url": "/user",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "user-1.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 10 Jun 2021 18:03:47 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"b7fb71c9f9723032eb235ddd346b34ab754f2b41d8a907c802131f8a771d71bb\"",
26+
"Last-Modified": "Sat, 05 Jun 2021 08:38:35 GMT",
27+
"X-OAuth-Scopes": "admin:org, repo, user",
28+
"X-Accepted-OAuth-Scopes": "",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4992",
32+
"X-RateLimit-Reset": "1623349987",
33+
"X-RateLimit-Used": "8",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "8DED:76B6:1A5518:1AEA33:60C25402"
42+
}
43+
},
44+
"uuid": "a20bf0ec-d676-4f9e-aaa0-b64e16887305",
45+
"persistent": true,
46+
"insertionIndex": 1
47+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "50b95df9-b365-4f47-a298-756999a88046",
3+
"name": "users_t0m4uk1991",
4+
"request": {
5+
"url": "/users/t0m4uk1991",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "users_t0m4uk1991-2.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 10 Jun 2021 18:03:48 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"b7fb71c9f9723032eb235ddd346b34ab754f2b41d8a907c802131f8a771d71bb\"",
26+
"Last-Modified": "Sat, 05 Jun 2021 08:38:35 GMT",
27+
"X-OAuth-Scopes": "admin:org, repo, user",
28+
"X-Accepted-OAuth-Scopes": "",
29+
"X-GitHub-Media-Type": "unknown, github.v3",
30+
"X-RateLimit-Limit": "5000",
31+
"X-RateLimit-Remaining": "4990",
32+
"X-RateLimit-Reset": "1623349987",
33+
"X-RateLimit-Used": "10",
34+
"X-RateLimit-Resource": "core",
35+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
36+
"X-Frame-Options": "deny",
37+
"X-Content-Type-Options": "nosniff",
38+
"X-XSS-Protection": "0",
39+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
40+
"Content-Security-Policy": "default-src 'none'",
41+
"X-GitHub-Request-Id": "1F30:2A5E:63945:69C68:60C25404"
42+
}
43+
},
44+
"uuid": "50b95df9-b365-4f47-a298-756999a88046",
45+
"persistent": true,
46+
"insertionIndex": 2
47+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"id": "a9d6c6bb-6be3-486a-9beb-17f1270fbfa9",
3+
"name": "users_t0m4uk1991_projects",
4+
"request": {
5+
"url": "/users/t0m4uk1991/projects",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.inertia-preview+json"
10+
}
11+
}
12+
},
13+
"response": {
14+
"status": 200,
15+
"bodyFileName": "users_t0m4uk1991_projects-3.json",
16+
"headers": {
17+
"Server": "GitHub.com",
18+
"Date": "Thu, 10 Jun 2021 18:03:48 GMT",
19+
"Content-Type": "application/json; charset=utf-8",
20+
"Cache-Control": "private, max-age=60, s-maxage=60",
21+
"Vary": [
22+
"Accept, Authorization, Cookie, X-GitHub-OTP",
23+
"Accept-Encoding, Accept, X-Requested-With"
24+
],
25+
"ETag": "W/\"ca6ae9200bb8d394dfb5a5f588e60071af37a4c8f23daf2e3e0ee8c305ab1e91\"",
26+
"X-OAuth-Scopes": "admin:org, repo, user",
27+
"X-Accepted-OAuth-Scopes": "repo",
28+
"X-GitHub-Media-Type": "github.inertia-preview; format=json",
29+
"X-RateLimit-Limit": "5000",
30+
"X-RateLimit-Remaining": "4989",
31+
"X-RateLimit-Reset": "1623349987",
32+
"X-RateLimit-Used": "11",
33+
"X-RateLimit-Resource": "core",
34+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
35+
"X-Frame-Options": "deny",
36+
"X-Content-Type-Options": "nosniff",
37+
"X-XSS-Protection": "0",
38+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
39+
"Content-Security-Policy": "default-src 'none'",
40+
"X-GitHub-Request-Id": "AC93:2A60:1A7CBA:1B1351:60C25404"
41+
}
42+
},
43+
"uuid": "a9d6c6bb-6be3-486a-9beb-17f1270fbfa9",
44+
"persistent": true,
45+
"insertionIndex": 3
46+
}

0 commit comments

Comments
 (0)