Skip to content

Commit b5b482f

Browse files
committed
Fixed duplicated content of API calls to repository contents
1 parent bc50424 commit b5b482f

File tree

3 files changed

+53
-31
lines changed

3 files changed

+53
-31
lines changed

lib/Github/Api/Repo.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ public function commits()
133133
return new Commits($this->client);
134134
}
135135

136+
/**
137+
* Manage the content of a repository
138+
* @link http://developer.github.com/v3/repos/contents/
139+
*
140+
* @return Contents
141+
*/
142+
public function contents()
143+
{
144+
return new Contents($this->client);
145+
}
146+
136147
/**
137148
* Manage the deploy keys of a repository
138149
* @link http://developer.github.com/v3/repos/keys/
@@ -270,21 +281,6 @@ public function teams($username, $repository)
270281
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/teams');
271282
}
272283

273-
/**
274-
* Get contents of any file or directory in a repository
275-
* @link http://developer.github.com/v3/repos/contents/
276-
*
277-
* @param string $username the user who owns the repository
278-
* @param string $repository the name of the repository
279-
* @param string $path path to file or directory
280-
*
281-
* @return array information for file | information for each item in directory
282-
*/
283-
public function contents($username, $repository, $path)
284-
{
285-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/contents/'.$path);
286-
}
287-
288284
/**
289285
* Get the downloads for selected repository
290286
* @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository

lib/Github/Api/Repository/Contents.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,32 @@
1111
*/
1212
class Contents extends AbstractApi
1313
{
14+
/**
15+
* Get content of README file in a repository
16+
* @link http://developer.github.com/v3/repos/contents/
17+
*
18+
* @param string $username the user who owns the repository
19+
* @param string $repository the name of the repository
20+
* @param string $reference reference to a branch or commit
21+
*
22+
* @return array information for README file
23+
*/
1424
public function readme($username, $repository, $reference = null)
1525
{
1626
return $this->show($username, $repository, 'readme', $reference);
1727
}
1828

29+
/**
30+
* Get contents of any file or directory in a repository
31+
* @link http://developer.github.com/v3/repos/contents/
32+
*
33+
* @param string $username the user who owns the repository
34+
* @param string $repository the name of the repository
35+
* @param string $path path to file or directory
36+
* @param string $reference reference to a branch or commit
37+
*
38+
* @return array information for file | information for each item in directory
39+
*/
1940
public function show($username, $repository, $path = null, $reference = null)
2041
{
2142
$url = 'repos/'.urlencode($username).'/'.urlencode($repository).'/contents';
@@ -28,6 +49,17 @@ public function show($username, $repository, $path = null, $reference = null)
2849
));
2950
}
3051

52+
/**
53+
* Get content of archives in a repository
54+
* @link http://developer.github.com/v3/repos/contents/
55+
*
56+
* @param string $username the user who owns the repository
57+
* @param string $repository the name of the repository
58+
* @param string $format format of archive: tarball or zipball
59+
* @param string $reference reference to a branch or commit
60+
*
61+
* @return array information for archives
62+
*/
3163
public function archive($username, $repository, $format, $reference = null)
3264
{
3365
if (!in_array($format, array('tarball', 'zipball'))) {

test/Github/Tests/Api/RepoTest.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,6 @@ public function shouldGetRepositoryTeams()
207207
$this->assertEquals($expectedArray, $api->teams('KnpLabs', 'php-github-api'));
208208
}
209209

210-
/**
211-
* @test
212-
*/
213-
public function shouldGetContentsForPathFromRepository()
214-
{
215-
$expectedArray = 'some content';
216-
217-
$api = $this->getApiMock();
218-
$api->expects($this->once())
219-
->method('get')
220-
->with('repos/KnpLabs/php-github-api/contents/path/in/repo')
221-
->will($this->returnValue($expectedArray));
222-
223-
$this->assertEquals($expectedArray, $api->contents('KnpLabs', 'php-github-api', 'path/in/repo'));
224-
}
225-
226210
/**
227211
* @test
228212
*/
@@ -331,6 +315,16 @@ public function shouldGetCommitsApiObject()
331315
$this->assertInstanceOf('Github\Api\Repository\Commits', $api->commits());
332316
}
333317

318+
/**
319+
* @test
320+
*/
321+
public function shouldGetContentsApiObject()
322+
{
323+
$api = $this->getApiMock();
324+
325+
$this->assertInstanceOf('Github\Api\Repository\Contents', $api->contents());
326+
}
327+
334328
/**
335329
* @test
336330
*/

0 commit comments

Comments
 (0)