Skip to content

Commit

Permalink
Merge pull request #29 from modcloth/dont-suffix-py
Browse files Browse the repository at this point in the history
Use modcloth_app_facts rather than modcloth_app_facts.py
  • Loading branch information
jszwedko committed Sep 30, 2014
2 parents 398af79 + f17fad9 commit 49a235d
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 74 deletions.
1 change: 0 additions & 1 deletion library/modcloth_app_facts

This file was deleted.

73 changes: 73 additions & 0 deletions library/modcloth_app_facts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8
import os
import subprocess
import sys
import tempfile

import requests


GITHUB_API = os.environ.get('GITHUB_API', 'https://api.github.com')


def main(sysargs=sys.argv[:]):
module = AnsibleModule(
argument_spec=dict(
github_token=dict(required=True),
repo=dict(required=True),
revision=dict(required=True),
)
)
module.exit_json(
changed=False,
ansible_facts=dict(
modcloth_app_deployer=_get_deployer(),
modcloth_app_tag_annotation=_get_tag_annotation(
module.params['repo'],
module.params['revision'],
module.params['github_token']
),
modcloth_app_hipchat_html=_get_hipchat_html(),
modcloth_app_facted=True,
)
)
return 0


def _get_hipchat_html():
return os.path.join(
tempfile.gettempdir(),
'.modcloth_app_hipchat_notification.frag.html'
)


def _get_deployer():
return subprocess.check_output(
['git', 'config', 'user.name']
).strip()


def _get_tag_annotation(repo, revision, github_token, api=GITHUB_API):
url = '{api}/repos/{repo}/git/refs/tags/{revision}'.format(
api=api, repo=repo, revision=revision
)
response_json = requests.get(
url, auth=(github_token, 'x-oauth-basic')
).json()

commit_url = response_json.get('object', {}).get('url')
if not commit_url:
return ''

message = requests.get(
commit_url, auth=(github_token, 'x-oauth-basic')
).json().get('message', '').strip()

if message:
return ' ({}) '.format(message)
return ''


from ansible.module_utils.basic import *
main()
73 changes: 0 additions & 73 deletions library/modcloth_app_facts.py

This file was deleted.

0 comments on commit 49a235d

Please # to comment.