Skip to content

Commit ba01b38

Browse files
authored
Merge pull request #653 from acrobat/issue-timeline-api
Missing issue timeline api
2 parents ac377f8 + 6af822c commit ba01b38

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ v3 APIs:
2727
* [Comments](issue/comments.md)
2828
* [Labels](issue/labels.md)
2929
* [Milestones](issue/milestones.md)
30+
* [Timeline](issue/timeline.md)
3031
* [Meta](meta.md)
3132
* Miscellaneous
3233
* [Emojis](miscellaneous/emojis.md)

doc/issue/timeline.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Issues / Timeline API
2+
[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md)
3+
4+
Wraps [GitHub Issue Timeline API](http://developer.github.com/v3/issues/timeline/).
5+
6+
This api is currently only available to developers in Early Access. To access the API during the Early Access period,
7+
you must provide a custom media type in the Accept header.
8+
9+
```php
10+
$client->api('ìssue')->timeline()->configure();
11+
```
12+
13+
### List events for an issue
14+
15+
```php
16+
$events = $client->api('issue')->timeline()->all('KnpLabs', 'php-github-api', 123);
17+
```

lib/Github/Api/Issue.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Github\Api\Issue\Events;
88
use Github\Api\Issue\Labels;
99
use Github\Api\Issue\Milestones;
10+
use Github\Api\Issue\Timeline;
1011
use Github\Exception\MissingArgumentException;
1112

1213
/**
@@ -245,4 +246,16 @@ public function assignees()
245246
{
246247
return new Assignees($this->client);
247248
}
249+
250+
/**
251+
* List all events.
252+
*
253+
* @link https://developer.github.com/v3/issues/timeline/
254+
*
255+
* @return Timeline
256+
*/
257+
public function timeline()
258+
{
259+
return new Timeline($this->client);
260+
}
248261
}

lib/Github/Api/Issue/Timeline.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Github\Api\Issue;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
7+
8+
class Timeline extends AbstractApi
9+
{
10+
use AcceptHeaderTrait;
11+
12+
public function configure()
13+
{
14+
$this->acceptHeaderValue = 'application/vnd.github.mockingbird-preview';
15+
16+
return $this;
17+
}
18+
19+
/**
20+
* Get all events for a specific issue.
21+
*
22+
* @link https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue
23+
* @param string $username
24+
* @param string $repository
25+
* @param int $issue
26+
*
27+
* @return array
28+
*/
29+
public function all($username, $repository, $issue)
30+
{
31+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/timeline');
32+
}
33+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Issue;
4+
5+
use Github\Tests\Api\TestCase;
6+
7+
class TimelineTest extends TestCase
8+
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldGetIssueEvents()
13+
{
14+
$expectedValue = array(
15+
'event1',
16+
'event2',
17+
);
18+
19+
$api = $this->getApiMock();
20+
$api->expects($this->once())
21+
->method('get')
22+
->with('/repos/KnpLabs/php-github-api/issues/123/timeline', array())
23+
->will($this->returnValue($expectedValue));
24+
25+
$this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123));
26+
}
27+
28+
29+
/**
30+
* @return string
31+
*/
32+
protected function getApiClass()
33+
{
34+
return \Github\Api\Issue\Timeline::class;
35+
}
36+
}

test/Github/Tests/Api/IssueTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ public function shouldGetMilestonesApiObject()
242242
$this->assertInstanceOf(\Github\Api\Issue\Milestones::class, $api->milestones());
243243
}
244244

245+
/**
246+
* @test
247+
*/
248+
public function shouldGetTimelineApiObject()
249+
{
250+
$api = $this->getApiMock();
251+
252+
$this->assertInstanceOf(\Github\Api\Issue\Timeline::class, $api->timeline());
253+
}
254+
245255
/**
246256
* @test
247257
*/

0 commit comments

Comments
 (0)