|
| 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