Skip to content

Commit b15d6d3

Browse files
committed
Add ignore blocks for merge commit bodies
1 parent edc1ad5 commit b15d6d3

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

homu/main.py

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141

4242
VARIABLES_RE = re.compile(r'\${([a-zA-Z_]+)}')
4343

44+
IGNORE_BLOCK_START = '<!-- homu-ignore:start -->'
45+
IGNORE_BLOCK_END = '<!-- homu-ignore:end -->'
46+
IGNORE_BLOCK_RE = re.compile(r'<!--\s*homu-ignore:start\s*-->.*<!--\s*homu-ignore:end\s*-->',
47+
flags=re.MULTILINE|re.DOTALL|re.IGNORECASE)
48+
4449
global_cfg = {}
4550

4651

@@ -49,6 +54,11 @@
4954
def suppress_pings(text):
5055
return re.sub(r'\B(@\S+)', r'`\g<1>`', text) # noqa
5156

57+
# Replace any text between IGNORE_BLOCK_START and IGNORE_BLOCK_END
58+
# HTML comments with an empty string in merge commits
59+
def suppress_ignore_block(text):
60+
return IGNORE_BLOCK_RE.sub('', text)
61+
5262

5363
@contextmanager
5464
def buildbot_sess(repo_cfg):
@@ -356,6 +366,7 @@ def refresh(self):
356366

357367
self.title = issue.title
358368
self.body = suppress_pings(issue.body)
369+
self.body = suppress_ignore_block(self.body)
359370

360371
def fake_merge(self, repo_cfg):
361372
if not repo_cfg.get('linear', False):
@@ -1554,6 +1565,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
15541565
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
15551566
state.title = pull.title
15561567
state.body = suppress_pings(pull.body)
1568+
state.body = suppress_ignore_block(state.body)
15571569
state.head_ref = pull.head.repo[0] + ':' + pull.head.ref
15581570
state.base_ref = pull.base.ref
15591571
state.set_mergeable(None)

homu/server.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
PullReqState,
66
parse_commands,
77
db_query,
8+
IGNORE_BLOCK_END,
9+
IGNORE_BLOCK_START,
810
INTERRUPTED_BY_HOMU_RE,
11+
suppress_ignore_block,
12+
suppress_pings,
913
synchronize,
1014
LabelEvent,
1115
)
@@ -306,6 +310,9 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
306310
failures.append(state.num)
307311
continue
308312

313+
state.body = suppress_pings(state.body)
314+
state.body = suppress_ignore_block(state.body)
315+
309316
merge_msg = 'Rollup merge of #{} - {}, r={}\n\n{}\n\n{}'.format(
310317
state.num,
311318
state.head_ref,
@@ -343,7 +350,10 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
343350
if base_url:
344351
pr_list = ','.join(str(x.num) for x in successes)
345352
link = '{}/queue/{}?prs={}'.format(base_url, repo_label, pr_list)
346-
body += '\n\n[Create a similar rollup]({})'.format(link)
353+
body += '\n'
354+
body += IGNORE_BLOCK_START
355+
body += '\n[Create a similar rollup]({})\n'.format(link)
356+
body += IGNORE_BLOCK_END
347357

348358
try:
349359
pull = base_repo.create_pull(

homu/tests/test_pr_body.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from homu.main import suppress_pings
1+
from homu.main import suppress_ignore_block, suppress_pings, IGNORE_BLOCK_START, IGNORE_BLOCK_END
22

33

44
def test_suppress_pings_in_PR_body():
@@ -15,3 +15,16 @@ def test_suppress_pings_in_PR_body():
1515
)
1616

1717
assert suppress_pings(body) == expect
18+
19+
def test_suppress_ignore_block_in_PR_body():
20+
body = ("Rollup merge\n"
21+
"{}\n"
22+
"[Create a similar rollup](https://fake.xyz/?prs=1,2,3)\n"
23+
"{}"
24+
)
25+
26+
body = body.format(IGNORE_BLOCK_START, IGNORE_BLOCK_END)
27+
28+
expect = "Rollup merge\n"
29+
30+
assert suppress_ignore_block(body) == expect

0 commit comments

Comments
 (0)