# Path: neckbeard/actions/utils.py
# def get_deployer():
#     return os.environ.get(
#         'POLICYSTAT_DEPLOYER_NAME',
#         os.environ.get('USER', 'unknown'),
#     )
# 
# def _get_gen_target():
#     generation_target = ''
#     if hasattr(env, '_active_gen'):
#         if env._active_gen:
#             generation_target = 'ACTIVE'
#         else:
#             if getattr(env, '_old_gen', False):
#                 generation_target = 'OLD'
#             else:
#                 generation_target = 'PENDING'
#     else:
#         logger.critical("Must run active, pending or old before this task")
#         exit(1)
# 
#     return generation_target


import httplib
import urllib
import json
import logging
import requests
    import git
    import pynotify
from datetime import datetime, timedelta
from fabric.api import env, local, sudo
from decorator import contextmanager
from requests.exceptions import RequestException
from neckbeard.actions.utils import get_deployer, _get_gen_target


## Helpers for announcing deployment for New Relic

def _announce_deployment():
    newrelic_conf = env._deployment_confs['conf'].get('newrelic', {})
    if newrelic_conf.get('announce_deploy', False):
        _send_deployment_end_newrelic()


def _send_deployment_end_newrelic():
    '''
    API: https://rpm.newrelic.com/accounts/87516/applications/402046/deployments/instructions  # noqa
    '''
    GIT_MOST_RECENT_TWO_TAGS = 'git tag | tail -2'
    GIT_MOST_RECENT_COMMIT_MESSAGE = 'git log -1 --format="%s"'
    GIT_CURRENT_TAG = 'git describe --tags'
    GITHUB_COMPARE_OPERATOR = '...'
    NEWRELIC_API_HTTP_METHOD = 'POST'

    def generate_github_changelog_url(tags):
        return GITHUB_COMPARE_URL % GITHUB_COMPARE_OPERATOR.join(tags)

    if env.get('newrelic_api_token', False):
        logger.info('Announcing deployment to newrelic')
        headers = {
            'x-api-key': env.newrelic_api_token,
        }

        # Description is the generation target, e.g. active, pending

# Path: neckbeard/actions/utils.py
# def get_deployer():
#     return os.environ.get(
#         'POLICYSTAT_DEPLOYER_NAME',
#         os.environ.get('USER', 'unknown'),
#     )
# 
# def _get_gen_target():
#     generation_target = ''
#     if hasattr(env, '_active_gen'):
#         if env._active_gen:
#             generation_target = 'ACTIVE'
#         else:
#             if getattr(env, '_old_gen', False):
#                 generation_target = 'OLD'
#             else:
#                 generation_target = 'PENDING'
#     else:
#         logger.critical("Must run active, pending or old before this task")
#         exit(1)
# 
#     return generation_target


# Path: neckbeard/actions/contrib_hooks.py
import httplib
import urllib
import json
import logging
import requests
    import git
    import pynotify
from datetime import datetime, timedelta
from fabric.api import env, local, sudo
from decorator import contextmanager
from requests.exceptions import RequestException
from neckbeard.actions.utils import get_deployer, _get_gen_target



## Helpers for announcing deployment for New Relic

def _announce_deployment():
    newrelic_conf = env._deployment_confs['conf'].get('newrelic', {})
    if newrelic_conf.get('announce_deploy', False):
        _send_deployment_end_newrelic()


def _send_deployment_end_newrelic():
    '''
    API: https://rpm.newrelic.com/accounts/87516/applications/402046/deployments/instructions  # noqa
    '''
    GIT_MOST_RECENT_TWO_TAGS = 'git tag | tail -2'
    GIT_MOST_RECENT_COMMIT_MESSAGE = 'git log -1 --format="%s"'
    GIT_CURRENT_TAG = 'git describe --tags'
    GITHUB_COMPARE_OPERATOR = '...'
    NEWRELIC_API_HTTP_METHOD = 'POST'

    def generate_github_changelog_url(tags):
        return GITHUB_COMPARE_URL % GITHUB_COMPARE_OPERATOR.join(tags)

    if env.get('newrelic_api_token', False):
        logger.info('Announcing deployment to newrelic')
        headers = {
            'x-api-key': env.newrelic_api_token,
        }

        # Description is the generation target, e.g. active, pending

        description = '%s ' % (_get_gen_target().lower(),)