Created
October 10, 2016 19:21
-
-
Save mberrueta/8e1f14de72e988d66207191d527f8046 to your computer and use it in GitHub Desktop.
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
import httplib, json | |
import getopt, sys, os | |
import subprocess | |
def get_data_from_git(format_string, commit): | |
return subprocess.check_output(['git', 'log', '-1', '--format=format:%s' % format_string, commit]) | |
def get_author(commit): | |
return get_data_from_git('%an', commit) | |
def post_message(connection, url, app): | |
headers = {'Content-Type': 'application/json'} | |
commit = os.environ['COMMIT'] | |
version = os.environ['HEROKU_V'] | |
color = 'good' | |
text = '%s deployed version %s of <https://%s.herokuapp.com| #%s>' % ( get_author(commit), version, app, app) | |
message = { | |
'username': 'Shippable', | |
'fallback': text, | |
'pretext': text, | |
'color': color | |
] | |
} | |
connection.request('POST', url, json.dumps(message), headers) | |
response = connection.getresponse() | |
print response.read().decode() | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], ':sf', ['app=', 'swh=']) | |
except getopt.GetoptError as err: | |
print str(err) | |
sys.exit(2) | |
app = None | |
url = None | |
message = None | |
for o, arg in opts: | |
if o == '--app': | |
app = arg | |
elif o == '--swh': | |
url = arg | |
connection = httplib.HTTPSConnection('hooks.slack.com') | |
post_message(connection, url, app) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment