-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from modcloth/dont-suffix-py
Use modcloth_app_facts rather than modcloth_app_facts.py
- Loading branch information
Showing
2 changed files
with
73 additions
and
74 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file was deleted.
Oops, something went wrong.