Skip to content

Commit 7e03320

Browse files
authored
Merge pull request #100 from lzutao/no-mention
Do not keep @mention people on merge commits
2 parents dde7c15 + 2778244 commit 7e03320

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

homu/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
global_cfg = {}
4343

4444

45+
# Replace @mention with `@mention` to suppress pings in merge commits.
46+
# Note: Don't replace non-mentions like "[email protected]".
47+
def suppress_pings(text):
48+
return re.sub(r'\B(@\S+)', r'`\g<1>`', text) # noqa
49+
50+
4551
@contextmanager
4652
def buildbot_sess(repo_cfg):
4753
sess = requests.Session()
@@ -347,7 +353,7 @@ def refresh(self):
347353
issue = self.get_repo().issue(self.num)
348354

349355
self.title = issue.title
350-
self.body = issue.body
356+
self.body = suppress_pings(issue.body)
351357

352358
def fake_merge(self, repo_cfg):
353359
if not repo_cfg.get('linear', False):
@@ -1533,7 +1539,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
15331539

15341540
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
15351541
state.title = pull.title
1536-
state.body = pull.body
1542+
state.body = suppress_pings(pull.body)
15371543
state.head_ref = pull.head.repo[0] + ':' + pull.head.ref
15381544
state.base_ref = pull.base.ref
15391545
state.set_mergeable(None)

homu/tests/test_pr_body.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from homu.main import suppress_pings
2+
3+
4+
def test_suppress_pings_in_PR_body():
5+
body = (
6+
"r? @matklad\n" # should escape
7+
"@bors r+\n" # shouldn't
8+
"[email protected]" # shouldn't
9+
)
10+
11+
expect = (
12+
"r? `@matklad`\n"
13+
"`@bors` r+\n"
14+
15+
)
16+
17+
assert suppress_pings(body) == expect

0 commit comments

Comments
 (0)