From 1713d3fb0b4e6037a6a90d9bb703d2340bbe2dfe Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Sat, 8 Sep 2012 14:08:20 +0200 Subject: [PATCH] Repository.get_branch --- .../description.human_readable.json | 5 +- .../description.normalized.json | 46 +++++++++++++++++++ doc/ReferenceOfApis.md | 2 +- doc/ReferenceOfClasses.md | 15 +++--- github/Repository.py | 10 ++++ test/ReplayData/Repository.testGetBranch.txt | 5 ++ test/Repository.py | 4 ++ 7 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 test/ReplayData/Repository.testGetBranch.txt diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json b/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json index bf382071..e79a54f9 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.human_readable.json @@ -1466,7 +1466,10 @@ "name": "branches", "singularName": "branch", "type": "Branch", - "getList": true + "getList": true, + "getElement": { + "parameter": { "name": "branch", "type": "string" } + } }, { "name": "collaborators", diff --git a/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json b/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json index 08d947af..4a6151ac 100644 --- a/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json +++ b/codegen/JsonDescriptionOfGithubApiV3/description.normalized.json @@ -8397,6 +8397,52 @@ "name": "void" } }, + { + "group": "branches", + "name": [ + "get", + "branch" + ], + "mandatoryParameters": [ + { + "type": { + "simple": true, + "cardinality": "scalar", + "name": "string" + }, + "name": "branch" + } + ], + "request": { + "url": [ + { + "type": "attribute", + "value": [ + "url" + ] + }, + { + "type": "constant", + "value": "/branches/" + }, + { + "type": "argument", + "value": [ + "branch" + ] + } + ], + "information": "data", + "verb": "GET" + }, + "isMutation": false, + "optionalParameters": [], + "type": { + "simple": false, + "cardinality": "scalar", + "name": "Branch" + } + }, { "group": "branches", "name": [ diff --git a/doc/ReferenceOfApis.md b/doc/ReferenceOfApis.md index bb577ec2..5a3fe1c5 100644 --- a/doc/ReferenceOfApis.md +++ b/doc/ReferenceOfApis.md @@ -151,7 +151,7 @@ API `/repos/:user/:repo/branches` API `/repos/:user/:repo/branches/:branch` ========================================= -* GET: (TODO) +* GET: `Repository.get_branch` API `/repos/:user/:repo/collaborators` ====================================== diff --git a/doc/ReferenceOfClasses.md b/doc/ReferenceOfClasses.md index fb2748c7..b13336ff 100644 --- a/doc/ReferenceOfClasses.md +++ b/doc/ReferenceOfClasses.md @@ -1,25 +1,20 @@ You don't normaly create instances of any class but `Github`. You obtain instances through calls to `search_`, `get_` and `create_` methods. - Methods returning an "iterator of `SomeType`" return an iterator which yields instances of `SomeType`. This implements lazy [pagination requests](http://developer.github.com/v3/#pagination). You can use this iterator in a `for f in user.get_followers():` loop or with any [itertools](http://docs.python.org/library/itertools.html) functions, but you cannot know the number of objects returned before the end of the iteration. If that's really what you need, you cant use `len( list( user.get_followers() ) )`, which does all the requests needed to enumerate the user's followers. Note that there is often an attribute giving this value (in that case `user.followers`). - Class `Github` ============== Constructed from user's login and password or OAuth token or nothing: - g = Github( login, password ) g = Github( token ) g = Github() - You can add an argument `base_url = "http://my.enterprise.com:8080/path/to/github"` to connect to a local install of Github (ie. Github Enterprise). Another argument, that can be passed is `timeout` which has default value `10`. - Attributes ---------- * `rate_limiting`: tuple of two integers: remaining and limit, as explained in [Rate Limiting](http://developer.github.com/v3/#rate-limiting) @@ -1153,6 +1148,8 @@ Assignees Branches -------- +* `get_branch( branch )`: `Branch` + * `branch`: string * `get_branches()`: iterator of `Branch` Collaborators @@ -1286,16 +1283,16 @@ Issues * `get_issue( number )`: `Issue` * `number`: integer * `get_issues( [milestone, state, assignee, mentioned, labels, sort, direction, since] )`: iterator of `Issue` - * `milestone`: `Milestone` or "none" or "*" + * `milestone`: `Milestone` * `state`: string - * `assignee`: `NamedUser` or "none" or "*" + * `assignee`: `NamedUser` * `mentioned`: `NamedUser` * `labels`: list of `Label` * `sort`: string * `direction`: string * `since`: datetime.datetime * `legacy_search_issues( state, keyword )`: iterator of `Issue` - * `state`: "open" or "closed" + * `state`: string * `keyword`: string Issues_events @@ -1353,7 +1350,7 @@ Modification Pulls ----- -* `create_pull( < title, body, base, head > or < issue, base, head > )`: `PullRequest` +* `create_pull( [title, body, issue, base, head] )`: `PullRequest` * `title`: string * `body`: string * `issue`: `Issue` diff --git a/github/Repository.py b/github/Repository.py index e583fd18..bbae4e1f 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -526,6 +526,16 @@ class Repository( GithubObject.GithubObject ): data ) + def get_branch( self, branch ): + assert isinstance( branch, ( str, unicode ) ), branch + headers, data = self._requester.requestAndCheck( + "GET", + self.url + "/branches/" + branch, + None, + None + ) + return Branch.Branch( self._requester, data, completed = True ) + def get_branches( self ): headers, data = self._requester.requestAndCheck( "GET", diff --git a/test/ReplayData/Repository.testGetBranch.txt b/test/ReplayData/Repository.testGetBranch.txt new file mode 100644 index 00000000..d5db2d61 --- /dev/null +++ b/test/ReplayData/Repository.testGetBranch.txt @@ -0,0 +1,5 @@ +https GET api.github.com None /repos/jacquev6/PyGithub/branches/develop {'Authorization': 'Basic login_and_password_removed'} null +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4997'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('content-length', '1679'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"b604c4203d816dfb31c48acf4171ed76"'), ('cache-control', 'max-age=0, private, must-revalidate'), ('date', 'Sat, 08 Sep 2012 12:06:47 GMT'), ('content-type', 'application/json; charset=utf-8')] +{"_links":{"self":"https://api.github.com/repos/jacquev6/PyGithub/branches/develop","html":"https://github.com/jacquev6/PyGithub/tree/develop"},"commit":{"sha":"03058a36164d2a7d946db205f25538434fa27d94","author":{"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","url":"https://api.github.com/users/jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"},"commit":{"message":"Commit statuses (issue #67)","author":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-09-08T04:41:15-07:00"},"comment_count":0,"url":"https://api.github.com/repos/jacquev6/PyGithub/git/commits/03058a36164d2a7d946db205f25538434fa27d94","tree":{"sha":"b1b660dc63a2de976b7c5aa1e303adce299bbeb8","url":"https://api.github.com/repos/jacquev6/PyGithub/git/trees/b1b660dc63a2de976b7c5aa1e303adce299bbeb8"},"committer":{"email":"vincent@vincent-jacques.net","name":"Vincent Jacques","date":"2012-09-08T04:41:15-07:00"}},"url":"https://api.github.com/repos/jacquev6/PyGithub/commits/03058a36164d2a7d946db205f25538434fa27d94","parents":[{"sha":"f109c644fddee5512f8e88a4a22d9c3aac68a306","url":"https://api.github.com/repos/jacquev6/PyGithub/commits/f109c644fddee5512f8e88a4a22d9c3aac68a306"}],"committer":{"gravatar_id":"b68de5ae38616c296fa345d2b9df2225","login":"jacquev6","url":"https://api.github.com/users/jacquev6","id":327146,"avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png"}},"name":"develop"} + diff --git a/test/Repository.py b/test/Repository.py index 67319d71..a0ffffca 100644 --- a/test/Repository.py +++ b/test/Repository.py @@ -366,3 +366,7 @@ class Repository( Framework.TestCase ): 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" ) + + def testGetBranch( self ): + branch = self.repo.get_branch( "develop" ) + self.assertEqual( branch.commit.sha, "03058a36164d2a7d946db205f25538434fa27d94" )