Skip to content

Commit

Permalink
upload: Support Update-Pr-Body as a commit tag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jerry-skydio committed Mar 13, 2024
1 parent 4c4b457 commit 8c17f14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
: The name or commit of the branch to be uploaded. If not specified, defaults to HEAD.
17 changes: 16 additions & 1 deletion revup/topic_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<label1>[a-zA-Z\-_0-9]+):.*|^\[(?P<label2>[a-zA-Z\-_0-9]+)\].*")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 8c17f14

Please sign in to comment.