Skip to content

Commit

Permalink
Fix an issue where github.preserve-pull-request-description=true was …
Browse files Browse the repository at this point in the history
…adding \n to commit message.

Summary:
While #863 fixed some important
issues with respect to recognizing `\r\n`, it also introduced a new
issue where running `sl pr s` with `github.preserve-pull-request-description=true`
would inadvertently add an extra `\n` before the horizontal rule
delimiting the Sapling stack information.

This fixes `create_pull_request_title_and_body()` to preserve whatever
whitespace was originally present before the horizontal rule,
only adding a new `\n` to the end of the commit message if it did not
already have one.

Test Plan:
```
./tests/run-tests.py ./tests/test-doctest.py
```
  • Loading branch information
bolinfest committed Apr 19, 2024
1 parent 1d26709 commit 33d9b4f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion eden/scm/sapling/ext/github/pull_request_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,33 @@ def create_pull_request_title_and_body(
* __->__ #42
* #4
Add trailing whitespace to commit_msg and ensure it is preserved.
>>> commit_msg += '\n\n'
>>> title, body = create_pull_request_title_and_body(
... commit_msg,
... pr_numbers_and_num_commits,
... pr_numbers_index,
... contributor_repo,
... )
>>> print(body.replace(reviewstack_url, "{reviewstack_url}"))
The original commit message.
Second line of message.
<BLANKLINE>
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack]({reviewstack_url}).
* #1
* #2 (2 commits)
* __->__ #42
* #4
Disable reviewstack message:
>>> title, body = create_pull_request_title_and_body(commit_msg, pr_numbers_and_num_commits,
... pr_numbers_index, contributor_repo, reviewstack=False)
>>> print(body)
The original commit message.
Second line of message.
<BLANKLINE>
---
[//]: # (BEGIN SAPLING FOOTER)
* #1
Expand Down Expand Up @@ -84,7 +105,9 @@ def create_pull_request_title_and_body(
)
extra.append(bulleted_list)
if extra:
body = "\n".join([body, _HORIZONTAL_RULE, _SAPLING_FOOTER_MARKER] + extra)
if not body.endswith("\n"):
body += "\n"
body += "\n".join([_HORIZONTAL_RULE, _SAPLING_FOOTER_MARKER] + extra)
return title, body


Expand Down

0 comments on commit 33d9b4f

Please sign in to comment.