Skip to content

Commit 748832f

Browse files
committed
message formatter
1 parent ea1b7c8 commit 748832f

File tree

4 files changed

+55
-32
lines changed

4 files changed

+55
-32
lines changed

.github/workflows/comment_bot.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ jobs:
4444
- run: |
4545
pip install -e arrow/dev/archery
4646
- name: Handle GH event
47+
env:
48+
ARROW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
CROSSBOW_GITHUB_TOKEN: ${{ secrets.CROSSBOW_GITHUB_TOKEN }}
4750
run: |
4851
archery trigger-bot \
4952
--event-name ${{ github.event_name }} \
50-
--event-payload ${{ github.event_path }} \
51-
--arrow-token ${{ secrets.GITHUB_TOKEN }}
53+
--event-payload ${{ github.event_path }}
5254
5355

dev/archery/archery/bot.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ def __init__(self, crossbow_repo):
130130

131131
def render(self, job):
132132
url = 'https://github.com/{repo}/branches/all?query={branch}'
133-
msg = f'Submitted crossbow builds: [{{repo}} @ {{branch}}]({url})\n'
133+
sha = job['target']['head']
134+
135+
msg = f'Revision: {sha}\n\n'
136+
msg += f'Submitted crossbow builds: [{{repo}} @ {{branch}}]({url})\n'
134137
msg += '\n|Task|Status|\n|----|------|'
135138

136139
tasks = sorted(job['tasks'].items(), key=operator.itemgetter(0))
@@ -233,15 +236,12 @@ def ursabot(ctx):
233236

234237

235238
@ursabot.group()
236-
@click.option('--arrow', '-a', default='apache/arrow',
237-
help='Arrow repository on github to use')
238239
@click.option('--crossbow', '-c', default='ursa-labs/crossbow',
239240
help='Crossbow repository on github to use')
240241
@click.pass_obj
241-
def crossbow(obj, arrow, crossbow):
242+
def crossbow(obj, crossbow):
242243
"""Trigger crossbow builds for this pull request"""
243-
# obj['arrow_repo'] = 'https://github.com/{}'.format(arrow)
244-
obj['crossbow_repo'] = 'https://github.com/{}'.format(crossbow)
244+
obj['crossbow_repo'] = crossbow
245245

246246

247247
@crossbow.command()
@@ -256,19 +256,19 @@ def submit(obj, task, group, dry_run):
256256
257257
See groups defined in arrow/dev/tasks/tests.yml
258258
"""
259-
args = ['--output-file', 'result.yaml']
259+
args = []
260260
for g in group:
261261
args.extend(['-g', g])
262262
for t in task:
263263
args.append(t)
264264

265265
# clone crossbow
266266
git = Git()
267-
git.clone(obj['crossbow_repo'], 'crossbow')
267+
git.clone('https://github.com/{}'.format(obj['crossbow_repo']), 'crossbow')
268268

269269
# submit the crossbow tasks
270270
xbow = Crossbow('arrow/dev/tasks/crossbow.py')
271-
xbow.run('submit', *args)
271+
xbow.run('--output-file', 'result.yaml', 'submit', *args)
272272

273273
# parse the result yml describing the submitted job
274274
yaml = YAML()
@@ -280,6 +280,4 @@ def submit(obj, task, group, dry_run):
280280
response = formatter.render(job)
281281

282282
# send the response
283-
obj['pull'].create_issue_comment(response)
284-
285-
283+
obj['pull'].create_issue_comment(response)

dev/archery/archery/tests/fixtures/crossbow-success-message.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
[Builder1 (#{build_id})]({build_url}) builder {status}
2-
31
Revision: {revision}
42

53
Submitted crossbow builds: [{repo} @ {branch}](https://github.com/{repo}/branches/all?query={branch})

dev/archery/archery/tests/test_bot.py

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
from unittest.mock import Mock
44

55
import pytest
6+
import textwrap
67
import responses as rsps
78
import click
89
from click.testing import CliRunner
10+
from ruamel.yaml import YAML
911

10-
from archery.bot import CommentBot, CommandError, group
12+
from archery.bot import (
13+
CommentBot, CommandError, CrossbowCommentFormatter, group
14+
)
1115

1216

1317
@pytest.fixture
@@ -17,9 +21,15 @@ def responses():
1721

1822

1923
def load_fixture(name):
20-
path = Path(__file__).parent / 'fixtures' / '{}.json'.format(name)
24+
path = Path(__file__).parent / 'fixtures' / name
2125
with path.open('r') as fp:
22-
return json.load(fp)
26+
if name.endswith('.json'):
27+
return json.load(fp)
28+
elif name.endswith('.yaml'):
29+
yaml = YAML()
30+
return yaml.load(fp)
31+
else:
32+
return fp.read()
2333

2434

2535
def github_url(path):
@@ -60,13 +70,28 @@ def test_click_based_commands():
6070
assert custom_handler('extra', extra='data') == {'extra': 'data'}
6171

6272

73+
def test_crossbow_comment_formatter():
74+
job = load_fixture('crossbow-job.yaml')
75+
msg = load_fixture('crossbow-success-message.md')
76+
77+
formatter = CrossbowCommentFormatter(crossbow_repo='ursa-labs/crossbow')
78+
response = formatter.render(job)
79+
expected = msg.format(
80+
repo='ursa-labs/crossbow',
81+
branch='ursabot-1',
82+
revision='f766a1d615dd1b7ee706d05102e579195951a61c',
83+
status='has been succeeded.'
84+
)
85+
assert response == textwrap.dedent(expected).strip()
86+
87+
6388
@pytest.mark.parametrize('fixture_name', [
6489
# the bot is not mentiond, nothing to do
65-
'event-issue-comment-not-mentioning-ursabot',
90+
'event-issue-comment-not-mentioning-ursabot.json',
6691
# don't respond to itself, it prevents recursive comment storms!
67-
'event-issue-comment-by-ursabot',
92+
'event-issue-comment-by-ursabot.json',
6893
# non-authorized user sent the comment, do not respond
69-
'event-issue-comment-by-non-authorized-user',
94+
'event-issue-comment-by-non-authorized-user.json',
7095
])
7196
def test_noop_events(fixture_name):
7297
payload = load_fixture(fixture_name)
@@ -82,7 +107,7 @@ def test_issue_comment_without_pull_request(responses):
82107
responses.add(
83108
responses.GET,
84109
github_url('/repositories/169101701/issues/19'),
85-
json=load_fixture('issue-19'),
110+
json=load_fixture('issue-19.json'),
86111
status=200
87112
)
88113
responses.add(
@@ -100,7 +125,7 @@ def test_issue_comment_without_pull_request(responses):
100125
def handler(command, **kwargs):
101126
pass
102127

103-
payload = load_fixture('event-issue-comment-without-pull-request')
128+
payload = load_fixture('event-issue-comment-without-pull-request.json')
104129
bot = CommentBot(name='ursabot', token='', handler=handler)
105130
bot.handle('issue_comment', payload)
106131

@@ -114,19 +139,19 @@ def test_respond_with_usage(responses):
114139
responses.add(
115140
responses.GET,
116141
github_url('/repositories/169101701/issues/26'),
117-
json=load_fixture('issue-26'),
142+
json=load_fixture('issue-26.json'),
118143
status=200
119144
)
120145
responses.add(
121146
responses.GET,
122147
github_url('/repos/ursa-labs/ursabot/pulls/26'),
123-
json=load_fixture('pull-request-26'),
148+
json=load_fixture('pull-request-26.json'),
124149
status=200
125150
)
126151
responses.add(
127152
responses.GET,
128153
github_url('/repos/ursa-labs/ursabot/issues/comments/480243811'),
129-
json=load_fixture('issue-comment-480243811')
154+
json=load_fixture('issue-comment-480243811.json')
130155
)
131156
responses.add(
132157
responses.POST,
@@ -137,7 +162,7 @@ def test_respond_with_usage(responses):
137162
def handler(command, **kwargs):
138163
raise CommandError('test-usage')
139164

140-
payload = load_fixture('event-issue-comment-with-empty-command')
165+
payload = load_fixture('event-issue-comment-with-empty-command.json')
141166
bot = CommentBot(name='ursabot', token='', handler=handler)
142167
bot.handle('issue_comment', payload)
143168

@@ -153,19 +178,19 @@ def test_issue_comment_with_commands(responses, command, reaction):
153178
responses.add(
154179
responses.GET,
155180
github_url('/repositories/169101701/issues/26'),
156-
json=load_fixture('issue-26'),
181+
json=load_fixture('issue-26.json'),
157182
status=200
158183
)
159184
responses.add(
160185
responses.GET,
161186
github_url('/repos/ursa-labs/ursabot/pulls/26'),
162-
json=load_fixture('pull-request-26'),
187+
json=load_fixture('pull-request-26.json'),
163188
status=200
164189
)
165190
responses.add(
166191
responses.GET,
167192
github_url('/repos/ursa-labs/ursabot/issues/comments/480248726'),
168-
json=load_fixture('issue-comment-480248726')
193+
json=load_fixture('issue-comment-480248726.json')
169194
)
170195
responses.add(
171196
responses.POST,
@@ -181,7 +206,7 @@ def handler(command, **kwargs):
181206
else:
182207
raise ValueError('Only `build` command is supported.')
183208

184-
payload = load_fixture('event-issue-comment-build-command')
209+
payload = load_fixture('event-issue-comment-build-command.json')
185210
payload["comment"]["body"] = command
186211

187212
bot = CommentBot(name='ursabot', token='', handler=handler)

0 commit comments

Comments
 (0)