From f109c644fddee5512f8e88a4a22d9c3aac68a306 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 8 Sep 2012 13:04:43 +0200 Subject: [PATCH] Repository.get_archive_link (issue #65) --- .../description.human_readable.json | 21 ++++++ .../description.normalized.json | 65 +++++++++++++++++++ doc/ReferenceOfApis.md | 2 +- doc/ReferenceOfClasses.md | 3 + github/Repository.py | 14 ++++ .../Repository.testGetArchiveLink.txt | 20 ++++++ test/Repository.py | 6 ++ 7 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 test/ReplayData/Repository.testGetArchiveLink.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json index 5d6787f7..6071d6ef 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json @@ -1864,6 +1864,27 @@ ] } }, + { + "name": [ "get", "archive", "link" ], + "type": "string", + "group": "contents", + "mandatoryParameters": [ + { "name": "archive_format", "type": "string" } + ], + "optionalParameters": [ + { "name": "ref", "type": "string" } + ], + "request": { + "verb": "GET", + "url": [ + { "type": "attribute", "value": [ "url" ] }, + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ "archive_format" ] }, + { "type": "constant", "value": "/" }, + { "type": "argument", "value": [ "ref" ] } + ] + } + }, { "name": [ "compare" ], "type": "Comparison", diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json index 0ed72e18..00e8e2e4 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json @@ -10834,6 +10834,71 @@ "name": "ContentFile" } }, + { + "group": "contents", + "name": [ + "get", + "archive", + "link" + ], + "mandatoryParameters": [ + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "archive_format" + } + ], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/" + }, + { + "type": "argument", + "value": [ + "archive_format" + ] + }, + { + "type": "constant", + "value": "/" + }, + { + "type": "argument", + "value": [ + "ref" + ] + } + ], + "verb": "GET" + }, + "isMutation": false, + "optionalParameters": [ + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "ref" + } + ], + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + } + }, { "group": "Comparison", "name": [ diff --git a/doc/ReferenceOfApis.md b/doc/ReferenceOfApis.md index e7a2a4cb..4a6eabcb 100644 --- a/doc/ReferenceOfApis.md +++ b/doc/ReferenceOfApis.md @@ -135,7 +135,7 @@ API `/repos/:user/:repo` API `/repos/:user/:repo/:archive_format/:ref` ============================================= -* GET: (TODO) +* GET: `Repository.get_archive_link` API `/repos/:user/:repo/assignees` ================================== diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index 32fc62ff..970bb796 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -1163,6 +1163,9 @@ Contents * `get_readme()`: `ContentFile` * `get_contents( path )`: `ContentFile` * `path`: string +* `get_archive_link( archive_format, [ref] )`: string + * `archive_format`: string + * `ref`: string Contributors ------------ diff --git a/github/Repository.py b/github/Repository.py index a36d9366..e583fd18 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -498,6 +498,20 @@ class Repository( GithubObject.GithubObject ): ) self._useAttributes( data ) + def get_archive_link( self, archive_format, ref = GithubObject.NotSet ): + assert isinstance( archive_format, ( str, unicode ) ), archive_format + assert ref is GithubObject.NotSet or isinstance( ref, ( str, unicode ) ), ref + url = self.url + "/" + archive_format + if ref is not GithubObject.NotSet: + url += "/" + ref + headers, data = self._requester.requestAndCheck( + "GET", + url, + None, + None + ) + return headers[ "location" ] + def get_assignees( self ): headers, data = self._requester.requestAndCheck( "GET", diff --git a/test/ReplayData/Repository.testGetArchiveLink.txt b/test/ReplayData/Repository.testGetArchiveLink.txt new file mode 100644 index 00000000..14f843ab --- /dev/null +++ b/test/ReplayData/Repository.testGetArchiveLink.txt @@ -0,0 +1,20 @@ +https GET api.github.com None /repos/jacquev6/PyGithub/tarball {'Authorization': 'Basic login_and_password_removed'} null +302 +[('status', '302 Found'), ('content-length', '0'), ('x-content-type-options', 'nosniff'), ('expires', 'Sat, 08 Sep 2012 11:03:00 GMT'), ('x-ratelimit-remaining', '4990'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('location', 'https://nodeload.github.com/jacquev6/PyGithub/tarball/master'), ('cache-control', 'public, must-revalidate, max-age=0'), ('date', 'Sat, 08 Sep 2012 11:03:00 GMT'), ('content-type', 'text/html;charset=utf-8')] + + +https GET api.github.com None /repos/jacquev6/PyGithub/zipball {'Authorization': 'Basic login_and_password_removed'} null +302 +[('status', '302 Found'), ('x-ratelimit-remaining', '4989'), ('x-content-type-options', 'nosniff'), ('expires', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('content-length', '0'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('location', 'https://nodeload.github.com/jacquev6/PyGithub/zipball/master'), ('cache-control', 'public, must-revalidate, max-age=0'), ('date', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('content-type', 'text/html;charset=utf-8')] + + +https GET api.github.com None /repos/jacquev6/PyGithub/zipball/master {'Authorization': 'Basic login_and_password_removed'} null +302 +[('status', '302 Found'), ('content-length', '0'), ('x-content-type-options', 'nosniff'), ('expires', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('x-ratelimit-remaining', '4988'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('location', 'https://nodeload.github.com/jacquev6/PyGithub/zipball/master'), ('cache-control', 'public, must-revalidate, max-age=0'), ('date', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('content-type', 'text/html;charset=utf-8')] + + +https GET api.github.com None /repos/jacquev6/PyGithub/tarball/develop {'Authorization': 'Basic login_and_password_removed'} null +302 +[('status', '302 Found'), ('x-ratelimit-remaining', '4987'), ('x-content-type-options', 'nosniff'), ('expires', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('content-length', '0'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('location', 'https://nodeload.github.com/jacquev6/PyGithub/tarball/develop'), ('cache-control', 'public, must-revalidate, max-age=0'), ('date', 'Sat, 08 Sep 2012 11:03:01 GMT'), ('content-type', 'text/html;charset=utf-8')] + + diff --git a/test/Repository.py b/test/Repository.py index cff70c86..67319d71 100644 --- a/test/Repository.py +++ b/test/Repository.py @@ -360,3 +360,9 @@ class Repository( Framework.TestCase ): def testGetContents( self ): self.assertEqual( len( self.repo.get_readme().content ), 10212 ) self.assertEqual( len( self.repo.get_contents( "doc/ReferenceOfClasses.md" ).content ), 38121 ) + + def testGetArchiveLink( self ): + self.assertEqual( self.repo.get_archive_link( "tarball" ), "https://nodeload.github.com/jacquev6/PyGithub/tarball/master" ) + self.assertEqual( self.repo.get_archive_link( "zipball" ), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master" ) + self.assertEqual( self.repo.get_archive_link( "zipball", "master" ), "https://nodeload.github.com/jacquev6/PyGithub/zipball/master" ) + self.assertEqual( self.repo.get_archive_link( "tarball", "develop" ), "https://nodeload.github.com/jacquev6/PyGithub/tarball/develop" )