37
37
from retrying import retry
38
38
import random
39
39
import string
40
+ import time
40
41
41
42
import bottle
42
43
bottle .BaseRequest .MEMFILE_MAX = 1024 * 1024 * 10
@@ -690,6 +691,13 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
690
691
)
691
692
692
693
if state .approved_by and not state .try_ :
694
+ # The set_ref call below sometimes fails with 422 failed to
695
+ # fast forward. We believe this is a spurious error on GitHub's
696
+ # side, though it's not entirely clear why. We sleep for 1
697
+ # minute before trying it after setting the status to try to
698
+ # increase the likelihood it will work, and also retry the
699
+ # set_ref a few times.
700
+ time .sleep (60 )
693
701
state .add_comment (comments .BuildCompleted (
694
702
approved_by = state .approved_by ,
695
703
base_ref = state .base_ref ,
@@ -698,31 +706,44 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
698
706
))
699
707
state .change_labels (LabelEvent .SUCCEED )
700
708
701
- def set_ref ():
709
+ def set_ref_inner ():
702
710
utils .github_set_ref (state .get_repo (), 'heads/' +
703
711
state .base_ref , state .merge_sha )
704
712
if state .test_on_fork is not None :
705
713
utils .github_set_ref (state .get_test_on_fork_repo (),
706
714
'heads/' + state .base_ref ,
707
715
state .merge_sha , force = True )
708
- try :
716
+
717
+ def set_ref ():
709
718
try :
710
- set_ref ()
719
+ set_ref_inner ()
711
720
except github3 .models .GitHubError :
712
721
utils .github_create_status (
713
722
state .get_repo (),
714
723
state .merge_sha ,
715
724
'success' , '' ,
716
725
'Branch protection bypassed' ,
717
726
context = 'homu' )
718
- set_ref ()
727
+ set_ref_inner ()
719
728
720
- state .fake_merge (repo_cfg )
729
+ error = None
730
+ for i in range (0 , 5 ):
731
+ try :
732
+ set_ref ()
733
+ state .fake_merge (repo_cfg )
734
+ error = None
735
+ except github3 .models .GitHubError as e :
736
+ error = e
737
+ pass
738
+ if error is None :
739
+ break
740
+ else :
741
+ time .sleep (10 )
721
742
722
- except github3 . models . GitHubError as e :
743
+ if error is not None :
723
744
state .set_status ('error' )
724
745
desc = ('Test was successful, but fast-forwarding failed:'
725
- ' {}' .format (e ))
746
+ ' {}' .format (error ))
726
747
utils .github_create_status (state .get_repo (),
727
748
state .head_sha , 'error' , url ,
728
749
desc , context = 'homu' )
0 commit comments