Skip to content

Commit b4ac83a

Browse files
authored
Merge pull request hub4j#1642 from PierreBtz/pbeitz/get-user-public-events
Add support for the public events for user API
2 parents 77f7f81 + 0fa0274 commit b4ac83a

24 files changed

+50409
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,23 @@ public List<GHEventInfo> getEvents() throws IOException {
915915
return createRequest().withUrlPath("/events").toIterable(GHEventInfo[].class, null).toList();
916916
}
917917

918+
/**
919+
* List public events for a user
920+
* <a href="https://docs.github.com/en/rest/activity/events?apiVersion=2022-11-28#list-public-events-for-a-user">see
921+
* API documentation</a>
922+
*
923+
* @param login
924+
* the login (user) to look public events for
925+
* @return the events
926+
* @throws IOException
927+
* the io exception
928+
*/
929+
public List<GHEventInfo> getUserPublicEvents(String login) throws IOException {
930+
return createRequest().withUrlPath("/users/" + login + "/events/public")
931+
.toIterable(GHEventInfo[].class, null)
932+
.toList();
933+
}
934+
918935
/**
919936
* Gets a single gist by ID.
920937
*

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,30 @@ public void testEventApi() throws Exception {
10361036
}
10371037
}
10381038

1039+
/**
1040+
* Test user public event api.
1041+
*
1042+
* @throws Exception
1043+
* the exception
1044+
*/
1045+
@Test
1046+
public void testUserPublicEventApi() throws Exception {
1047+
for (GHEventInfo ev : gitHub.getUserPublicEvents("PierreBtz")) {
1048+
if (ev.getType() == GHEvent.PULL_REQUEST) {
1049+
if (ev.getId() == 27449881624L) {
1050+
assertThat(ev.getActorLogin(), equalTo("PierreBtz"));
1051+
assertThat(ev.getOrganization().getLogin(), equalTo("hub4j"));
1052+
assertThat(ev.getRepository().getFullName(), equalTo("hub4j/github-api"));
1053+
assertThat(ev.getCreatedAt(), equalTo(GitHubClient.parseDate("2023-03-02T16:37:49Z")));
1054+
assertThat(ev.getType(), equalTo(GHEvent.PULL_REQUEST));
1055+
}
1056+
1057+
GHEventPayload.PullRequest pr = ev.getPayload(GHEventPayload.PullRequest.class);
1058+
assertThat(pr.getNumber(), is(pr.getPullRequest().getNumber()));
1059+
}
1060+
}
1061+
}
1062+
10391063
/**
10401064
* Test app.
10411065
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"login": "hub4j",
3+
"id": 54909825,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
5+
"url": "https://api.github.com/orgs/hub4j",
6+
"repos_url": "https://api.github.com/orgs/hub4j/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/54909825?v=4",
13+
"description": null,
14+
"is_verified": false,
15+
"has_organization_projects": true,
16+
"has_repository_projects": true,
17+
"public_repos": 1,
18+
"public_gists": 0,
19+
"followers": 0,
20+
"following": 0,
21+
"html_url": "https://github.com/hub4j",
22+
"created_at": "2019-09-04T18:12:34Z",
23+
"updated_at": "2020-05-08T21:26:19Z",
24+
"type": "Organization"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
{
2+
"id": 617210,
3+
"node_id": "MDEwOlJlcG9zaXRvcnk2MTcyMTA=",
4+
"name": "github-api",
5+
"full_name": "hub4j/github-api",
6+
"private": false,
7+
"owner": {
8+
"login": "hub4j",
9+
"id": 54909825,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/54909825?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j",
14+
"html_url": "https://github.com/hub4j",
15+
"followers_url": "https://api.github.com/users/hub4j/followers",
16+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j/repos",
22+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
24+
"type": "Organization",
25+
"site_admin": false
26+
},
27+
"html_url": "https://github.com/hub4j/github-api",
28+
"description": "Java API for GitHub",
29+
"fork": false,
30+
"url": "https://api.github.com/repos/hub4j/github-api",
31+
"forks_url": "https://api.github.com/repos/hub4j/github-api/forks",
32+
"keys_url": "https://api.github.com/repos/hub4j/github-api/keys{/key_id}",
33+
"collaborators_url": "https://api.github.com/repos/hub4j/github-api/collaborators{/collaborator}",
34+
"teams_url": "https://api.github.com/repos/hub4j/github-api/teams",
35+
"hooks_url": "https://api.github.com/repos/hub4j/github-api/hooks",
36+
"issue_events_url": "https://api.github.com/repos/hub4j/github-api/issues/events{/number}",
37+
"events_url": "https://api.github.com/repos/hub4j/github-api/events",
38+
"assignees_url": "https://api.github.com/repos/hub4j/github-api/assignees{/user}",
39+
"branches_url": "https://api.github.com/repos/hub4j/github-api/branches{/branch}",
40+
"tags_url": "https://api.github.com/repos/hub4j/github-api/tags",
41+
"blobs_url": "https://api.github.com/repos/hub4j/github-api/git/blobs{/sha}",
42+
"git_tags_url": "https://api.github.com/repos/hub4j/github-api/git/tags{/sha}",
43+
"git_refs_url": "https://api.github.com/repos/hub4j/github-api/git/refs{/sha}",
44+
"trees_url": "https://api.github.com/repos/hub4j/github-api/git/trees{/sha}",
45+
"statuses_url": "https://api.github.com/repos/hub4j/github-api/statuses/{sha}",
46+
"languages_url": "https://api.github.com/repos/hub4j/github-api/languages",
47+
"stargazers_url": "https://api.github.com/repos/hub4j/github-api/stargazers",
48+
"contributors_url": "https://api.github.com/repos/hub4j/github-api/contributors",
49+
"subscribers_url": "https://api.github.com/repos/hub4j/github-api/subscribers",
50+
"subscription_url": "https://api.github.com/repos/hub4j/github-api/subscription",
51+
"commits_url": "https://api.github.com/repos/hub4j/github-api/commits{/sha}",
52+
"git_commits_url": "https://api.github.com/repos/hub4j/github-api/git/commits{/sha}",
53+
"comments_url": "https://api.github.com/repos/hub4j/github-api/comments{/number}",
54+
"issue_comment_url": "https://api.github.com/repos/hub4j/github-api/issues/comments{/number}",
55+
"contents_url": "https://api.github.com/repos/hub4j/github-api/contents/{+path}",
56+
"compare_url": "https://api.github.com/repos/hub4j/github-api/compare/{base}...{head}",
57+
"merges_url": "https://api.github.com/repos/hub4j/github-api/merges",
58+
"archive_url": "https://api.github.com/repos/hub4j/github-api/{archive_format}{/ref}",
59+
"downloads_url": "https://api.github.com/repos/hub4j/github-api/downloads",
60+
"issues_url": "https://api.github.com/repos/hub4j/github-api/issues{/number}",
61+
"pulls_url": "https://api.github.com/repos/hub4j/github-api/pulls{/number}",
62+
"milestones_url": "https://api.github.com/repos/hub4j/github-api/milestones{/number}",
63+
"notifications_url": "https://api.github.com/repos/hub4j/github-api/notifications{?since,all,participating}",
64+
"labels_url": "https://api.github.com/repos/hub4j/github-api/labels{/name}",
65+
"releases_url": "https://api.github.com/repos/hub4j/github-api/releases{/id}",
66+
"deployments_url": "https://api.github.com/repos/hub4j/github-api/deployments",
67+
"created_at": "2010-04-19T04:13:03Z",
68+
"updated_at": "2023-04-14T09:46:15Z",
69+
"pushed_at": "2023-04-14T09:41:23Z",
70+
"git_url": "git://github.com/hub4j/github-api.git",
71+
"ssh_url": "[email protected]:hub4j/github-api.git",
72+
"clone_url": "https://github.com/hub4j/github-api.git",
73+
"svn_url": "https://github.com/hub4j/github-api",
74+
"homepage": "https://github-api.kohsuke.org/",
75+
"size": 41026,
76+
"stargazers_count": 996,
77+
"watchers_count": 996,
78+
"language": "Java",
79+
"has_issues": true,
80+
"has_projects": true,
81+
"has_downloads": true,
82+
"has_wiki": true,
83+
"has_pages": true,
84+
"has_discussions": true,
85+
"forks_count": 669,
86+
"mirror_url": null,
87+
"archived": false,
88+
"disabled": false,
89+
"open_issues_count": 144,
90+
"license": {
91+
"key": "mit",
92+
"name": "MIT License",
93+
"spdx_id": "MIT",
94+
"url": "https://api.github.com/licenses/mit",
95+
"node_id": "MDc6TGljZW5zZTEz"
96+
},
97+
"allow_forking": true,
98+
"is_template": false,
99+
"web_commit_signoff_required": false,
100+
"topics": [
101+
"api",
102+
"client-library",
103+
"github",
104+
"github-api",
105+
"github-api-v3",
106+
"java",
107+
"java-api"
108+
],
109+
"visibility": "public",
110+
"forks": 669,
111+
"open_issues": 144,
112+
"watchers": 996,
113+
"default_branch": "main",
114+
"permissions": {
115+
"admin": false,
116+
"maintain": false,
117+
"push": false,
118+
"triage": false,
119+
"pull": true
120+
},
121+
"temp_clone_token": "",
122+
"organization": {
123+
"login": "hub4j",
124+
"id": 54909825,
125+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjU0OTA5ODI1",
126+
"avatar_url": "https://avatars.githubusercontent.com/u/54909825?v=4",
127+
"gravatar_id": "",
128+
"url": "https://api.github.com/users/hub4j",
129+
"html_url": "https://github.com/hub4j",
130+
"followers_url": "https://api.github.com/users/hub4j/followers",
131+
"following_url": "https://api.github.com/users/hub4j/following{/other_user}",
132+
"gists_url": "https://api.github.com/users/hub4j/gists{/gist_id}",
133+
"starred_url": "https://api.github.com/users/hub4j/starred{/owner}{/repo}",
134+
"subscriptions_url": "https://api.github.com/users/hub4j/subscriptions",
135+
"organizations_url": "https://api.github.com/users/hub4j/orgs",
136+
"repos_url": "https://api.github.com/users/hub4j/repos",
137+
"events_url": "https://api.github.com/users/hub4j/events{/privacy}",
138+
"received_events_url": "https://api.github.com/users/hub4j/received_events",
139+
"type": "Organization",
140+
"site_admin": false
141+
},
142+
"network_count": 669,
143+
"subscribers_count": 44
144+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"login": "PierreBtz",
3+
"id": 9881659,
4+
"node_id": "MDQ6VXNlcjk4ODE2NTk=",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/9881659?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/PierreBtz",
8+
"html_url": "https://github.com/PierreBtz",
9+
"followers_url": "https://api.github.com/users/PierreBtz/followers",
10+
"following_url": "https://api.github.com/users/PierreBtz/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/PierreBtz/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/PierreBtz/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/PierreBtz/subscriptions",
14+
"organizations_url": "https://api.github.com/users/PierreBtz/orgs",
15+
"repos_url": "https://api.github.com/users/PierreBtz/repos",
16+
"events_url": "https://api.github.com/users/PierreBtz/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/PierreBtz/received_events",
18+
"type": "User",
19+
"site_admin": false,
20+
"name": "Pierre Beitz",
21+
"company": "@cloudbees ",
22+
"blog": "",
23+
"location": null,
24+
"email": "[email protected]",
25+
"hireable": null,
26+
"bio": null,
27+
"twitter_username": null,
28+
"public_repos": 88,
29+
"public_gists": 7,
30+
"followers": 13,
31+
"following": 11,
32+
"created_at": "2014-11-21T10:26:34Z",
33+
"updated_at": "2023-04-13T15:51:35Z",
34+
"private_gists": 25,
35+
"total_private_repos": 51,
36+
"owned_private_repos": 2,
37+
"disk_usage": 21381,
38+
"collaborators": 0,
39+
"two_factor_authentication": true,
40+
"plan": {
41+
"name": "free",
42+
"space": 976562499,
43+
"collaborators": 0,
44+
"private_repos": 10000
45+
}
46+
}

0 commit comments

Comments
 (0)