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 ef12644 commit 7ce245c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 11 additions & 8 deletions docs/upload.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ 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:**
: When set to true (default) revup will attempt to update the github PR body
whenever the local version has changes. When set to false, revup will create
PRs with the commit text to start out, but does not attempt to update it again.
This allows users to use the github UI to edit the PR body without having
revup overwrite those changes.

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 @@ -149,13 +156,9 @@ confirmation step and only print topic info.
: Print out status info of pull requests for existing topics but don't attempt
to push or update them.

**--no-update-pr-body**
: Revup will attempt to update the github PR body whenever the local version
has changes that differ from the remote. However, this means that if a user
uses the github web interface to edit the PR body, especially to embed
HTML or images, revup won't know about it and will try to overwrite it on
the next upload. With this flag, uploading will only update the pr body
on creation, but not after, ensuring that any custom PR text is kept.
**--update-pr-body**
: Boolean that specifies how the pr body text is updated. See the
Update-Pr-Body: tag section for details.

**--review-graph**
: Enable the review graph feature, which adds a comment containing links and
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 7ce245c

Please sign in to comment.