Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not keep @mention people on merge commits #100

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case is unfortunate, but I assume nobody use @bors r+ in PR body.

"[email protected]"
)

assert suppress_pings(body) == expect