-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotifier.py
executable file
·39 lines (35 loc) · 1.7 KB
/
notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!flask/bin/python
from flask import Flask
from flask import request
from rocketchat.api import RocketChatAPI
from os import environ
app = Flask(__name__)
def notify_rocketchat(app, release, release_summary, sha, user):
api.send_message(':new: *Deis({env})* {app} #{release} - {release_summary}'
.format(app=app, release=release, release_summary=release_summary, env=env), topic)
@app.route('/notify_deploy', methods=['POST'])
def notify_deploy():
app = request.args.get('app')
release = request.args.get('release')
release_summary = request.args.get('release_summary')
sha = request.args.get('sha')
user = request.args.get('user')
print('notifying deploy app={app}, release={release}, release_summary={release_summary} topic={topic} '.format(app=app, release=release, release_summary=release_summary, topic=topic))
notify_rocketchat(app, release, release_summary, sha, user)
return ''
if __name__ == '__main__' or __name__ == 'notifier':
env = environ.get('ENV', 'stag')
debug_env = environ.get('DEBUG', 'false')
username = environ.get('ROCKETCHAT_USERNAME', 'user')
password = environ.get('ROCKETCHAT_PASSWORD', 'password')
topic = environ.get('ROCKETCHAT_TOPIC', 'deis-releases')
port = int(environ.get('PORT', 5000))
url = environ.get('ROCKETCHAT_URL', 'http://localhost:8080')
api = RocketChatAPI(settings={'username': username, 'password': password,
'domain': url})
print 'initializing deis-rocket-notifier with rocketchat username={username}, url={url}'.format(username=username, url=url)
debug = False
if debug_env == 'true':
debug=True
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port, debug=debug)