def main(): for repo_config in app.config["REPOSITORIES"]: for pull_request in get_pull_requests(app, repo_config): sha = pull_request['head']['sha'] repo_name = repo_config['github_repo'] status_data = get_status(app, repo_config, repo_name, sha).json if status_data: last_status = status_data[0] status = last_status.get('state') if status == 'pending': max_age = MAX_AGE_PENDING_WITHOUT_URL if last_status.get('target_url'): max_age = MAX_AGE_PENDING_WITH_URL age = convert_to_age_in_seconds(last_status) if age > max_age: # Somewhat heavy, but it'll do retry_jenkins(repo_config, pull_request) else: # Somewhat heavy, but it'll do retry_jenkins(repo_config, pull_request)
def has_status(app, repo_config, repo_name, sha): response = get_status(app, repo_config, repo_name, sha) # The GitHub commit status API returns a JSON list, so `len()` checks # whether any statuses are set for the commit. return bool(len(response.json))