Skip to content

Commit 54ddd41

Browse files
authored
feature KnpLabs#1000 Events list per authenticated user for all repos (richard015ar)
This PR was squashed before being merged into the 3.2.x-dev branch. Discussion ---------- This change add a list of events for all repos for an authenticated user: https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user. It is pretty useful if you want to get a list of different [types of events](https://docs.github.com/en/developers/webhooks-and-events/github-event-types) without specify any repo. Commits ------- b565d6d Add list events for an authenticated user method 10a85ea Add docs and tests for List Events by Authenticated User method 3938a42 Fix lint for comment block 5534e25 Fix lint for comment block c520754 Add API unit test. Remove perPage and page parameters for events method 42f1f42 Add unit test for API
1 parent 26a838b commit 54ddd41

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

doc/activity.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ $activity = $client->api('current_user')->starring()->all();
3131
```
3232
Returns an array of starred repos.
3333

34+
### Get list of private and public events for an authenticated user for all repos
35+
36+
```php
37+
$activity = $client->api('user')->events('ornicar');
38+
```
39+
Returns an array of private and public events created for all repos related to the user.
40+
3441
### Get repos that a authenticated user has starred with creation date
3542

3643
Support for getting the star creation timestamp in the response, using the custom `Accept: application/vnd.github.v3.star+json` header.
@@ -100,4 +107,4 @@ $owner = "KnpLabs";
100107
$repo = "php-github-api";
101108
$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo);
102109
```
103-
Throws an Exception in case of failure or NULL in case of success.
110+
Throws an Exception in case of failure or NULL in case of success.

doc/users.md

+11
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ $users = $client->api('current_user')->starring()->all();
148148

149149
Returns an array of starred repos.
150150

151+
### Get the authenticated user activity
152+
153+
> Requires [authentication](security.md).
154+
155+
```php
156+
$activity = $client->api('user')->events('ornicar');
157+
```
158+
159+
Returns an array of private and public events created for all repos related to the user.
160+
> See [more](activity.md).
161+
151162
### Get the authenticated user emails
152163

153164
> Requires [authentication](security.md).

lib/Github/Api/User.php

+12
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,16 @@ public function publicEvents($username)
234234
{
235235
return $this->get('/users/'.rawurlencode($username).'/events/public');
236236
}
237+
238+
/**
239+
* List events performed by an authenticated user.
240+
*
241+
* @link https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user
242+
*
243+
* @return array
244+
*/
245+
public function events(string $username)
246+
{
247+
return $this->get('/users/'.rawurlencode($username).'/events');
248+
}
237249
}

test/Github/Tests/Api/UserTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,29 @@ public function shouldGetUserGists()
228228
$this->assertEquals($expectedArray, $api->gists('l3l0'));
229229
}
230230

231+
/**
232+
* @test
233+
*/
234+
public function shouldGetAuthorizedUserEvents()
235+
{
236+
$expectedArray = [
237+
[
238+
'id' => 1,
239+
'actor' => [
240+
'id' => 1,
241+
'login' => 'l3l0',
242+
],
243+
],
244+
];
245+
$api = $this->getApiMock();
246+
$api->expects($this->once())
247+
->method('get')
248+
->with('/users/l3l0/events')
249+
->will($this->returnValue($expectedArray));
250+
251+
$this->assertEquals($expectedArray, $api->events('l3l0'));
252+
}
253+
231254
/**
232255
* @return string
233256
*/

test/Github/Tests/Integration/UserTest.php

+21
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,25 @@ public function shouldGetReposBeingStarred()
138138
$this->assertArrayHasKey('git_url', $repo);
139139
$this->assertArrayHasKey('svn_url', $repo);
140140
}
141+
142+
/**
143+
* @test
144+
*/
145+
public function shouldGetEventsForAuthenticatedUserBeignWatched()
146+
{
147+
$username = 'l3l0';
148+
149+
$events = $this->client->api('user')->events($username);
150+
$event = array_pop($events);
151+
152+
$this->assertArrayHasKey('id', $event);
153+
$this->assertArrayHasKey('type', $event);
154+
$this->assertArrayHasKey('actor', $event);
155+
$this->assertArrayHasKey('login', $event['actor']);
156+
$this->assertArrayHasKey('repo', $event);
157+
$this->assertArrayHasKey('name', $event['repo']);
158+
$this->assertArrayHasKey('payload', $event);
159+
$this->assertArrayHasKey('public', $event);
160+
$this->assertArrayHasKey('created_at', $event);
161+
}
141162
}

0 commit comments

Comments
 (0)