diff --git a/homu/main.py b/homu/main.py index 6b3b4b6..a86529d 100644 --- a/homu/main.py +++ b/homu/main.py @@ -42,6 +42,12 @@ global_cfg = {} +# Replace @mention with `@mention` to suppress pings in merge commits. +# Note: Don't replace non-mentions like "email@gmail.com". +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) diff --git a/homu/tests/test_pr_body.py b/homu/tests/test_pr_body.py new file mode 100644 index 0000000..06a5287 --- /dev/null +++ b/homu/tests/test_pr_body.py @@ -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 + "mail@example.com" # shouldn't + ) + + expect = ( + "r? `@matklad`\n" + "`@bors` r+\n" + "mail@example.com" + ) + + assert suppress_pings(body) == expect