-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not keep @mention people on merge commits
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,12 @@ | |
global_cfg = {} | ||
|
||
|
||
# Replace @mention with `@mention` to suppress pings in merge commits. | ||
# Note: Don't replace non-mentions like "[email protected]". | ||
def suppress_pings(text): | ||
return re.sub(r'\B(@\S+)', r'`\g<1>`', text) # noqa | ||
|
||
|
||
@contextmanager | ||
def buildbot_sess(repo_cfg): | ||
sess = requests.Session() | ||
|
@@ -347,7 +353,7 @@ def refresh(self): | |
issue = self.get_repo().issue(self.num) | ||
|
||
self.title = issue.title | ||
self.body = issue.body | ||
self.body = suppress_pings(issue.body) | ||
|
||
def fake_merge(self, repo_cfg): | ||
if not repo_cfg.get('linear', False): | ||
|
@@ -1533,7 +1539,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q | |
|
||
state = PullReqState(pull.number, pull.head.sha, status, db, repo_label, mergeable_que, gh, repo_cfg['owner'], repo_cfg['name'], repo_cfg.get('labels', {}), repos, repo_cfg.get('test-on-fork')) # noqa | ||
state.title = pull.title | ||
state.body = pull.body | ||
state.body = suppress_pings(pull.body) | ||
state.head_ref = pull.head.repo[0] + ':' + pull.head.ref | ||
state.base_ref = pull.base.ref | ||
state.set_mergeable(None) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from homu.main import suppress_pings | ||
|
||
|
||
def test_suppress_pings_in_PR_body(): | ||
body = ( | ||
"r? @matklad\n" # should escape | ||
"@bors r+\n" # shouldn't | ||
"[email protected]" # shouldn't | ||
) | ||
|
||
expect = ( | ||
"r? `@matklad`\n" | ||
"`@bors` r+\n" | ||
"[email protected]" | ||
) | ||
|
||
assert suppress_pings(body) == expect |