def publish_draft_comments(): owner = request.form['owner'] repo = request.form['repo'] pull_number = request.form['pull_number'] token = session['token'] login = session['login'] new_top_level = request.form['top_level_comment'] 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" draft_comments = db.get_draft_comments(login, owner, repo, pull_number) if not draft_comments and not new_top_level: return "No comments to publish!" # TODO(danvk): publish comments in parallel errors = [] for comment in draft_comments: result = github.post_comment(token, owner, repo, pull_number, comment) if not result: errors.append(comment) sys.stderr.write("Unable to publish comment: %s" % json.dumps(comment)) else: db.delete_draft_comments([comment['id']]) logging.info('Successfully published %d comments', len(draft_comments)) if new_top_level: result = github.post_issue_comment(token, owner, repo, pull_number, new_top_level) if not result: return "Unable to publish comment: %s" % new_top_level github.expire_cache_for_pull_request(owner, repo, pull_number) github.expire_cache_for_pull_request_children(owner, repo, pull_number) if errors: flash("Some comments could not be published. They've been left as drafts.") return redirect(url_for('pull', owner=owner, repo=repo, number=pull_number))
def check_for_updates(): owner = request.form['owner'] repo = request.form['repo'] pull_number = request.form['pull_number'] updated_at = request.form['updated_at'] token = session['token'] pr = github.get_pull_request(token, owner, repo, pull_number, bust_cache=True) if not pr: return "Error" if pr['updated_at'] <= updated_at: return "OK" # Invalidate associated RPCs: commit list, comments github.expire_cache_for_pull_request_children(owner, repo, pull_number) return "Update"