from github2.core import BaseData, GithubCommand, Attribute, DateAttribute

class PullRequest(BaseData):
    state = Attribute("The pull request state")
    base = Attribute("The base repo")
    head = Attribute("The head of the pull request")
    issue_user = Attribute("The user who created the pull request.")
    user = Attribute("The owner of the repo.")
    title = Attribute("The text of the pull request title.")
    body = Attribute("The text of the body.")
    position = Attribute("Floating point position of the pull request.")
    number = Attribute("Number of this request.")
    votes = Attribute("Number of votes for this request.")
    comments = Attribute("Number of comments made on this request.")
    diff_url = Attribute("The URL to the unified diff.")
    patch_url = Attribute("The URL to the downloadable patch.")
    labels = Attribute("A list of labels attached to the pull request.")
    html_url = Attribute("The URL to the pull request.")
    issue_created_at = DateAttribute("The date the issue for this pull request was opened.",
                                     format='iso')
    issue_updated_at = DateAttribute("The date the issue for this pull request was last updated.",
                                     format='iso')
    created_at = DateAttribute("The date when this pull request was created.",
                               format='iso')
    updated_at = DateAttribute("The date when this pull request was last updated.",
                               format='iso')
    closed_at = DateAttribute("The date when this pull request was closed",
                              format='iso')
    discussion = Attribute("Discussion thread for the pull request.")
    mergeable = Attribute("Whether the pull request can be merge cleanly")

    def __repr__(self):
        return "<PullRequest: %s>" % self.html_url


class PullRequests(GithubCommand):
    domain = "pulls"

    def new(self, project, base, head, title=None, body=None, issue=None):
        """ Create a new pull request """
        post_data = {"base": base, "head": head}
        if issue:
            post_data["issue"] = issue
        elif title:
            post_data["title"] = title
            if body:
                post_data["body"] = body
        pull_request_data = [("pull[%s]" % k, v) for k, v in post_data.items()]
        return self.get_value(project, post_data=dict(pull_request_data),
            filter="pull", datatype=PullRequest)

    def show(self, project, number):
        """ Show a single pull request """
        return self.get_value(project, str(number), filter="pull",
                              datatype=PullRequest)

    def list(self, project, state="open"):
        """ List all pull requests for a project """

        return self.get_values(project, state, filter="pulls",
                               datatype=PullRequest)

@@ -1917,19 +1917,22 @@
     def 
-new
+create
 (self, p
@@ -1998,17 +1998,16 @@
      %22%22%22
- 
 Create a
@@ -2015,32 +2015,632 @@
 new pull request
+%0A%0A        Pull requests can be created from scratch, or attached to an existing%0A        issue.  If an %60%60issue%60%60 parameter is supplied the pull request is%0A        attached to that issue, else a new pull request is created.%0A%0A        .. versionadded:: 0.4.0%0A%0A        :param str project: Github project%0A        :param str base: branch changes should be pulled into%0A        :param str head: branch of the changes to be pulled%0A        :param str title: title for pull request%0A        :param str body: optional body for pull request%0A        :param str issue: existing issue to attach pull request to%0A       
  %22%22%22%0A        pos
@@ -3107,17 +3107,16 @@
      %22%22%22
- 
 Show a s
@@ -3133,16 +3133,138 @@
  request
+%0A%0A        :param str project: Github project%0A        :param int number: pull request number in the Github database%0A       
  %22%22%22%0A   
@@ -3434,17 +3434,16 @@
      %22%22%22
- 
 List all
@@ -3474,14 +3474,128 @@
 ject
+%0A%0A        :param str project: Github project%0A        :param str state: can be either %60%60open%60%60 or %60%60closed%60%60%0A       
  %22%22%22%0A
-%0A
     

Document PullRequests methods.