def loop_until_passed(pr_url, sleep_between, session, jenkins_session, max_retries):
 retry_counts = Counter()
 for _ in infinite_sleeps(sleep_between):
  resp = session.get(pr_url)
  if (resp.status_code != 200):
   print('PR not found: {}'.format(resp.content))
   return (None, None)
  pr = resp.json()
  if (pr['state'] != u'open'):
   print('Merge request not open: {}'.format(pr['state']))
   return (None, None)
  else:
   statuses = get_statuses(pr, session)
   if (len(statuses) < MINIMUM_STATUSES):
    print("Can't merge PR yet because there aren't enough statuses reporting ({} so far)".format(len(statuses)))
   else:
    needed = filter(not_success, statuses)
    if (not needed):
     return (pr, statuses)
    print("Can't merge PR yet because these {} checks haven't succeeded:".format(len(needed)))
    maybe_retry_jobs(needed, retry_counts, max_retries, jenkins_session)
  print('Sleeping for {} seconds and trying again.\n\n'.format(sleep_between))

def loop_until_passed ( pr_url , sleep_between , session , jenkins_session , max_retries ) : retry_counts = Counter ( ) for _ in infinite_sleeps ( sleep_between ) : resp = session . get ( pr_url ) if ( resp . status_code != 200 ) : print ( 'PR not found: {}' . format ( resp . content ) ) return ( None , None ) pr = resp . json ( ) if ( pr [ 'state' ] != u'open' ) : print ( 'Merge request not open: {}' . format ( pr [ 'state' ] ) ) return ( None , None ) else : statuses = get_statuses ( pr , session ) if ( len ( statuses ) < MINIMUM_STATUSES ) : print ( "Can't merge PR yet because there aren't enough statuses reporting ({} so far)" . format ( len ( statuses ) ) ) else : needed = filter ( not_success , statuses ) if ( not needed ) : return ( pr , statuses ) print ( "Can't merge PR yet because these {} checks haven't succeeded:" . format ( len ( needed ) ) ) maybe_retry_jobs ( needed , retry_counts , max_retries , jenkins_session ) print ( 'Sleeping for {} seconds and trying again.\n\n' . format ( sleep_between ) )
loop until all the statuses for the target pull request are green .