Skip to content

Commit b76299f

Browse files
Merge branch '9.19' into 10.0
2 parents ac74c8a + a65d1cc commit b76299f

File tree

3 files changed

+114
-1
lines changed

3 files changed

+114
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CHANGE LOG
22
==========
33

44

5-
## 10.0.0 (Upcoming)
5+
## 10.0.0 (UPCOMING)
66

77
* Removed all deprecated functionality
88
* Switched to PSR-17 and PSR-18
@@ -11,6 +11,11 @@ CHANGE LOG
1111
* Redesigned pagination
1212

1313

14+
## 9.19.0 (UPCOMING)
15+
16+
* Added user events API
17+
18+
1419
## 9.18.0 (11/07/2020)
1520

1621
* Deprecated all APIs that are deprecated or removed as of GitLab 13.1

src/Api/Users.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,44 @@ public function removeImpersonationToken($user_id, $impersonation_token_id)
416416
{
417417
return $this->delete('users/'.self::encodePath($user_id).'/impersonation_tokens/'.self::encodePath($impersonation_token_id));
418418
}
419+
420+
/**
421+
* @param int $user_id
422+
* @param array $parameters {
423+
*
424+
* @var string $action include only events of a particular action type
425+
* @var string $target_type include only events of a particular target type
426+
* @var \DateTimeInterface $before include only events created before a particular date
427+
* @var \DateTimeInterface $after include only events created after a particular date
428+
* @var string $sort Sort events in asc or desc order by created_at (default is desc)
429+
* }
430+
*
431+
* @return mixed
432+
*/
433+
public function events($user_id, array $parameters = [])
434+
{
435+
$resolver = $this->createOptionsResolver();
436+
$datetimeNormalizer = function (Options $resolver, \DateTimeInterface $value) {
437+
return $value->format('Y-m-d');
438+
};
439+
440+
$resolver->setDefined('action')
441+
->setAllowedValues('action', ['created', 'updated', 'closed', 'reopened', 'pushed', 'commented', 'merged', 'joined', 'left', 'destroyed', 'expired'])
442+
;
443+
$resolver->setDefined('target_type')
444+
->setAllowedValues('target_type', ['issue', 'milestone', 'merge_request', 'note', 'project', 'snippet', 'user'])
445+
;
446+
$resolver->setDefined('before')
447+
->setAllowedTypes('before', \DateTimeInterface::class)
448+
->setNormalizer('before', $datetimeNormalizer);
449+
$resolver->setDefined('after')
450+
->setAllowedTypes('after', \DateTimeInterface::class)
451+
->setNormalizer('after', $datetimeNormalizer)
452+
;
453+
$resolver->setDefined('sort')
454+
->setAllowedValues('sort', ['asc', 'desc'])
455+
;
456+
457+
return $this->get('users/'.$this->encodePath($user_id).'/events', $resolver->resolve($parameters));
458+
}
419459
}

tests/Api/UsersTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,72 @@ protected function getApiClass()
707707
{
708708
return 'Gitlab\Api\Users';
709709
}
710+
711+
/**
712+
* @test
713+
*/
714+
public function shouldGetEvents()
715+
{
716+
$expectedArray = [
717+
['id' => 1, 'title' => 'An event'],
718+
['id' => 2, 'title' => 'Another event'],
719+
];
720+
721+
$api = $this->getApiMock();
722+
$api->expects($this->once())
723+
->method('get')
724+
->with('users/1/events', [])
725+
->will($this->returnValue($expectedArray));
726+
727+
$this->assertEquals($expectedArray, $api->events(1));
728+
}
729+
730+
/**
731+
* @test
732+
*/
733+
public function shouldGetEventsWithDateTimeParams()
734+
{
735+
$expectedArray = [
736+
['id' => 1, 'title' => 'An event'],
737+
['id' => 2, 'title' => 'Another event'],
738+
];
739+
740+
$after = new \DateTime('2018-01-01 00:00:00');
741+
$before = new \DateTime('2018-01-31 00:00:00');
742+
743+
$expectedWithArray = [
744+
'after' => $after->format('Y-m-d'),
745+
'before' => $before->format('Y-m-d'),
746+
];
747+
748+
$api = $this->getApiMock();
749+
$api->expects($this->once())
750+
->method('get')
751+
->with('users/1/events', $expectedWithArray)
752+
->will($this->returnValue($expectedArray));
753+
754+
$this->assertEquals($expectedArray, $api->events(1, ['after' => $after, 'before' => $before]));
755+
}
756+
757+
/**
758+
* @test
759+
*/
760+
public function shouldGetEventsWithPagination()
761+
{
762+
$expectedArray = [
763+
['id' => 1, 'title' => 'An event'],
764+
['id' => 2, 'title' => 'Another event'],
765+
];
766+
767+
$api = $this->getApiMock();
768+
$api->expects($this->once())
769+
->method('get')
770+
->with('users/1/events', [
771+
'page' => 2,
772+
'per_page' => 15,
773+
])
774+
->will($this->returnValue($expectedArray));
775+
776+
$this->assertEquals($expectedArray, $api->events(1, ['page' => 2, 'per_page' => 15]));
777+
}
710778
}

0 commit comments

Comments
 (0)