Skip to content

Commit fe810b1

Browse files
committed
Merge branch 'pull_requests' of https://github.com/ChristopherMacGown/python-github2 into ChristopherMacGown-pull_requests
* 'pull_requests' of https://github.com/ChristopherMacGown/python-github2: Fixed the datetime format for the DateAttributes Adds support for Github API pull requests
2 parents 7a33a64 + d00d079 commit fe810b1

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

github2/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from github2.repositories import Repositories
44
from github2.users import Users
55
from github2.commits import Commits
6+
from github2.pull_requests import PullRequests
67

78

89
class Github(object):
@@ -40,6 +41,7 @@ def __init__(self, username=None, api_token=None, debug=False,
4041
self.users = Users(self.request)
4142
self.repos = Repositories(self.request)
4243
self.commits = Commits(self.request)
44+
self.pull_requests = PullRequests(self.request)
4345

4446
def project_for_user_repo(self, user, repo):
4547
"""Return Github identifier for a user's repository

github2/pull_requests.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
2+
3+
class PullRequest(BaseData):
4+
state = Attribute("The pull request state")
5+
base = Attribute("The base repo")
6+
head = Attribute("The head of the pull request")
7+
issue_user = Attribute("The user who created the pull request.")
8+
user = Attribute("The owner of the repo.")
9+
title = Attribute("The text of the pull request title.")
10+
body = Attribute("The text of the body.")
11+
position = Attribute("Floating point position of the pull request.")
12+
number = Attribute("Number of this request.")
13+
votes = Attribute("Number of votes for this request.")
14+
comments = Attribute("Any comments made on this request.")
15+
diff_url = Attribute("The URL to the unified diff.")
16+
patch_url = Attribute("The URL to the downloadable patch.")
17+
labels = Attribute("A list of labels attached to the pull request.")
18+
html_url = Attribute("The URL to the pull request.")
19+
issue_created_at = DateAttribute("The date the issue for this pull request was opened.", format='commit')
20+
issue_updated_at = DateAttribute("The date the issue for this pull request was last updated.", format='commit')
21+
created_at = DateAttribute("The date when this pull request was created.", format='commit')
22+
updated_at = DateAttribute("The date when this pull request was last updated.", format='commit')
23+
24+
def __repr__(self):
25+
return "<PullRequest: %s>" % self.html_url
26+
27+
28+
class PullRequests(GithubCommand):
29+
domain = "pulls"
30+
31+
def new(self, repo, base, head, title=None, body=None, issue=None):
32+
""" Create a new pull request """
33+
post_data = {"base": base, "head": head}
34+
if issue:
35+
post_data["issue"] = issue
36+
elif title and body:
37+
post_data["title"] = title
38+
post_data["body"] = body
39+
pull_request_data = [("pull[%s]" % k, v) for k, v in post_data.items()]
40+
return self.get_value(repo, post_data=dict(pull_request_data),
41+
filter="pull", datatype=PullRequest)
42+
43+
def show(self, repo, number):
44+
""" Show a single pull request """
45+
return self.get_value(repo, str(number), filter="pull", datatype=PullRequest)
46+
47+
def list(self, repo, state=None):
48+
""" List all pull requests for a repo """
49+
return self.get_values(repo, state, filter="pulls", datatype=PullRequest)

0 commit comments

Comments
 (0)