From acebebdc9fa637ee79d9343bbb3665760fd093e4 Mon Sep 17 00:00:00 2001 From: "BK brandon.kurtz@airbnb.com" <> Date: Mon, 6 Feb 2023 23:27:25 -0800 Subject: [PATCH] PR templates --- .../edenscm/ext/github/pull_request_body.py | 23 ++++++++++++++----- eden/scm/edenscm/ext/github/submit.py | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/eden/scm/edenscm/ext/github/pull_request_body.py b/eden/scm/edenscm/ext/github/pull_request_body.py index 64aadb3323457..d37ab5e575053 100644 --- a/eden/scm/edenscm/ext/github/pull_request_body.py +++ b/eden/scm/edenscm/ext/github/pull_request_body.py @@ -5,6 +5,7 @@ import re from typing import List, Tuple +import string from .gh_submit import Repository @@ -16,6 +17,7 @@ def create_pull_request_title_and_body( pr_numbers_and_num_commits: List[Tuple[int, int]], pr_numbers_index: int, repository: Repository, + template: str, ) -> Tuple[str, str]: r"""Returns (title, body) for the pull request. @@ -48,6 +50,15 @@ def create_pull_request_title_and_body( owner, name = repository.get_upstream_owner_and_name() pr = pr_numbers_and_num_commits[pr_numbers_index][0] reviewstack_url = f"https://reviewstack.dev/{owner}/{name}/pull/{pr}" + if not template: + body = string.Template(f''' +$commit_msg +$horizontal_rule +Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack]({reviewstack_url}). +$bulleted_list +''') + else: + body = string.Template(template) bulleted_list = "\n".join( [ _format_stack_entry(pr_number, index, pr_numbers_index, num_commits) @@ -55,12 +66,12 @@ def create_pull_request_title_and_body( ] ) title = firstline(commit_msg) - body = f"""{commit_msg} -{_HORIZONTAL_RULE} -Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack]({reviewstack_url}). -{bulleted_list} -""" - return title, body + tbody = body.safe_substitute( + commit_msg=commit_msg, + horizontal_rule=_HORIZONTAL_RULE, + bulleted_list=bulleted_list, + ) + return title, tbody _STACK_ENTRY = re.compile(r"^\* (__->__ )?#([1-9]\d*).*$") diff --git a/eden/scm/edenscm/ext/github/submit.py b/eden/scm/edenscm/ext/github/submit.py index 0086d171066bb..23ac7154e917c 100644 --- a/eden/scm/edenscm/ext/github/submit.py +++ b/eden/scm/edenscm/ext/github/submit.py @@ -262,11 +262,13 @@ async def rewrite_pull_request_body( head_commit_data = partition[0] commit_msg = head_commit_data.get_msg() + title, body = create_pull_request_title_and_body( commit_msg, pr_numbers_and_num_commits, index, repository, + template=ui.config("pr", "template", default="") ) pr = head_commit_data.pr assert pr