Skip to content

Commit d9251e0

Browse files
committed
Pushed commits reset the try_ state
1 parent f0c2aec commit d9251e0

File tree

4 files changed

+76
-8
lines changed

4 files changed

+76
-8
lines changed

homu/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,14 +1182,18 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
11821182
# status = info.state
11831183
# break
11841184

1185-
if pull.number in [60966, 60730, 60547, 59312]:
1186-
# TODO: WHY DOES THIS HAPPEN!?
1187-
print("Skipping {} because GraphQL never returns a success!".format(pull.number))
1188-
continue
1185+
# if pull.number in [60966, 60730, 60547, 59312]:
1186+
# # TODO: WHY DOES THIS HAPPEN!?
1187+
# # Reported to GitHub. They're working on it.
1188+
# print("Skipping {} because GraphQL never returns a success!".format(pull.number))
1189+
# continue
11891190

11901191
print("{}/{}#{}".format(repo_cfg['owner'], repo_cfg['name'], pull.number))
11911192
access_token = global_cfg['github']['access_token']
1192-
response = all_pull_request_events(access_token, repo_cfg['owner'], repo_cfg['name'], pull.number)
1193+
try:
1194+
response = all_pull_request_events(access_token, repo_cfg['owner'], repo_cfg['name'], pull.number)
1195+
except:
1196+
continue
11931197
status = ''
11941198

11951199
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) # noqa

homu/pull_req_state.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ def process_event(self, event):
351351
# New commits come in: no longer approved
352352
result.changed = result.changed or self.approved_by != ''
353353
self.approved_by = ''
354+
result.changed = result.changed or self.try_ != False
355+
self.try_ = False
356+
# TODO: Do we *always* reset the state?
357+
result.changed = result.changed or self.status != ''
358+
self.status = ''
354359

355360
elif event.event_type == 'HeadRefForcePushedEvent':
356361
result.changed = self.head_sha != event['afterCommit']['oid']
@@ -412,6 +417,7 @@ def process_event(self, event):
412417

413418
elif event.event_type in [
414419
'SubscribedEvent',
420+
'UnsubscribedEvent',
415421
'MentionedEvent',
416422
'LabeledEvent',
417423
'UnlabeledEvent',

homu/pull_request_events.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def all(access_token, owner, repo, pull):
231231
result.repo = repo
232232
result.pull = pull
233233

234+
attempt = 1
235+
234236
while True:
235237
response = one(access_token=access_token,
236238
owner=owner,
@@ -245,6 +247,9 @@ def all(access_token, owner, repo, pull):
245247
r = response.json()
246248

247249
if 'errors' in r:
250+
if attempt == 10:
251+
raise Exception("Too many errors")
252+
attempt += 1
248253
print("GraphQL query failed:")
249254
for error in r['errors']:
250255
print(" * {}".format(error['message']))

homu/tests/test_process_event.py

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,59 @@ def test_try_failed(_):
363363
assert state.get_status() == 'failure'
364364

365365

366+
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
367+
side_effect=return_true)
368+
def test_try_reset_by_push(_):
369+
"""
370+
Test that a pull request that has been tried, and new commits pushed, does
371+
not show up as tried
372+
"""
373+
374+
state = new_state()
375+
result = state.process_event(create_event({
376+
'eventType': 'IssueComment',
377+
'author': {
378+
'login': 'bors',
379+
},
380+
'body': '''
381+
:hourglass: Trying commit 065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe with merge 330c85d9270b32d7703ebefc337eb37ae959f741...
382+
<!-- homu: {"type":"TryBuildStarted","head_sha":"065151f8b2c31d9e4ddd34aaf8d3263a997f5cfe","merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
383+
''', # noqa
384+
'publishedAt': '1985-04-21T00:00:00Z',
385+
}))
386+
387+
assert result.changed is True
388+
assert state.try_ is True
389+
assert state.get_status() == 'pending'
390+
391+
result = state.process_event(create_event({
392+
'eventType': 'IssueComment',
393+
'author': {
394+
'login': 'bors',
395+
},
396+
'body': '''
397+
:sunny: Try build successful - [checks-travis](https://travis-ci.com/rust-lang/rust/builds/115542062) Build commit: 330c85d9270b32d7703ebefc337eb37ae959f741
398+
<!-- homu: {"type":"TryBuildCompleted","builders":{"checks-travis":"https://travis-ci.com/rust-lang/rust/builds/115542062"},"merge_sha":"330c85d9270b32d7703ebefc337eb37ae959f741"} -->
399+
''', # noqa
400+
'publishedAt': '1985-04-21T00:01:00Z',
401+
}))
402+
403+
assert result.changed is True
404+
assert state.try_ is True
405+
assert state.get_status() == 'success'
406+
407+
result = state.process_event(create_event({
408+
'eventType': 'PullRequestCommit',
409+
'commit': {
410+
'oid': '012345',
411+
}
412+
}))
413+
414+
assert result.changed is True
415+
assert state.try_ is False
416+
assert state.get_status() == ''
417+
418+
366419
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
367420
side_effect=return_true)
368421
def test_build(_):
@@ -403,7 +456,7 @@ def test_build(_):
403456

404457
assert result.changed is True
405458
assert state.try_ is False
406-
assert state.get_status() == 'success'
459+
assert state.get_status() == 'completed'
407460

408461

409462
@unittest.mock.patch('homu.pull_req_state.assert_authorized',
@@ -427,7 +480,7 @@ def test_build_failed(_):
427480
}))
428481

429482
assert result.changed is True
430-
assert state.try_ is True
483+
assert state.try_ is False
431484
assert state.get_status() == 'pending'
432485

433486
result = state.process_event(create_event({
@@ -443,7 +496,7 @@ def test_build_failed(_):
443496
}))
444497

445498
assert result.changed is True
446-
assert state.try_ is True
499+
assert state.try_ is False
447500
assert state.get_status() == 'failure'
448501

449502

0 commit comments

Comments
 (0)