Skip to content

Commit 530cf1f

Browse files
authored
Merge pull request #112 from oliviacrain/rollup-link
Add a "create a similar rollup" link in rollup PR body
2 parents 882e5b1 + 6ff2d7f commit 530cf1f

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

cfg.production.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ${HOMU_SSH_KEY}
1818
host = '0.0.0.0'
1919
port = 80
2020

21+
base_url = "https://bors.rust-lang.org"
2122
canonical_url = "https://bors.rust-lang.org"
2223
remove_path_prefixes = ["homu"]
2324

cfg.sample.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ port = 54856
5151
# all open PRs.
5252
sync_on_start = true
5353

54+
# The base url used for links pointing to this homu instance.
55+
# If base_url is not present, links will use canonical_url as a fallback.
56+
# If neither base_url nor canonical_url are present, no links to this homu
57+
# instance will be generated.
58+
#base_url = "https://bors.example.com"
59+
5460
# The canonical URL of this homu instance. If a user reaches the instance
5561
# through a different path they will be redirected. If this is not present in
5662
# the configuration homu will still work, but no redirect will be performed.

homu/html/queue.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,14 @@ <h1>Homu queue - {% if repo_url %}<a href="{{repo_url}}" target="_blank">{{repo_
187187

188188
<tbody>
189189
{% for state in states %}
190+
{% set checkbox_state =
191+
('checked' if state.prechecked else '') if
192+
((state.status == 'approved' or (state.status == 'pending' and not state.try_)) and state.rollup != 'never')
193+
else 'disabled'
194+
%}
190195
<tr class="{{state.greyed}}">
191196
<td class="hide">{{loop.index}}</td>
192-
<td><input type="checkbox" data-num="{{state.num}}" {{ '' if ((state.status == 'approved' or (state.status == 'pending' and not state.try_)) and state.rollup != 'never') else 'disabled' }}></td>
197+
<td><input type="checkbox" data-num="{{state.num}}" {{checkbox_state}}></td>
193198
{% if multiple %}
194199
<td><a href="{{state.repo_url}}">{{state.repo_label}}</a></td>
195200
{% endif %}

homu/main.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
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(
47+
r'<!--\s*homu-ignore:start\s*-->'
48+
r'.*'
49+
r'<!--\s*homu-ignore:end\s*-->',
50+
flags=re.MULTILINE | re.DOTALL | re.IGNORECASE
51+
)
52+
4453
global_cfg = {}
4554

4655

@@ -50,6 +59,12 @@ def suppress_pings(text):
5059
return re.sub(r'\B(@\S+)', r'`\g<1>`', text) # noqa
5160

5261

62+
# Replace any text between IGNORE_BLOCK_START and IGNORE_BLOCK_END
63+
# HTML comments with an empty string in merge commits
64+
def suppress_ignore_block(text):
65+
return IGNORE_BLOCK_RE.sub('', text)
66+
67+
5368
@contextmanager
5469
def buildbot_sess(repo_cfg):
5570
sess = requests.Session()
@@ -356,6 +371,7 @@ def refresh(self):
356371

357372
self.title = issue.title
358373
self.body = suppress_pings(issue.body)
374+
self.body = suppress_ignore_block(self.body)
359375

360376
def fake_merge(self, repo_cfg):
361377
if not repo_cfg.get('linear', False):
@@ -1554,6 +1570,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
15541570
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
15551571
state.title = pull.title
15561572
state.body = suppress_pings(pull.body)
1573+
state.body = suppress_ignore_block(state.body)
15571574
state.head_ref = pull.head.repo[0] + ':' + pull.head.ref
15581575
state.base_ref = pull.base.ref
15591576
state.set_mergeable(None)

homu/server.py

Lines changed: 26 additions & 0 deletions
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
)
@@ -139,6 +143,10 @@ def queue(repo_label):
139143
except KeyError:
140144
abort(404, 'No such repository: {}'.format(label))
141145

146+
prechecked_prs = set()
147+
if request.query.get('prs'):
148+
prechecked_prs = set(request.query.get('prs').split(','))
149+
142150
pull_states = sorted(states)
143151
rows = []
144152
for state in pull_states:
@@ -154,6 +162,7 @@ def queue(repo_label):
154162
'status_ext': status_ext,
155163
'priority': state.priority,
156164
'rollup': ROLLUP_STR.get(state.rollup, ''),
165+
'prechecked': str(state.num) in prechecked_prs,
157166
'url': 'https://github.com/{}/{}/pull/{}'.format(state.owner,
158167
state.name,
159168
state.num),
@@ -303,6 +312,9 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
303312
failures.append(state.num)
304313
continue
305314

315+
state.body = suppress_pings(state.body)
316+
state.body = suppress_ignore_block(state.body)
317+
306318
merge_msg = 'Rollup merge of #{} - {}, r={}\n\n{}\n\n{}'.format(
307319
state.num,
308320
state.head_ref,
@@ -331,6 +343,20 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
331343
body += ' - #{} ({})\n'.format(x.num, x.title)
332344
body += '\nr? @ghost'
333345

346+
# Set web.base_url in cfg to enable
347+
base_url = g.cfg['web'].get('base_url')
348+
if not base_url:
349+
# If web.base_url is not present, fall back to using web.canonical_url
350+
base_url = g.cfg['web'].get('canonical_url')
351+
352+
if base_url:
353+
pr_list = ','.join(str(x.num) for x in successes)
354+
link = '{}/queue/{}?prs={}'.format(base_url, repo_label, pr_list)
355+
body += '\n'
356+
body += IGNORE_BLOCK_START
357+
body += '\n[Create a similar rollup]({})\n'.format(link)
358+
body += IGNORE_BLOCK_END
359+
334360
try:
335361
pull = base_repo.create_pull(
336362
title,

homu/tests/test_pr_body.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from homu.main import suppress_pings
1+
from homu.main import (
2+
suppress_ignore_block,
3+
suppress_pings,
4+
IGNORE_BLOCK_START,
5+
IGNORE_BLOCK_END,
6+
)
27

38

49
def test_suppress_pings_in_PR_body():
@@ -15,3 +20,18 @@ def test_suppress_pings_in_PR_body():
1520
)
1621

1722
assert suppress_pings(body) == expect
23+
24+
25+
def test_suppress_ignore_block_in_PR_body():
26+
body = (
27+
"Rollup merge\n"
28+
"{}\n"
29+
"[Create a similar rollup](https://fake.xyz/?prs=1,2,3)\n"
30+
"{}"
31+
)
32+
33+
body = body.format(IGNORE_BLOCK_START, IGNORE_BLOCK_END)
34+
35+
expect = "Rollup merge\n"
36+
37+
assert suppress_ignore_block(body) == expect

0 commit comments

Comments
 (0)