Skip to content

Commit f0c2aec

Browse files
committed
Test builds and try builds
1 parent 3db73f2 commit f0c2aec

File tree

2 files changed

+266
-36
lines changed

2 files changed

+266
-36
lines changed

homu/pull_req_state.py

Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,8 @@ def process_event(self, event):
426426
'DemilestonedEvent',
427427
'ReviewRequestedEvent',
428428
'ReviewDismissedEvent',
429-
'CommentDeletedEvent']:
429+
'CommentDeletedEvent',
430+
'PullRequestCommitCommentThread']:
430431
# TODO! Review these events to see if we care about any of them.
431432
# These events were seen as "Unknown event type: {}" when doing initial testing.
432433
pass
@@ -750,6 +751,12 @@ def process_issue_comment(self, event, command):
750751
# args=[state, hook_cfg, body, command.hook_extra]
751752
# ).start()
752753

754+
elif command.action == 'homu-state' and username == botname:
755+
subresult = self.process_homu_state(event, command)
756+
result.comments.extend(subresult.comments)
757+
result.label_events.extend(subresult.label_events)
758+
result.changed = subresult.changed
759+
753760
else:
754761
found = False
755762

@@ -766,51 +773,71 @@ def process_homu_state(self, event, command):
766773
result = ProcessEventResult()
767774
state = command.homu_state
768775

776+
769777
if state['type'] == 'Approved':
770-
# TODO: Something with states
771-
result.changed = self.approval_state != 'approved'
772-
result.changed = result.changed or self.approver != state['approver']
773-
self.approval_state = 'approved'
778+
result.changed = self.approved_by != state['approver']
774779
self.approved_by = state['approver']
775780

776781
elif state['type'] == 'BuildStarted':
777-
# TODO: Something with states
778782
result.changed = True
779-
self.build_state = 'pending'
783+
self.try_ = False
784+
self.status = 'pending'
785+
# TODO: Something with states
786+
# result.changed = True
787+
# self.build_state = 'pending'
788+
pass
780789

781790
elif state['type'] == 'BuildCompleted':
782-
# TODO: Something with states
783791
result.changed = True
784-
self.build_state = 'completed'
792+
self.try_ = False
793+
self.status = 'completed'
794+
# TODO: Something with states
795+
# result.changed = True
796+
# self.build_state = 'completed'
797+
pass
785798

786799
elif state['type'] == 'BuildFailed':
787-
# TODO: Something with states
788800
result.changed = True
789-
self.build_state = 'failure'
801+
self.try_ = False
802+
self.status = 'failure'
803+
# TODO: Something with states
804+
# result.changed = True
805+
# self.build_state = 'failure'
806+
pass
790807

791808
elif state['type'] == 'TryBuildStarted':
792-
# TODO: Multiple tries?
793809
result.changed = True
794-
self.tries.append(PullRequestTry(
795-
len(self.tries) + 1,
796-
state['head_sha'],
797-
state['merge_sha'],
798-
event['publishedAt'])
799-
)
810+
self.try_ = True
811+
self.status = 'pending'
812+
# TODO: Multiple tries?
813+
# result.changed = True
814+
# self.tries.append(PullRequestTry(
815+
# len(self.tries) + 1,
816+
# state['head_sha'],
817+
# state['merge_sha'],
818+
# event['publishedAt'])
819+
# )
800820

801821
elif state['type'] == 'TryBuildCompleted':
802-
item = next((try_
803-
for try_ in self.tries
804-
if try_.state == 'pending'
805-
and try_.merge_sha == state['merge_sha']),
806-
None)
807-
808-
if item:
809-
result.changed = True
810-
# TODO: Multiple tries?
811-
item.ended_at = event['publishedAt']
812-
item.state = 'completed'
813-
item.builders = state['builders']
822+
result.changed = True
823+
self.status = 'success'
824+
# TODO: Multiple tries?
825+
# item = next((try_
826+
# for try_ in self.tries
827+
# if try_.state == 'pending'
828+
# and try_.merge_sha == state['merge_sha']),
829+
# None)
830+
#
831+
# if item:
832+
# result.changed = True
833+
# # TODO: Multiple tries?
834+
# item.ended_at = event['publishedAt']
835+
# item.state = 'completed'
836+
# item.builders = state['builders']
837+
838+
elif state['type'] == 'TryBuildFailed':
839+
result.changed = True
840+
self.status = 'failure'
814841

815842
return result
816843

homu/tests/test_process_event.py

Lines changed: 209 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,215 @@ def test_approved(_):
238238
assert state.get_status() == 'approved'
239239

240240

241-
#def test_tried():
242-
# """
243-
# Test that a pull request that has been tried shows up as tried
244-
# """
245-
#
246-
#
241+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
242+
side_effect=return_true)
243+
def test_homu_state_approval(_):
244+
state = new_state(head_sha='abcdef')
245+
event = create_event({
246+
'eventType': 'IssueComment',
247+
'author': {
248+
'login': 'bors',
249+
},
250+
'body': '''
251+
Commit abcdef has been approved
252+
253+
<!-- homu: {"type":"Approved","sha":"012345","approver":"ferris"} -->
254+
''', # noqa
255+
'publishedAt': '1985-04-21T00:00:00Z',
256+
})
257+
result = state.process_event(event)
258+
assert result.changed is True
259+
assert len(result.comments) == 0
260+
assert state.get_status() == 'approved'
261+
assert state.approved_by == 'ferris'
262+
263+
# Nobody but bors can use homu state
264+
state = new_state(head_sha='abcdef')
265+
event = create_event({
266+
'eventType': 'IssueComment',
267+
'author': {
268+
'login': 'ferris',
269+
},
270+
'body': '''
271+
Commit abcdef has been approved
272+
273+
<!-- homu: {"type":"Approved","sha":"012345","approver":"ferris"} -->
274+
''', # noqa
275+
'publishedAt': '1985-04-21T00:00:00Z',
276+
})
277+
result = state.process_event(event)
278+
assert result.changed is False
279+
assert len(result.comments) == 0
280+
assert state.get_status() == ''
281+
assert state.approved_by == ''
282+
283+
284+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
285+
side_effect=return_true)
286+
def test_tried(_):
287+
"""
288+
Test that a pull request that has been tried shows up as tried
289+
"""
290+
291+
state = new_state()
292+
result = state.process_event(create_event({
293+
'eventType': 'IssueComment',
294+
'author': {
295+
'login': 'bors',
296+
},
297+
'body': '''
298+
:hourglass: Trying commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
299+
<!-- homu: {"type":"TryBuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
300+
''', # noqa
301+
'publishedAt': '1985-04-21T00:00:00Z',
302+
}))
303+
304+
assert result.changed is True
305+
assert state.try_ is True
306+
assert state.get_status() == 'pending'
307+
308+
result = state.process_event(create_event({
309+
'eventType': 'IssueComment',
310+
'author': {
311+
'login': 'bors',
312+
},
313+
'body': '''
314+
:sunny: Try build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
315+
<!-- homu: {"type":"TryBuildCompleted","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
316+
''', # noqa
317+
'publishedAt': '1985-04-21T00:01:00Z',
318+
}))
319+
320+
assert result.changed is True
321+
assert state.try_ is True
322+
assert state.get_status() == 'success'
323+
324+
325+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
326+
side_effect=return_true)
327+
def test_try_failed(_):
328+
"""
329+
Test that a pull request that has been tried shows up as tried
330+
"""
331+
332+
state = new_state()
333+
result = state.process_event(create_event({
334+
'eventType': 'IssueComment',
335+
'author': {
336+
'login': 'bors',
337+
},
338+
'body': '''
339+
:hourglass: Trying commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
340+
<!-- homu: {"type":"TryBuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
341+
''', # noqa
342+
'publishedAt': '1985-04-21T00:00:00Z',
343+
}))
344+
345+
assert result.changed is True
346+
assert state.try_ is True
347+
assert state.get_status() == 'pending'
348+
349+
result = state.process_event(create_event({
350+
'eventType': 'IssueComment',
351+
'author': {
352+
'login': 'bors',
353+
},
354+
'body': '''
355+
:sunny: Try build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
356+
<!-- homu: {"type":"TryBuildFailed","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
357+
''', # noqa
358+
'publishedAt': '1985-04-21T00:01:00Z',
359+
}))
360+
361+
assert result.changed is True
362+
assert state.try_ is True
363+
assert state.get_status() == 'failure'
364+
365+
366+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
367+
side_effect=return_true)
368+
def test_build(_):
369+
"""
370+
Test that a pull request that has been built shows up as built. This is
371+
maybe a bad test because a PR that has been built and succeeds will likely
372+
be merged and removed.
373+
"""
374+
375+
state = new_state()
376+
result = state.process_event(create_event({
377+
'eventType': 'IssueComment',
378+
'author': {
379+
'login': 'bors',
380+
},
381+
'body': '''
382+
:hourglass: Building commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
383+
<!-- homu: {"type":"BuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
384+
''', # noqa
385+
'publishedAt': '1985-04-21T00:00:00Z',
386+
}))
387+
388+
assert result.changed is True
389+
assert state.try_ is False
390+
assert state.get_status() == 'pending'
391+
392+
result = state.process_event(create_event({
393+
'eventType': 'IssueComment',
394+
'author': {
395+
'login': 'bors',
396+
},
397+
'body': '''
398+
:sunny: Build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
399+
<!-- homu: {"type":"BuildCompleted","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
400+
''', # noqa
401+
'publishedAt': '1985-04-21T00:01:00Z',
402+
}))
403+
404+
assert result.changed is True
405+
assert state.try_ is False
406+
assert state.get_status() == 'success'
407+
408+
409+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
410+
side_effect=return_true)
411+
def test_build_failed(_):
412+
"""
413+
Test that a pull request that has been built and failed shows up that way.
414+
"""
415+
416+
state = new_state()
417+
result = state.process_event(create_event({
418+
'eventType': 'IssueComment',
419+
'author': {
420+
'login': 'bors',
421+
},
422+
'body': '''
423+
:hourglass: Building commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
424+
<!-- homu: {"type":"BuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
425+
''', # noqa
426+
'publishedAt': '1985-04-21T00:00:00Z',
427+
}))
428+
429+
assert result.changed is True
430+
assert state.try_ is True
431+
assert state.get_status() == 'pending'
432+
433+
result = state.process_event(create_event({
434+
'eventType': 'IssueComment',
435+
'author': {
436+
'login': 'bors',
437+
},
438+
'body': '''
439+
:sunny: Build failed - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
440+
<!-- homu: {"type":"BuildFailed","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
441+
''', # noqa
442+
'publishedAt': '1985-04-21T00:01:00Z',
443+
}))
444+
445+
assert result.changed is True
446+
assert state.try_ is True
447+
assert state.get_status() == 'failure'
448+
449+
247450
#def test_tried_and_approved():
248451
# """
249452
# Test that a pull request that has been approved AND tried shows up as

0 commit comments

Comments
 (0)