def review(ui, repo, *dest, **opts): """create a code review for some changesets on kiln Review creates a brand new code review on kiln for a changeset on kiln. If no revision is specified, the code review defaults to the most recent changeset. Specify people to peek at your review by passing a comma-separated list of people to review your code, by passing multiple -p flags, or both. hg review -p tim,alex,ben -p joey You can specify revisions by passing a hash-range, hg review -r 13bs32abc:tip or by passing individual changesets hg review -r 75c471319a5b -r 41056495619c Using -e will open up your favorite editor and includes all the changeset descriptions for any revisions selected as the code review comment. """ prefix = repo.ui.config("auth", "kiln.prefix") current_user = repo.ui.config("auth", "kiln.username") or repo.ui.config( "ui", "username") if prefix is None: ui.warn("In order to work, in your hgrc please set:\n\n") ui.warn("[auth]\n") ui.warn("kiln.prefix = https://kilnrepo.kilnhg.com\n") ui.warn("kiln.username = [email protected]\n") ui.warn("kiln.password = keymash\n") return 0 review_params = {} changesets = ['tip'] if opts.get('revs'): revs = opts.get('revs') changesets = [ repo[rev].hex()[:12] for rev in scmutil.revrange(repo, revs) ] review_params['revs'] = changesets comment = opts.get('comment') if opts.get('editor'): if opts.get('comment'): default_comment = opts['comment'] else: changeset_descs = [repo[rev].description() for rev in changesets] default_comment = "\n".join(changeset_descs) comment = ui.edit(default_comment, current_user) if comment: review_params['sDescription'] = comment if opts.get('title'): review_params['sTitle'] = opts.get('title') token = _token() review_params['token'] = token if dest: dest = dest[0] rev_repo = _get_user_repos(ui, repo, dest) if rev_repo: all_repos = _get_kiln_paths(ui, repo, token) kiln_repo = all_repos[rev_repo] review_params["ixRepo"] = kiln_repo["ixRepo"] reviewers = _get_reviewers(ui, repo, token, opts.get('people')) review_params['ixReviewers'] = [r['ixPerson'] for r in reviewers] review_status = _make_review(review_params) if review_status: ui.status("Review created!\n") ui.status("%s/Review/%s" % (prefix, review_status['ixReview'])) return 1 else: return 0
def review(ui, repo, *dest, **opts): """create a code review for some changesets on kiln Review creates a brand new code review on kiln for a changeset on kiln. If no revision is specified, the code review defaults to the most recent changeset. Specify people to peek at your review by passing a comma-separated list of people to review your code, by passing multiple -p flags, or both. hg review -p tim,alex,ben -p joey You can specify revisions by passing a hash-range, hg review -r 13bs32abc:tip or by passing individual changesets hg review -r 75c471319a5b -r 41056495619c Using -e will open up your favorite editor and includes all the changeset descriptions for any revisions selected as the code review comment. """ prefix = repo.ui.config("auth","kiln.prefix") current_user = repo.ui.config("auth","kiln.username") or repo.ui.config("ui","username") if prefix is None: ui.warn("In order to work, in your hgrc please set:\n\n") ui.warn("[auth]\n") ui.warn("kiln.prefix = https://kilnrepo.kilnhg.com\n") ui.warn("kiln.username = [email protected]\n") ui.warn("kiln.password = keymash\n") return 0 review_params = {} changesets = ['tip'] if opts.get('revs'): revs = opts.get('revs') changesets = [repo[rev].hex()[:12] for rev in scmutil.revrange(repo, revs)] review_params['revs'] = changesets comment = opts.get('comment') if opts.get('editor'): if opts.get('comment'): default_comment = opts['comment'] else: changeset_descs = [repo[rev].description() for rev in changesets] default_comment = "\n".join(changeset_descs) comment = ui.edit(default_comment, current_user) if comment: review_params['sDescription'] = comment if opts.get('title'): review_params['sTitle'] = opts.get('title') token = _token() review_params['token'] = token if dest: dest = dest[0] rev_repo = _get_user_repos(ui, repo, dest) if rev_repo: all_repos = _get_kiln_paths(ui, repo, token) kiln_repo = all_repos[rev_repo] review_params["ixRepo"] = kiln_repo["ixRepo"] reviewers = _get_reviewers(ui, repo, token, opts.get('people')) review_params['ixReviewers'] = [r['ixPerson'] for r in reviewers] review_status = _make_review(review_params) if review_status: ui.status("Review created!\n") ui.status("%s/Review/%s" % (prefix, review_status['ixReview'])) return 1 else: return 0
def push_with_review(origfn, ui, repo, *args, **opts): """overrides 'hg push' to add creating a code review for the push on kiln. Review creates a brand new code review on kiln for a changeset on kiln. If no revision is specified, the code review defaults to the most recent changeset. Specify people to peek at your review by passing a comma-separated list of people to review your code, by passing multiple --rr flags, or both. hg push --rr tim,alex,ben --rr joey You can specify revisions by passing a hash-range, hg push --rrev 13bs32abc:tip or by passing individual changesets hg push --rrev 75c471319a5b --rrev 41056495619c Using --reditor will open up your favorite editor and includes all the changeset descriptions for any revisions selected as the code review comment. All the flags supported by 'hg push' are passed through to push. """ # First order of business: If the user passed in --rr none, just # fall back onto the native push. if opts.get('rr') == ['none']: return origfn(ui, repo, *args, **opts) # TODO(csilvers): also bypass review if # a) this push is a conflict-free merge push # b) they have a review number in the commit notes (this means # there's already a review for them in kilnhg). url_prefix = repo.ui.config('auth', 'kiln.prefix') if url_prefix is None: ui.warn("In order to work, in your hgrc please set:\n\n") ui.warn("[auth]\n") ui.warn("kiln.prefix = https://<kilnrepo.kilnhg.com> # no trailing /\n") ui.warn("kiln.username = <username>@<domain.com>\n") ui.warn("kiln.password = <password>\n") return 0 # dest is the commandline argument. At most one should be specified. dest = None if args: if len(args) > 1: raise mercurial.util.Abort('At most one dest should be specified.') dest = args[0] review_params = {} auth_token = _get_authtoken(ui) review_params['token'] = auth_token # -rtitle: title title = opts.pop('rtitle', None) if title: review_params['sTitle'] = title # -rcomment: comment comment = opts.pop('rcomment', None) if comment: review_params['sDescription'] = comment # -rrev: revs revs = opts.pop('rrev', None) if revs: changesets = [repo[rev].hex()[:12] for rev in mercurial.scmutil.revrange(repo, revs)] else: # TODO(csilvers): don't use an internal function from hg. changeset_nodes = mercurial.hg._outgoing(ui, repo, dest, {}) if not changeset_nodes: raise mercurial.util.Abort('No changesets found to push/review. Use' ' --rrev to specify changesets manually.') changesets = [mercurial.node.hex(n)[:12] for n in changeset_nodes] review_params['revs'] = changesets # -rr: people people = opts.pop('rr', None) if not people: raise mercurial.util.Abort('Must specify at least one reviewer via --rr.' ' Pass "--rr none" to bypass review.') assert people != ['none'] # should have been checked above reviewers = _get_reviewers(ui, auth_token, people) review_params['ixReviewers'] = [r['ixPerson'] for r in reviewers] # -e: editor editor = opts.pop('editor', None) if editor: # If -rcomment was also specified, default the editor-text to that. # Otherwise, use the text from the changesets being reviewed. if 'sDescription' in review_params: default_comment = review_params['sDescription'] else: changeset_descs = [repo[rev].description() for rev in changesets] default_comment = "\n".join(changeset_descs) current_user = (repo.ui.config('auth', 'kiln.username') or repo.ui.config('ui', 'username')) review_params['sDescription'] = ui.edit(default_comment, current_user) repo_url_to_push_to = _get_repo_to_push_to(repo, dest) review_params['ixRepo'] = _get_repo_index_for_repo_url(repo, auth_token, repo_url_to_push_to) # First do the push, then do the review. origfn(ui, repo, *args, **opts) ui.status('Creating review...') review_status = _make_review(review_params) assert review_status, 'Kiln API is returning None??' if 'ixReview' not in review_status: ui.status('FAILED: %s\n' % review_status) return 0 ui.status('done!\n') ui.status('%s/Review/%s\n' % (url_prefix, review_status['ixReview'])) return 1