def _create_diff(ghrequest, config): # Dictionary with filename matched with a string of diff ghrequest.diff = {} # Process the files and prepare the diff for the gist helpers.autopep8(ghrequest, config) # Create the gist helpers.create_gist(ghrequest) comment = "Here you go with [the gist]({}) !\n\n" + \ "> You can ask me to create a PR against this branch " + \ "with those fixes. Simply comment " + \ "`@pep8speaks pep8ify`.\n\n" if ghrequest.reviewer == ghrequest.author: # Both are the same person comment += "@{} " comment = comment.format(ghrequest.gist_url, ghrequest.reviewer) else: comment += "@{} @{} " comment = comment.format(ghrequest.gist_url, ghrequest.reviewer, ghrequest.author) query = "/repos/{}/issues/{}/comments" query = query.format(ghrequest.repository, str(ghrequest.pr_number)) response = utils.query_request(query, method='POST', json={"body": comment}) ghrequest.comment_response = response.json() if ghrequest.error: return utils.Response(ghrequest, status=400) return utils.Response(ghrequest)
def _create_diff(request, data, config): # Dictionary with filename matched with a string of diff data["diff"] = {} # Process the files and prepare the diff for the gist helpers.autopep8(data, config) # Create the gist helpers.create_gist(data, config) comment = "Here you go with [the gist]({}) !\n\n" + \ "> You can ask me to create a PR against this branch " + \ "with those fixes. Submit a review comment as " + \ "`@pep8speaks pep8ify`.\n\n" if data["reviewer"] == data["author"]: # Both are the same person comment += "@{} " comment = comment.format(data["gist_url"], data["reviewer"]) else: comment += "@{} @{} " comment = comment.format(data["gist_url"], data["reviewer"], data["author"]) headers = {"Authorization": "token " + os.environ["GITHUB_TOKEN"]} query = "https://api.github.com/repos/{}/issues/{}/comments" query = query.format(data["repository"], str(data["pr_number"])) response = requests.post(query, json={"body": comment}, headers=headers) data["comment_response"] = response.json() status_code = 200 if "error" in data.keys(): status_code = 400 js = json.dumps(data) return Response(js, status=status_code, mimetype='application/json')