2012-12-04 18:22:15 +01:00
|
|
|
#!/usr/bin/env python
|
2013-08-06 21:32:15 +02:00
|
|
|
# Copyright (C) 2012 Zulip, Inc.
|
2012-12-04 18:22:15 +01:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person
|
|
|
|
# obtaining a copy of this software and associated documentation files
|
|
|
|
# (the "Software"), to deal in the Software without restriction,
|
|
|
|
# including without limitation the rights to use, copy, modify, merge,
|
|
|
|
# publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
# and to permit persons to whom the Software is furnished to do so,
|
|
|
|
# subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
# SOFTWARE.
|
|
|
|
|
|
|
|
import sys
|
2013-10-28 15:54:32 +01:00
|
|
|
import os
|
2012-12-04 18:22:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Configure this script as a Tddium post-build task and it will send
|
2013-08-06 21:32:15 +02:00
|
|
|
# messages to Zulip when a build finishes.
|
2012-12-04 18:22:15 +01:00
|
|
|
#
|
|
|
|
# Expects Tddium environment variables plus:
|
|
|
|
#
|
2013-10-04 20:08:19 +02:00
|
|
|
# ZULIP_USER e.g. builds@solanolabs.com
|
|
|
|
# ZULIP_API_KEY e.g. 00000000000000000000000000000000
|
|
|
|
# ZULIP_STREAM e.g. builds
|
2012-12-04 18:22:15 +01:00
|
|
|
#
|
2013-10-04 20:08:19 +02:00
|
|
|
# If ZULIP_API_KEY is not specified, it will be read from
|
|
|
|
# ~/.zulip-api-key.
|
2012-12-04 18:22:15 +01:00
|
|
|
|
|
|
|
|
2013-10-04 20:08:19 +02:00
|
|
|
# Path to the directory where zulip.py lives.
|
2012-12-04 18:22:15 +01:00
|
|
|
# Here we assume it's in the parent of the directory
|
|
|
|
# where this script lives.
|
|
|
|
|
2013-10-28 15:54:32 +01:00
|
|
|
zulip_directory = os.path.join(os.path.dirname(__file__), '../api')
|
2012-12-04 18:22:15 +01:00
|
|
|
|
|
|
|
|
2013-10-04 20:08:19 +02:00
|
|
|
sys.path.append(zulip_directory)
|
2013-08-07 17:51:03 +02:00
|
|
|
import zulip
|
2012-12-04 18:22:15 +01:00
|
|
|
|
2013-08-07 17:51:03 +02:00
|
|
|
client = zulip.Client(
|
2013-12-06 23:50:55 +01:00
|
|
|
client = "ZulipTddiumNotifier/0.1",
|
2013-10-28 15:54:32 +01:00
|
|
|
email = os.environ['ZULIP_USER'],
|
|
|
|
api_key = os.environ.get('ZULIP_API_KEY'))
|
2012-12-04 18:22:15 +01:00
|
|
|
|
2013-10-28 15:54:32 +01:00
|
|
|
tddium_server = os.environ.get('TDDIUM_API_SERVER', 'api.tddium.com')
|
|
|
|
report_url = 'https://%s/1/reports/%s' % (tddium_server, os.environ['TDDIUM_SESSION_ID'])
|
|
|
|
repo_name = os.path.basename(os.environ['TDDIUM_REPO_ROOT'])
|
2012-12-04 18:22:15 +01:00
|
|
|
|
|
|
|
result = client.send_message(dict(
|
|
|
|
type = 'stream',
|
2013-10-28 15:54:32 +01:00
|
|
|
to = os.environ['ZULIP_STREAM'],
|
2012-12-04 18:22:15 +01:00
|
|
|
subject = 'build for ' + repo_name,
|
|
|
|
content = '%s [%s](%s)' %
|
2013-10-28 15:54:32 +01:00
|
|
|
(repo_name, os.environ['TDDIUM_BUILD_STATUS'], report_url)))
|
2012-12-04 18:22:15 +01:00
|
|
|
|
|
|
|
if result['result'] != 'success':
|
2013-08-06 21:32:15 +02:00
|
|
|
sys.stderr.write('Error sending to Zulip:\n%s\n' % (result['msg'],))
|
2012-12-04 18:22:15 +01:00
|
|
|
sys.exit(1)
|