# Path: cfme/utils/dockerbot/dockerbot.py
# def _dgci(d, key):
# def _name(docker_info):
#     def docker_client(self):
#     def __del__(self):
#     def process_bindings(self, bindings):
#     def wait(self):
#     def stop(self):
#     def remove(self):
#     def kill(self):
#     def __init__(self, bindings, image, dry_run=False):
#     def run(self):
#     def __init__(self, name, bindings, env, log_path, links, pytest_con, artifactor_dir,
#                  dry_run=False):
#     def run(self):
#     def __init__(self, **args):
#     def cache_files(self):
#     def get_base_branch(self, pr):
#     def get_dev_branch(self, pr=None):
#     def get_pr_metadata(self, pr=None):
#     def find_files_by_pr(self, pr=None):
#     def check_arg(self, name, default):
#     def validate_args(self):
#     def display_banner(self):
#     def process_appliance(self):
#     def create_pytest_command(self):
#     def enc_key(self):
#     def create_pytest_envvars(self):
#     def handle_pr(self):
#     def create_log_path(self):
#     def create_pytest_bindings(self):
#     def handle_watch(self):
#     def handle_output(self):
# class DockerInstance:
# class SeleniumDocker(DockerInstance):
# class PytestDocker(DockerInstance):
# class DockerBot:


import json
import logging
import traceback
import fauxfactory
import pika
import requests
from datetime import datetime
from slumber.exceptions import HttpClientError
from cfme.utils.appliance import Appliance
from cfme.utils.conf import docker as docker_conf
from cfme.utils.dockerbot import dockerbot
from cfme.utils.log import setup_logger
from cfme.utils.trackerbot import api
    """
    page = 1

    numbers = []
    while True:
        json_data = perform_request(f'pulls?per_page=100&page={page}')
        if not json_data:
            break
        for pr in json_data:
            numbers.append(pr['number'])
            if pr['state'] == 'open':
                check_pr(pr)
        page += 1

    prs = tapi.pr.get(closed=False, limit=0)['objects']
    for pr in prs:
        if pr['number'] not in numbers:
            logger.info("PR {} closed".format(pr['number']))
            tapi.pr(pr['number']).patch({'closed': True})


def run_tasks():
    """ Runs the pending tasks

    This function first checks the number of dockerbot containers which are running the
    py_test_base image running and stores this count. If the count is lower than the threshold,
    it proceeds to grab a pending task from the list and provision an appliance. The appliance
    is then configured before being handed off to Dockerbot for the running of the PR.
    """
    cont_count = 0

# Path: cfme/utils/dockerbot/dockerbot.py
# def _dgci(d, key):
# def _name(docker_info):
#     def docker_client(self):
#     def __del__(self):
#     def process_bindings(self, bindings):
#     def wait(self):
#     def stop(self):
#     def remove(self):
#     def kill(self):
#     def __init__(self, bindings, image, dry_run=False):
#     def run(self):
#     def __init__(self, name, bindings, env, log_path, links, pytest_con, artifactor_dir,
#                  dry_run=False):
#     def run(self):
#     def __init__(self, **args):
#     def cache_files(self):
#     def get_base_branch(self, pr):
#     def get_dev_branch(self, pr=None):
#     def get_pr_metadata(self, pr=None):
#     def find_files_by_pr(self, pr=None):
#     def check_arg(self, name, default):
#     def validate_args(self):
#     def display_banner(self):
#     def process_appliance(self):
#     def create_pytest_command(self):
#     def enc_key(self):
#     def create_pytest_envvars(self):
#     def handle_pr(self):
#     def create_log_path(self):
#     def create_pytest_bindings(self):
#     def handle_watch(self):
#     def handle_output(self):
# class DockerInstance:
# class SeleniumDocker(DockerInstance):
# class PytestDocker(DockerInstance):
# class DockerBot:


# Path: cfme/utils/dockerbot/check_prs.py
import json
import logging
import traceback
import fauxfactory
import pika
import requests
from datetime import datetime
from slumber.exceptions import HttpClientError
from cfme.utils.appliance import Appliance
from cfme.utils.conf import docker as docker_conf
from cfme.utils.dockerbot import dockerbot
from cfme.utils.log import setup_logger
from cfme.utils.trackerbot import api

    """
    page = 1

    numbers = []
    while True:
        json_data = perform_request(f'pulls?per_page=100&page={page}')
        if not json_data:
            break
        for pr in json_data:
            numbers.append(pr['number'])
            if pr['state'] == 'open':
                check_pr(pr)
        page += 1

    prs = tapi.pr.get(closed=False, limit=0)['objects']
    for pr in prs:
        if pr['number'] not in numbers:
            logger.info("PR {} closed".format(pr['number']))
            tapi.pr(pr['number']).patch({'closed': True})


def run_tasks():
    """ Runs the pending tasks

    This function first checks the number of dockerbot containers which are running the
    py_test_base image running and stores this count. If the count is lower than the threshold,
    it proceeds to grab a pending task from the list and provision an appliance. The appliance
    is then configured before being handed off to Dockerbot for the running of the PR.
    """
    cont_count = 0

    for container in dockerbot.dc.containers():