Skip to content

Commit a9234c7

Browse files
committed
Test that @bors retry resets the state
Test that issuing a `@bors retry` command moves the state from 'pending' to '' for pending pull requests. This is frequently used as a way to yield the current build to a different pull request.
1 parent a024fbe commit a9234c7

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

homu/pull_req_state.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -675,18 +675,21 @@ def process_issue_comment(self, event, command):
675675
# delegate=state.delegate
676676
# ))
677677
#
678-
# elif command.action == 'retry' and realtime:
679-
# _assert_try_auth_verified()
680-
#
681-
# state.set_status('')
682-
# if realtime:
683-
# if state.try_:
684-
# event = LabelEvent.TRY
685-
# else:
686-
# event = LabelEvent.APPROVED
687-
# state.record_retry_log(command_src, body, global_cfg)
688-
# state.change_labels(event)
689-
#
678+
elif command.action == 'retry':
679+
_assert_try_auth_verified()
680+
681+
self.status = ''
682+
if self.try_:
683+
event = LabelEvent.TRY
684+
self.try_state = BuildState.NONE
685+
else:
686+
event = LabelEvent.APPROVED
687+
self.build_state = BuildState.NONE
688+
# TODO: re-enable the retry log!
689+
#self.record_retry_log(command_src, body, global_cfg)
690+
result.label_events.append(event)
691+
result.changed = True
692+
690693
# elif command.action in ['try', 'untry'] and realtime:
691694
# _assert_try_auth_verified()
692695
#

homu/tests/test_process_event.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,52 @@ def test_build_failed(_):
540540
assert state.try_state == BuildState.NONE
541541

542542

543+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
544+
side_effect=return_true)
545+
def test_build_retry_cancels(_):
546+
"""
547+
Test that a pull request that has started a build and then gets a 'retry'
548+
command cancels the build.
549+
"""
550+
551+
state = new_state()
552+
result = state.process_event(create_event({
553+
'eventType': 'IssueComment',
554+
'author': {
555+
'login': 'bors',
556+
},
557+
'body': '''
558+
:hourglass: Building commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
559+
<!-- homu: {"type":"BuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
560+
''', # noqa
561+
'publishedAt': '1985-04-21T00:00:00Z',
562+
}))
563+
564+
assert result.changed is True
565+
assert state.try_ is False
566+
assert state.get_status() == 'pending'
567+
assert state.build_state == BuildState.PENDING
568+
assert state.try_state == BuildState.NONE
569+
570+
result = state.process_event(create_event({
571+
'eventType': 'IssueComment',
572+
'author': {
573+
'login': 'ferris',
574+
},
575+
'body': '''
576+
@bors retry
577+
''',
578+
'publishedAt': '1985-04-21T00:01:00Z',
579+
}))
580+
581+
assert result.changed is True
582+
assert state.try_ is False
583+
assert state.get_status() == ''
584+
assert state.build_state == BuildState.NONE
585+
assert state.try_state == BuildState.NONE
586+
# TODO: does issuing this retry emit label events?
587+
588+
543589
#def test_tried_and_approved():
544590
# """
545591
# Test that a pull request that has been approved AND tried shows up as

0 commit comments

Comments
 (0)