Skip to content

Commit

Permalink
Do not keep @mention people on merge commits
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Sep 1, 2020
1 parent dde7c15 commit 2778244
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions homu/tests/test_pr_body.py
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

0 comments on commit 2778244

Please sign in to comment.