#41 Add the repo_from in create_pull_request
Merged 4 years ago by cverna. Opened 4 years ago by lenkaseg.
lenkaseg/libpagure repo_from  into  master

file modified
+63 -18
@@ -11,6 +11,7 @@ 

      # Python 2

      import httplib as http_client

  

+ 

  class NullHandler(logging.Handler):

      # Null logger to avoid spurious messages

      def emit(self, record):
@@ -80,7 +81,11 @@ 

          """

  

          req = self.session.request(

-             method=method, url=url, params=params, data=data, verify=not self.insecure

+             method=method,

+             url=url,

+             params=params,

+             data=data,

+             verify=not self.insecure,

          )

  

          output = None
@@ -95,7 +100,9 @@ 

              LOG.error(output)

              if "error_code" in output:

                  if "errors" in output:

-                     raise APIError("%s, details: \"%s\"" % (output["error"], output["errors"]))

+                     raise APIError(

+                         '%s, details: "%s"' % (output["error"], output["errors"])

+                     )

                  else:

                      raise APIError(output["error"])

          return output
@@ -112,10 +119,14 @@ 

              if self.namespace is None:

                  request_url = "{}/api/0/{}/".format(self.instance, self.repo)

              else:

-                 request_url = "{}/api/0/{}/{}/".format(self.instance, self.namespace, self.repo)

+                 request_url = "{}/api/0/{}/{}/".format(

+                     self.instance, self.namespace, self.repo_to

+                 )

          else:

              if self.namespace is None:

-                 request_url = "{}/api/0/fork/{}/{}/".format(self.instance, self.username, self.repo)

+                 request_url = "{}/api/0/fork/{}/{}/".format(

+                     self.instance, self.username, self.repo_to

+                 )

              else:

                  request_url = "{}/api/0/fork/{}/{}/{}/".format(

                      self.instance, self.username, self.namespace, self.repo
@@ -142,7 +153,6 @@ 

              requests_log.setLevel(logging.DEBUG)

              requests_log.propagate = True

  

- 

      def list_users(self, pattern=None):

          """

          List all users registered on this Pagure instance.
@@ -232,7 +242,9 @@ 

          :param request_id: the id of the request

          :return:

          """

-         request_url = "{}pull-request/{}/merge".format(self.create_basic_url(), request_id)

+         request_url = "{}pull-request/{}/merge".format(

+             self.create_basic_url(), request_id

+         )

  

          return_value = self._call_api(request_url, method="POST")

  
@@ -244,7 +256,9 @@ 

          :param request_id: the id of the request

          :return:

          """

-         request_url = "{}pull-request/{}/close".format(self.create_basic_url(), request_id)

+         request_url = "{}pull-request/{}/close".format(

+             self.create_basic_url(), request_id

+         )

  

          return_value = self._call_api(request_url, method="POST")

  
@@ -260,7 +274,9 @@ 

          :param row: which line of code to comment on

          :return:

          """

-         request_url = "{}pull-request/{}/comment".format(self.create_basic_url(), request_id)

+         request_url = "{}pull-request/{}/comment".format(

+             self.create_basic_url(), request_id

+         )

  

          payload = {"comment": body}

          if commit is not None:
@@ -274,7 +290,9 @@ 

  

          LOG.debug(return_value)

  

-     def flag_request(self, request_id, username, percent, comment, url, uid=None, commit=None):

+     def flag_request(

+         self, request_id, username, percent, comment, url, uid=None, commit=None

+     ):

          """

          Add or edit a flag of the request.

          :param request_id: the id of the request
@@ -287,9 +305,16 @@ 

          :param commit: which commit to flag on

          :return:

          """

-         request_url = "{}pull-request/{}/flag".format(self.create_basic_url(), request_id)

+         request_url = "{}pull-request/{}/flag".format(

+             self.create_basic_url(), request_id

+         )

  

-         payload = {"username": username, "percent": percent, "comment": comment, "url": url}

+         payload = {

+             "username": username,

+             "percent": percent,

+             "comment": comment,

+             "url": url,

+         }

          if commit is not None:

              payload["commit"] = commit

          if uid is not None:
@@ -300,7 +325,14 @@ 

          LOG.debug(return_value)

  

      def create_issue(

-         self, title, content, priority=None, milestone=None, tags=None, assignee=None, private=None

+         self,

+         title,

+         content,

+         priority=None,

+         milestone=None,

+         tags=None,

+         assignee=None,

+         private=None,

      ):

          """

          Create a new issue.
@@ -407,7 +439,9 @@ 

          :param comment_id: the id of the comment

          :return:

          """

-         request_url = "{}issue/{}/comment/{}".format(self.create_basic_url(), issue_id, comment_id)

+         request_url = "{}issue/{}/comment/{}".format(

+             self.create_basic_url(), issue_id, comment_id

+         )

  

          return_value = self._call_api(request_url)

  
@@ -578,7 +612,9 @@ 

              list: A list of activities done by a given user on some particular

                    date for all the projects for given Pagure instance.

          """

-         request_url = "{}/api/0/user/{}/activity/{}".format(self.instance, username, date)

+         request_url = "{}/api/0/user/{}/activity/{}".format(

+             self.instance, username, date

+         )

  

          payload = {}

          if username is not None:
@@ -592,9 +628,7 @@ 

  

          return return_value["activities"]

  

-     def create_pull_request(

-             self, title, branch_to, branch_from,

-             initial_comment=None):

+     def create_pull_request(self, title, branch_to, branch_from, initial_comment=None):

          """

          Create pull-request

           -------------------
@@ -606,6 +640,12 @@ 

          :param branch_from: the name of the branch containing the changes to merge

          :param initial_comment: the initial comment describing what these changes

              are about

+         :param repo_from: the name on the project the changes originate from,

+             received as a dictionary and posted as a string

+         :param repo_from_username: the username of the project the changes

+             originate from, received as a dictionary and posted as a string

+         :param repo_from_namespace: the namespace of the project the changes

+             originate from, received as a dictionary and posted as a string

          :return:

          """

          request_url = "{}pull-request/new".format(self.create_basic_url())
@@ -613,6 +653,9 @@ 

              "title": title,

              "branch_to": branch_to,

              "branch_from": branch_from,

+             "repo_from": self.repo_from["repo"],

+             "repo_from_username": self.repo_from["username"],

+             "repo_from_namespace": self.repo_from["namespace"],

          }

          if initial_comment is not None:

              payload["initial_comment"] = initial_comment
@@ -665,7 +708,9 @@ 

              list: A list of Pull-Requests a user is able to action for all the

                    projects for given Pagure instance.

          """

-         request_url = "{}/api/0/user/{}/requests/actionable".format(self.instance, username)

+         request_url = "{}/api/0/user/{}/requests/actionable".format(

+             self.instance, username

+         )

  

          payload = {}

          if username is not None:

Pagure is now expecting three more arguments to specify from which project a pull request is opened with API:
repo_from, repo_from_username and repo_from_namespace.

Libpagure receives them as a dictionary and converts them into a string.

The second commit are the changes black made on all the libpagure.py file. Now both black and flake8 pass.

Pull-Request has been merged by cverna

4 years ago
Metadata