From b7af7b37685f84217e7a7e3b9c6c07d0e01fb464 Mon Sep 17 00:00:00 2001 From: Lei Yang Date: Jul 17 2015 12:32:56 +0000 Subject: Change the format of some return values and doc them --- diff --git a/libpagure/libpagure.py b/libpagure/libpagure.py index 5fc3943..699923b 100644 --- a/libpagure/libpagure.py +++ b/libpagure/libpagure.py @@ -191,7 +191,8 @@ class Pagure: """ Merge a pull request. :param request_id: the id of the request - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/pull-request/{}/merge".format( @@ -204,16 +205,17 @@ class Pagure: return_value = self.__call_api(request_url, method='POST') if return_value['message'] == "Changes merged!": - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def close_request(self, request_id): """ Close a pull request. :param request_id: the id of the request - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/pull-request/{}/close".format( @@ -226,10 +228,10 @@ class Pagure: return_value = self.__call_api(request_url, method='POST') if return_value['message'] == "Pull-request closed!": - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def comment_request(self, request_id, body, commit=None, filename=None, row=None): """ @@ -239,7 +241,8 @@ class Pagure: :param commit: which commit to comment on :param filename: which file to comment on :param row: which line of code to comment on - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/pull-request/{}/comment".format( @@ -260,10 +263,10 @@ class Pagure: return_value = self.__call_api(request_url, method='POST', data=payload) if return_value['message'] == "Comment added": - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def flag_request(self, request_id, username, percent, comment, url, uid=None, commit=None): """ @@ -275,7 +278,8 @@ class Pagure: :param url: a relevant URL :param uid: a unique id used to identify the flag. If not provided, pagure will generate one :param commit: which commit to flag on - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/pull-request/{}/flag".format( @@ -294,10 +298,10 @@ class Pagure: return_value = self.__call_api(request_url, method='POST', data=payload) if return_value['message'] == "Flag added" or return_value['message'] == "Flag updated": - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def create_issue(self, title, content, private=None): """ @@ -305,7 +309,8 @@ class Pagure: :param title: the title of the issue :param content: the description of the issue :param private: whether create this issue as private - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/new_issue".format( @@ -321,10 +326,10 @@ class Pagure: return_value = self.__call_api(request_url, method='POST', data=payload) if return_value['message'] == "Issue created": - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def list_issues(self, status=None, tags=None, assignee=None, author=None): """ @@ -398,7 +403,8 @@ class Pagure: Change the status of an issue. :param issue_id: the id of the issue :param new_status: the new status fo the issue - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/issue/{}/status".format( @@ -413,17 +419,18 @@ class Pagure: return_value = self.__call_api(request_url, method='POST', data=payload) if return_value['message'].startswith("Successfully"): - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def comment_issue(self, issue_id, body): """ Comment to an issue. :param issue_id: the id of the comment :param body: the comment body - :return: + :return: a dictionary, key 'result' contains a boolean indicating whether the operation was successful, + key 'message' contains the message returned from Pagure """ if self.ForkUsername is None: request_url = "{}/api/0/{}/issue/{}/comment".format( @@ -438,10 +445,10 @@ class Pagure: return_value = self.__call_api(request_url, method='POST', data=payload) if return_value['message'] == 'Comment added': - result = (True, return_value['message']) + return_value['result'] = True else: - result = (False, return_value['message']) - return result + return_value['result'] = False + return return_value def project_tags(self): """