From de8f62ec426add9289f66851767b042b2931ed76 Mon Sep 17 00:00:00 2001 From: Lenka Segura Date: May 07 2019 09:13:48 +0000 Subject: [PATCH 1/2] Adjust the repo_from in create_pull_request 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. --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index 8ff0e6a..cdc4f54 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -606,6 +606,12 @@ class Pagure(object): :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 +619,9 @@ class Pagure(object): "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 From 075ee2f17c36b1c1477f72f711204945b609d5b1 Mon Sep 17 00:00:00 2001 From: Lenka Segura Date: May 07 2019 09:23:09 +0000 Subject: [PATCH 2/2] code style changes --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index cdc4f54..d06ff43 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -11,6 +11,7 @@ except ImportError: # 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 @@ class Pagure(object): """ 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 @@ class Pagure(object): 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 @@ class Pagure(object): 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 @@ class Pagure(object): 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 @@ class Pagure(object): :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 @@ class Pagure(object): :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 @@ class Pagure(object): :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 @@ class Pagure(object): 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 @@ class Pagure(object): :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 @@ class Pagure(object): 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 @@ class Pagure(object): :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 @@ class Pagure(object): 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 @@ class Pagure(object): 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 ------------------- @@ -621,7 +655,7 @@ class Pagure(object): "branch_from": branch_from, "repo_from": self.repo_from["repo"], "repo_from_username": self.repo_from["username"], - "repo_from_namespace": self.repo_from["namespace"] + "repo_from_namespace": self.repo_from["namespace"], } if initial_comment is not None: payload["initial_comment"] = initial_comment @@ -674,7 +708,9 @@ class Pagure(object): 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: