From 2d6c7c26d30ccb3c8540cee5787d0ff4c4565059 Mon Sep 17 00:00:00 2001 From: Jerry Zhang Date: Tue, 12 Mar 2024 11:29:40 -0700 Subject: [PATCH] upload: Support Update-Pr-Body as a commit tag This allows you to manually specify one or more prs as no-update while maintaining the default option for all other prs. (and vise versa) Fixes: #140 --- docs/upload.md | 5 ++++- revup/topic_stack.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/docs/upload.md b/docs/upload.md index a2c4505..9850f7c 100644 --- a/docs/upload.md +++ b/docs/upload.md @@ -82,6 +82,9 @@ branches once they are merged. If a relative branch is specified, only one "Branch:" can be specified and all relative topics must specify the same relative branch (or none, in which case it will get set automatically). +**Update-Pr-Body:** +: Overrides the value of the update-pr-body command line flag for this topic. + For each review, the pull request title is the title of the first commit message in that topic, and the body is the body text of the first commit message in that topic. A user can also create an empty commit if they @@ -197,4 +200,4 @@ mappings are used to transform usernames specified in Reviewers/Assignees. If "a2r", add users from the Assignees tag as reviewers. If "both", do both of the previous. **--head** -: The name or commit of the branch to be uploaded. If not specified, defaults to HEAD. \ No newline at end of file +: The name or commit of the branch to be uploaded. If not specified, defaults to HEAD. diff --git a/revup/topic_stack.py b/revup/topic_stack.py index bcb5976..fd407b0 100644 --- a/revup/topic_stack.py +++ b/revup/topic_stack.py @@ -48,6 +48,7 @@ def format_remote_branch(uploader: str, base_branch: str, topic: str) -> str: TAG_RELATIVE = "relative" TAG_RELATIVE_BRANCH = "relative-branch" TAG_UPLOADER = "uploader" +TAG_UPDATE_PR_BODY = "update-pr-body" VALID_TAGS = { TAG_BRANCH, TAG_LABEL, @@ -57,6 +58,7 @@ def format_remote_branch(uploader: str, base_branch: str, topic: str) -> str: TAG_ASSIGNEE, TAG_TOPIC, TAG_UPLOADER, + TAG_UPDATE_PR_BODY, } RE_COMMIT_LABEL = re.compile(r"^(?P[a-zA-Z\-_0-9]+):.*|^\[(?P[a-zA-Z\-_0-9]+)\].*") @@ -494,6 +496,14 @@ async def populate_reviews( if len(topic.tags[TAG_UPLOADER]) > 1: raise RevupUsageException(f"Can't specify more than one uploader for topic {name}!") + if TAG_UPDATE_PR_BODY in topic.tags: + if len(topic.tags[TAG_UPDATE_PR_BODY]) > 1 or min( + topic.tags[TAG_UPDATE_PR_BODY] + ).lower() not in {"true", "false"}: + raise RevupUsageException( + f"Invalid tags for update-pr-body: {topic.tags[TAG_UPDATE_PR_BODY]}" + ) + relative_topic = "" if force_relative_chain and last_topic is not None: relative_topic = last_topic @@ -1055,7 +1065,7 @@ async def query_github(self) -> None: def populate_update_info( self, - update_pr_body: bool, + update_pr_body_arg: bool, ) -> None: """ Populate information necessary to do PR creation / update in github. @@ -1128,6 +1138,11 @@ def populate_update_info( topic.tags[TAG_ASSIGNEE], self.names_to_logins ).difference(review.pr_info.assignees) + if TAG_UPDATE_PR_BODY in topic.tags: + update_pr_body = min(topic.tags[TAG_UPDATE_PR_BODY]).lower() == "true" + else: + update_pr_body = update_pr_body_arg + if review.pr_info.baseRef != review.remote_base: review.pr_update.baseRef = review.remote_base if update_pr_body and review.pr_info.body != body: