Skip to content

Commit fada3f3

Browse files
committed
Fixed archive download by reference
According to the API docs, the reference should be passed directly as the last URL segment, not as a GET parameter. Check https://developer.github.com/v3/repos/contents/#get-archive-link Bug triaged by @garak. Closes KnpLabs#225
1 parent 08a176c commit fada3f3

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

lib/Github/Api/Repository/Contents.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ public function archive($username, $repository, $format, $reference = null)
225225
$format = 'tarball';
226226
}
227227

228-
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format), array(
229-
'ref' => $reference
230-
));
228+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($format).
229+
((null !== $reference) ? ('/'.rawurlencode($reference)) : ''));
231230
}
232231

233232
/**

test/Github/Tests/Api/Repository/ContentsTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function shouldFetchTarballArchiveWhenFormatNotRecognized()
233233
$api = $this->getApiMock();
234234
$api->expects($this->once())
235235
->method('get')
236-
->with('repos/KnpLabs/php-github-api/tarball', array('ref' => null))
236+
->with('repos/KnpLabs/php-github-api/tarball')
237237
->will($this->returnValue($expectedValue));
238238

239239
$this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'someFormat'));
@@ -249,7 +249,7 @@ public function shouldFetchTarballArchive()
249249
$api = $this->getApiMock();
250250
$api->expects($this->once())
251251
->method('get')
252-
->with('repos/KnpLabs/php-github-api/tarball', array('ref' => null))
252+
->with('repos/KnpLabs/php-github-api/tarball')
253253
->will($this->returnValue($expectedValue));
254254

255255
$this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'tarball'));
@@ -265,12 +265,28 @@ public function shouldFetchZipballArchive()
265265
$api = $this->getApiMock();
266266
$api->expects($this->once())
267267
->method('get')
268-
->with('repos/KnpLabs/php-github-api/zipball', array('ref' => null))
268+
->with('repos/KnpLabs/php-github-api/zipball')
269269
->will($this->returnValue($expectedValue));
270270

271271
$this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball'));
272272
}
273273

274+
/**
275+
* @test
276+
*/
277+
public function shouldFetchZipballArchiveByReference()
278+
{
279+
$expectedValue = 'zip';
280+
281+
$api = $this->getApiMock();
282+
$api->expects($this->once())
283+
->method('get')
284+
->with('repos/KnpLabs/php-github-api/zipball/master')
285+
->will($this->returnValue($expectedValue));
286+
287+
$this->assertEquals($expectedValue, $api->archive('KnpLabs', 'php-github-api', 'zipball', 'master'));
288+
}
289+
274290
/**
275291
* @test
276292
*/

0 commit comments

Comments
 (0)