3737from retrying import retry
3838import random
3939import string
40+ import time
4041
4142import bottle
4243bottle .BaseRequest .MEMFILE_MAX = 1024 * 1024 * 10
@@ -690,6 +691,13 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
690691 )
691692
692693 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 )
693701 state .add_comment (comments .BuildCompleted (
694702 approved_by = state .approved_by ,
695703 base_ref = state .base_ref ,
@@ -698,28 +706,40 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
698706 ))
699707 state .change_labels (LabelEvent .SUCCEED )
700708
701- def set_ref ():
709+ def set_ref_inner ():
702710 utils .github_set_ref (state .get_repo (), 'heads/' +
703711 state .base_ref , state .merge_sha )
704712 if state .test_on_fork is not None :
705713 utils .github_set_ref (state .get_test_on_fork_repo (),
706714 'heads/' + state .base_ref ,
707715 state .merge_sha , force = True )
708- try :
716+
717+ def set_ref ():
709718 try :
710- set_ref ()
719+ set_ref_inner ()
711720 except github3 .models .GitHubError :
712721 utils .github_create_status (
713722 state .get_repo (),
714723 state .merge_sha ,
715724 'success' , '' ,
716725 'Branch protection bypassed' ,
717726 context = 'homu' )
718- set_ref ()
727+ set_ref_inner ()
719728
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+ except github3 .models .GitHubError as e :
735+ error = e
736+ pass
737+ if error is None :
738+ break
739+ else :
740+ time .sleep (10 )
721741
722- except github3 . models . GitHubError as e :
742+ if error is not None :
723743 state .set_status ('error' )
724744 desc = ('Test was successful, but fast-forwarding failed:'
725745 ' {}' .format (e ))
0 commit comments