def post_comment(): owner = request.form['owner'] repo = request.form['repo'] pull_number = request.form['pull_number'] path = request.form['path'] commit_id = request.form['commit_id'] line_number = int(request.form['line_number']) body = request.form['body'] if not owner: return "Incomplete post_comment request, missing owner" if not repo: return "Incomplete post_comment request, missing repo" if not pull_number: return "Incomplete post_comment request, missing pull_number" if not path: return "Incomplete post_comment request, missing path" if not commit_id: return "Incomplete post_comment request, missing commit_id" if not line_number: return "Incomplete post_comment request, missing line_number" if not body: return "Incomplete post_comment request, missing body" token = session['token'] if not token: return "You must be oauthed to post a comment." pr = github.get_pull_request(token, owner, repo, pull_number) base_sha = pr['base']['sha'] diff_position = github_comments.lineNumberToDiffPosition(token, owner, repo, base_sha, path, commit_id, line_number, False) # False = on_left (for now!) if not diff_position: return "Unable to get diff position for %s:%s @%s" % (path, line_number, commit_id) sys.stderr.write('diff_position=%s\n' % diff_position) response = github.post_comment(token, owner, repo, pull_number, commit_id, path, diff_position, body) if response: github_comments.add_line_number_to_comment(token, owner, repo, base_sha, response) return jsonify(response)
def save_draft_comment(): owner = request.form['owner'] repo = request.form['repo'] path = request.form['path'] pull_number = request.form['pull_number'] commit_id = request.form['commit_id'] line_number = int(request.form['line_number']) in_reply_to = request.args.get('in_reply_to') comment = { 'owner': owner, 'repo': repo, 'pull_number': pull_number, 'path': path, 'original_commit_id': commit_id, 'body': request.form['body'] } if in_reply_to: comment['in_reply_to'] = in_reply_to comment_id = request.form.get('id') if comment_id: comment['id'] = comment_id token = session['token'] pr = github.get_pull_request(token, owner, repo, pull_number) base_sha = pr['base']['sha'] position, hunk = github_comments.lineNumberToDiffPositionAndHunk(token, owner, repo, base_sha, path, commit_id, line_number, False) if not position: return "Unable to get diff position for %s:%s @%s" % (path, line_number, commit_id) comment['original_position'] = position comment['diff_hunk'] = hunk result = db.add_draft_comment(session['login'], comment) result = db.githubify_comment(result) # This is a bit roundabout, but more reliable! github_comments.add_line_number_to_comment(token, owner, repo, base_sha, result) return jsonify(result)