Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions lib/Github/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,23 @@ 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
*
* @param string $username
* @param int $page the page number of the paginated result set
* @param int $perPage the number of results per page
*
* @return array
*/
public function events($username, $page = 1, $perPage = 30)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the $page and $perPage parameters, the ResultPager should be used to loop over all the results

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed both parameters, thank you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add the string typehint to the $username parameter and remove the superfluous @param docs

Copy link
Contributor Author

@richard015ar richard015ar Apr 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the typehint and I removed completely the @param docs. I also would remove the complete block of comments, since the function looks pretty readable. But I left it to keep consistency with previous methods.

{
return $this->get('/users/'.rawurlencode($username).'/events', [
'page' => $page,
'per_page' => $perPage,
]);
}
}
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);
}
}