Add support for the Flowdock Team chat API: https://www.flowdock.com/api/push
This commit is contained in:
parent
02d3b70013
commit
35bd28a77e
8 changed files with 84 additions and 3 deletions
|
@ -184,6 +184,8 @@ class BuildFailureEvent(NotificationEvent):
|
|||
return 'build_failure'
|
||||
|
||||
def get_sample_data(self, repository):
|
||||
build_uuid = 'fake-build-id'
|
||||
|
||||
return build_event_data(repository, {
|
||||
'build_id': build_uuid,
|
||||
'build_name': 'some-fake-build',
|
||||
|
|
|
@ -4,9 +4,10 @@ import os.path
|
|||
import tarfile
|
||||
import base64
|
||||
import json
|
||||
import requests
|
||||
|
||||
from flask.ext.mail import Message
|
||||
from app import mail, app
|
||||
from app import mail, app, get_app_url
|
||||
from data import model
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -187,3 +188,55 @@ class WebhookMethod(NotificationMethod):
|
|||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class FlowdockMethod(NotificationMethod):
|
||||
""" Method for sending notifications to Flowdock via the Team Inbox API:
|
||||
https://www.flowdock.com/api/team-inbox
|
||||
"""
|
||||
@classmethod
|
||||
def method_name(cls):
|
||||
return 'flowdock'
|
||||
|
||||
def validate(self, repository, config_data):
|
||||
token = config_data.get('flow_api_token', '')
|
||||
if not token:
|
||||
raise CannotValidateNotificationMethodException('Missing Flowdock API Token')
|
||||
|
||||
def perform(self, notification, event_handler, notification_data):
|
||||
config_data = json.loads(notification.config_json)
|
||||
token = config_data.get('flow_api_token', '')
|
||||
if not token:
|
||||
return False
|
||||
|
||||
owner = model.get_user(notification.repository.namespace)
|
||||
if not owner:
|
||||
# Something went wrong.
|
||||
return False
|
||||
|
||||
url = 'https://api.flowdock.com/v1/messages/team_inbox/%s' % token
|
||||
headers = {'Content-type': 'application/json'}
|
||||
payload = {
|
||||
'source': 'Quay',
|
||||
'from_address': 'support@quay.io',
|
||||
'subject': event_handler.get_summary(notification_data['event_data'], notification_data),
|
||||
'content': event_handler.get_message(notification_data['event_data'], notification_data),
|
||||
'from_name': owner.username,
|
||||
'project': notification.repository.namespace + ' ' + notification.repository.name,
|
||||
'tags': ['#' + event_handler.event_name()],
|
||||
'link': notification_data['event_data']['homepage']
|
||||
}
|
||||
|
||||
try:
|
||||
resp = requests.post(url, data=json.dumps(payload), headers=headers)
|
||||
if resp.status_code/100 != 2:
|
||||
logger.error('%s response for flowdock to url: %s' % (resp.status_code,
|
||||
url))
|
||||
logger.error(resp.content)
|
||||
return False
|
||||
|
||||
except requests.exceptions.RequestException as ex:
|
||||
logger.exception('Flowdock method was unable to be sent: %s' % ex.message)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
|
@ -251,6 +251,8 @@ def initialize_database():
|
|||
ExternalNotificationMethod.create(name='email')
|
||||
ExternalNotificationMethod.create(name='webhook')
|
||||
|
||||
ExternalNotificationMethod.create(name='flowdock')
|
||||
|
||||
NotificationKind.create(name='repo_push')
|
||||
NotificationKind.create(name='build_queued')
|
||||
NotificationKind.create(name='build_start')
|
||||
|
|
|
@ -4559,6 +4559,13 @@ i.quay-icon {
|
|||
height: 16px;
|
||||
}
|
||||
|
||||
i.flowdock-icon {
|
||||
background-image: url(/static/img/flowdock.ico);
|
||||
background-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.external-notification-view-element {
|
||||
margin: 10px;
|
||||
padding: 6px;
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
<tr ng-if="currentMethod.fields.length"><td colspan="2"><hr></td></tr>
|
||||
|
||||
<tr ng-repeat="field in currentMethod.fields">
|
||||
<td>{{ field.title }}:</td>
|
||||
<td valign="top">{{ field.title }}:</td>
|
||||
<td>
|
||||
<div ng-switch on="field.type">
|
||||
<span ng-switch-when="email">
|
||||
|
@ -86,7 +86,11 @@
|
|||
current-entity="currentConfig[field.name]"
|
||||
ng-model="currentConfig[field.name]"
|
||||
allowed-entities="['user', 'team', 'org']"
|
||||
ng-switch-when="entity">
|
||||
ng-switch-when="entity"></div>
|
||||
|
||||
<div ng-if="field.help_url" style="margin-top: 10px">
|
||||
See: <a href="{{ field.help_url }}" target="_blank">{{ field.help_url }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
BIN
static/img/flowdock.ico
Normal file
BIN
static/img/flowdock.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
|
@ -1076,6 +1076,19 @@ quayApp = angular.module('quay', quayDependencies, function($provide, cfpLoading
|
|||
'title': 'Webhook URL'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'id': 'flowdock',
|
||||
'title': 'Flowdock Team Notification',
|
||||
'icon': 'flowdock-icon',
|
||||
'fields': [
|
||||
{
|
||||
'name': 'flow_api_token',
|
||||
'type': 'string',
|
||||
'title': 'Flow API Token',
|
||||
'help_url': 'https://www.flowdock.com/account/tokens'
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
|
|
Binary file not shown.
Reference in a new issue