<s> from __future__ import absolute_import <EOL> __all__ = [ '<STR_LIT>' ] <EOL> import json <EOL> from freight import http <EOL> from freight . models import App , TaskStatus <EOL> from . base import Notifier , NotifierEvent <EOL> class SlackNotifier ( Notifier ) : <EOL> def get_options ( self ) : <EOL> return { <EOL> '<STR_LIT>' : { '<STR_LIT>' : True } , <EOL> } <EOL> def send_deploy ( self , deploy , task , config , event ) : <EOL> webhook_url = config [ '<STR_LIT>' ] <EOL> app = App . query . get ( deploy . app_id ) <EOL> params = { <EOL> '<STR_LIT>' : deploy . number , <EOL> '<STR_LIT>' : app . name , <EOL> '<STR_LIT>' : dict ( task . params or { } ) , <EOL> '<STR_LIT>' : deploy . environment , <EOL> '<STR_LIT>' : task . ref , <EOL> '<STR_LIT>' : task . sha [ : <NUM_LIT:7> ] if task . sha else task . ref , <EOL> '<STR_LIT>' : task . status_label , <EOL> '<STR_LIT>' : task . duration , <EOL> '<STR_LIT>' : http . absolute_uri ( '<STR_LIT>' . format ( app . name , deploy . environment , deploy . number ) ) , <EOL> } <EOL> if event == NotifierEvent . TASK_QUEUED : <EOL> title = "<STR_LIT>" . format ( ** params ) <EOL> elif event == NotifierEvent . TASK_STARTED : <EOL> title = "<STR_LIT>" . format ( ** params ) <EOL> elif task . status == TaskStatus . failed : <EOL> title = "<STR_LIT>" . format ( ** params ) <EOL> elif task . status == TaskStatus . cancelled : <EOL> title = "<STR_LIT>" . format ( ** params ) <EOL> elif task . status == TaskStatus . finished : <EOL> title = "<STR_LIT>" . format ( ** params ) <EOL> else : <EOL> raise NotImplementedError ( task . status ) <EOL> payload = { <EOL> '<STR_LIT>' : '<STR_LIT:none>' , <EOL> '<STR_LIT:text>' : title , <EOL> } <EOL> values = { '<STR_LIT>' : json . dumps ( payload ) } <EOL> http . post ( webhook_url , values ) </s>
