Skip to content

Add a "create a similar rollup" link in rollup PR body #112

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

Merged
merged 6 commits into from
Nov 2, 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
1 change: 1 addition & 0 deletions cfg.production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ${HOMU_SSH_KEY}
host = '0.0.0.0'
port = 80

base_url = "https://bors.rust-lang.org"
canonical_url = "https://bors.rust-lang.org"
remove_path_prefixes = ["homu"]

Expand Down
6 changes: 6 additions & 0 deletions cfg.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ port = 54856
# all open PRs.
sync_on_start = true

# The base url used for links pointing to this homu instance.
# If base_url is not present, links will use canonical_url as a fallback.
# If neither base_url nor canonical_url are present, no links to this homu
# instance will be generated.
#base_url = "https://bors.example.com"

# The canonical URL of this homu instance. If a user reaches the instance
# through a different path they will be redirected. If this is not present in
# the configuration homu will still work, but no redirect will be performed.
Expand Down
7 changes: 6 additions & 1 deletion homu/html/queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ <h1>Homu queue - {% if repo_url %}<a href="{{repo_url}}" target="_blank">{{repo_

<tbody>
{% for state in states %}
{% set checkbox_state =
('checked' if state.prechecked else '') if
((state.status == 'approved' or (state.status == 'pending' and not state.try_)) and state.rollup != 'never')
else 'disabled'
%}
<tr class="{{state.greyed}}">
<td class="hide">{{loop.index}}</td>
<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>
<td><input type="checkbox" data-num="{{state.num}}" {{checkbox_state}}></td>
{% if multiple %}
<td><a href="{{state.repo_url}}">{{state.repo_label}}</a></td>
{% endif %}
Expand Down
17 changes: 17 additions & 0 deletions homu/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@

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

IGNORE_BLOCK_START = '<!-- homu-ignore:start -->'
IGNORE_BLOCK_END = '<!-- homu-ignore:end -->'
IGNORE_BLOCK_RE = re.compile(
r'<!--\s*homu-ignore:start\s*-->'
r'.*'
r'<!--\s*homu-ignore:end\s*-->',
flags=re.MULTILINE | re.DOTALL | re.IGNORECASE
)

global_cfg = {}


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


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


@contextmanager
def buildbot_sess(repo_cfg):
sess = requests.Session()
Expand Down Expand Up @@ -356,6 +371,7 @@ def refresh(self):

self.title = issue.title
self.body = suppress_pings(issue.body)
self.body = suppress_ignore_block(self.body)

def fake_merge(self, repo_cfg):
if not repo_cfg.get('linear', False):
Expand Down Expand Up @@ -1554,6 +1570,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 = suppress_pings(pull.body)
state.body = suppress_ignore_block(state.body)
state.head_ref = pull.head.repo[0] + ':' + pull.head.ref
state.base_ref = pull.base.ref
state.set_mergeable(None)
Expand Down
26 changes: 26 additions & 0 deletions homu/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
PullReqState,
parse_commands,
db_query,
IGNORE_BLOCK_END,
IGNORE_BLOCK_START,
INTERRUPTED_BY_HOMU_RE,
suppress_ignore_block,
suppress_pings,
synchronize,
LabelEvent,
)
Expand Down Expand Up @@ -139,6 +143,10 @@ def queue(repo_label):
except KeyError:
abort(404, 'No such repository: {}'.format(label))

prechecked_prs = set()
if request.query.get('prs'):
prechecked_prs = set(request.query.get('prs').split(','))

pull_states = sorted(states)
rows = []
for state in pull_states:
Expand All @@ -154,6 +162,7 @@ def queue(repo_label):
'status_ext': status_ext,
'priority': state.priority,
'rollup': ROLLUP_STR.get(state.rollup, ''),
'prechecked': str(state.num) in prechecked_prs,
'url': 'https://github.com/{}/{}/pull/{}'.format(state.owner,
state.name,
state.num),
Expand Down Expand Up @@ -301,6 +310,9 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
failures.append(state.num)
continue

state.body = suppress_pings(state.body)
state.body = suppress_ignore_block(state.body)

merge_msg = 'Rollup merge of #{} - {}, r={}\n\n{}\n\n{}'.format(
state.num,
state.head_ref,
Expand Down Expand Up @@ -329,6 +341,20 @@ def rollup(user_gh, state, repo_label, repo_cfg, repo):
body += ' - #{} ({})\n'.format(x.num, x.title)
body += '\nr? @ghost'

# Set web.base_url in cfg to enable
base_url = g.cfg['web'].get('base_url')
if not base_url:
# If web.base_url is not present, fall back to using web.canonical_url
base_url = g.cfg['web'].get('canonical_url')

if base_url:
pr_list = ','.join(str(x.num) for x in successes)
link = '{}/queue/{}?prs={}'.format(base_url, repo_label, pr_list)
body += '\n'
body += IGNORE_BLOCK_START
body += '\n[Create a similar rollup]({})\n'.format(link)
body += IGNORE_BLOCK_END

try:
pull = base_repo.create_pull(
title,
Expand Down
22 changes: 21 additions & 1 deletion homu/tests/test_pr_body.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from homu.main import suppress_pings
from homu.main import (
suppress_ignore_block,
suppress_pings,
IGNORE_BLOCK_START,
IGNORE_BLOCK_END,
)


def test_suppress_pings_in_PR_body():
Expand All @@ -15,3 +20,18 @@ def test_suppress_pings_in_PR_body():
)

assert suppress_pings(body) == expect


def test_suppress_ignore_block_in_PR_body():
body = (
"Rollup merge\n"
"{}\n"
"[Create a similar rollup](https://fake.xyz/?prs=1,2,3)\n"
"{}"
)

body = body.format(IGNORE_BLOCK_START, IGNORE_BLOCK_END)

expect = "Rollup merge\n"

assert suppress_ignore_block(body) == expect