Skip to content
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
9 changes: 8 additions & 1 deletion doc/activity.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ $activity = $client->api('current_user')->starring()->all();
```
Returns an array of starred repos.

### Get list of private and public events for an authenticated user for all repos

```php
$activity = $client->api('user')->events('ornicar');
```
Returns an array of private and public events created for all repos related to the user.

### Get repos that a authenticated user has starred with creation date

Support for getting the star creation timestamp in the response, using the custom `Accept: application/vnd.github.v3.star+json` header.
Expand Down Expand Up @@ -100,4 +107,4 @@ $owner = "KnpLabs";
$repo = "php-github-api";
$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo);
```
Throws an Exception in case of failure or NULL in case of success.
Throws an Exception in case of failure or NULL in case of success.
11 changes: 11 additions & 0 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ $users = $client->api('current_user')->starring()->all();

Returns an array of starred repos.

### Get the authenticated user activity

> Requires [authentication](security.md).

```php
$activity = $client->api('user')->events('ornicar');
```

Returns an array of private and public events created for all repos related to the user.
> See [more](activity.md).

### Get the authenticated user emails

> Requires [authentication](security.md).
Expand Down
12 changes: 12 additions & 0 deletions lib/Github/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,16 @@ public function publicEvents($username)
{
return $this->get('/users/'.rawurlencode($username).'/events/public');
}

/**
* List events performed by an authenticated user.
*
* @link https://docs.github.com/en/rest/reference/activity#list-events-for-the-authenticated-user
*
* @return array
*/
public function events(string $username)
{
return $this->get('/users/'.rawurlencode($username).'/events');
}
}
23 changes: 23 additions & 0 deletions test/Github/Tests/Api/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,29 @@ public function shouldGetUserGists()
$this->assertEquals($expectedArray, $api->gists('l3l0'));
}

/**
* @test
*/
public function shouldGetAuthorizedUserEvents()
{
$expectedArray = [
[
'id' => 1,
'actor' => [
'id' => 1,
'login' => 'l3l0',
],
],
];
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/users/l3l0/events')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->events('l3l0'));
}

/**
* @return string
*/
Expand Down
21 changes: 21 additions & 0 deletions test/Github/Tests/Integration/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,25 @@ public function shouldGetReposBeingStarred()
$this->assertArrayHasKey('git_url', $repo);
$this->assertArrayHasKey('svn_url', $repo);
}

/**
* @test
*/
public function shouldGetEventsForAuthenticatedUserBeignWatched()
{
$username = 'l3l0';

$events = $this->client->api('user')->events($username);
$event = array_pop($events);

$this->assertArrayHasKey('id', $event);
$this->assertArrayHasKey('type', $event);
$this->assertArrayHasKey('actor', $event);
$this->assertArrayHasKey('login', $event['actor']);
$this->assertArrayHasKey('repo', $event);
$this->assertArrayHasKey('name', $event['repo']);
$this->assertArrayHasKey('payload', $event);
$this->assertArrayHasKey('public', $event);
$this->assertArrayHasKey('created_at', $event);
}
}