Repository.get_branch

This commit is contained in:
Vincent Jacques
2012-09-08 14:08:20 +02:00
parent 03058a3616
commit 1713d3fb0b
7 changed files with 76 additions and 11 deletions
@@ -1466,7 +1466,10 @@
"name": "branches",
"singularName": "branch",
"type": "Branch",
"getList": true
"getList": true,
"getElement": {
"parameter": { "name": "branch", "type": "string" }
}
},
{
"name": "collaborators",
@@ -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": [
+1 -1
View File
@@ -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`
======================================
+6 -9
View File
@@ -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`
+10
View File
@@ -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",
@@ -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"}
+4
View File
@@ -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" )