# Path: blackbelt/handle_github.py
# GITHUB_CLIENT_ID = "c9f51ce9cb320bf86f16"
# UA_STRING = "black-belt/%s" % VERSION
# PR_PHRASE_PREFIX = "Pull request for"
# def get_pr_info(pr_url):
# def get_pr_api_url(pr_url):
# def get_pr_details(pr_url):
# def get_branch_url(pr_details):
# def get_username():
# def get_request_headers():
# def get_json_response(url):
# def pull_request(card_url):
# def verify_merge(pr_url, headers, max_waiting_time=30, retry_time=0.1):
#     def do_request():
# def merge(pr_url):
# def check_status(pr_url=None, branch_name=None, error_on_failure=False):
# def verify_pr_state(pr_details):
# def verify_pr_required_checks(pr_details):
# def verify_branch_required_checks(branch_name):
# def verify_gh_repo(pr_gh_repo):
# def get_pr_ticket_id(description):
# def deploy(pr_url):
# def create_release(ref, payload, description, repo_info):
# def run_grunt_in_parallel(grunt_commands):
# def get_grunt_application_name(command):
# 
# Path: blackbelt/messages.py
# def post_message(message, room):
#   slack_post_message(message, room)


from subprocess import check_call, check_output
from blackbelt.handle_github import get_current_branch, run_grunt_in_parallel
from blackbelt.messages import post_message



def deploy_staging():
    branch_name = get_current_branch()

    post_message("Deploying branch %s to staging" % branch_name, "#deploy-queue")

    check_call(['grunt', 'deploy', '--app=apiary-staging', '--force', "--branch=%s" % branch_name])

def deploy_production():
    post_message("Deploying to production", "#deploy-queue")

    slug_creaction_return_code = run_grunt_in_parallel((
        ['grunt', 'create-slug'],
        ['grunt', 'create-slug', '--app=apiary-staging-pre'],
        ['grunt', 'create-slug', '--app=apiary-staging-qa'],
    ))

    if slug_creaction_return_code != 0:

# Path: blackbelt/handle_github.py
# GITHUB_CLIENT_ID = "c9f51ce9cb320bf86f16"
# UA_STRING = "black-belt/%s" % VERSION
# PR_PHRASE_PREFIX = "Pull request for"
# def get_pr_info(pr_url):
# def get_pr_api_url(pr_url):
# def get_pr_details(pr_url):
# def get_branch_url(pr_details):
# def get_username():
# def get_request_headers():
# def get_json_response(url):
# def pull_request(card_url):
# def verify_merge(pr_url, headers, max_waiting_time=30, retry_time=0.1):
#     def do_request():
# def merge(pr_url):
# def check_status(pr_url=None, branch_name=None, error_on_failure=False):
# def verify_pr_state(pr_details):
# def verify_pr_required_checks(pr_details):
# def verify_branch_required_checks(branch_name):
# def verify_gh_repo(pr_gh_repo):
# def get_pr_ticket_id(description):
# def deploy(pr_url):
# def create_release(ref, payload, description, repo_info):
# def run_grunt_in_parallel(grunt_commands):
# def get_grunt_application_name(command):
# 
# Path: blackbelt/messages.py
# def post_message(message, room):
#   slack_post_message(message, room)


# Path: blackbelt/deployment.py
from subprocess import check_call, check_output
from blackbelt.handle_github import get_current_branch, run_grunt_in_parallel
from blackbelt.messages import post_message




def deploy_staging():
    branch_name = get_current_branch()

    post_message("Deploying branch %s to staging" % branch_name, "#deploy-queue")

    check_call(['grunt', 'deploy', '--app=apiary-staging', '--force', "--branch=%s" % branch_name])

def deploy_production():
    post_message("Deploying to production", "#deploy-queue")

    slug_creaction_return_code = run_grunt_in_parallel((
        ['grunt', 'create-slug'],
        ['grunt', 'create-slug', '--app=apiary-staging-pre'],
        ['grunt', 'create-slug', '--app=apiary-staging-qa'],
    ))

    if slug_creaction_return_code != 0:

        post_message("Slug creation failed, deploy stopped.", "#deploy-queue")