Exemplo n.º 1
0
 def get_comment_attachment(self, data):
     """
     Return a dict with attachment data for Comment activity
     """
     comment = data['attributes']
     pretext = '%s commented on %s %s:' % (
         MessageServiceBase.format_name(comment['created_by']),
         comment['item']['type'], self.format_item_link(comment['item']))
     return {
         'color': self.get_attachment_color(comment['item']),
         'pretext': pretext,
         'text': '"%s"' % MessageServiceBase.format_comment(comment['body'])
     }
Exemplo n.º 2
0
 def get_comment_attachment(self, data):
     """
     Return a dict with attachment data for Comment activity
     """
     comment = data['attributes']
     pretext = '%s commented on %s %s:' % (
         MessageServiceBase.format_name(comment['created_by']),
         comment['item']['type'], self.format_item_link(comment['item']))
     return {
         'color': self.get_attachment_color(comment['item']),
         'pretext': pretext,
         'text': '"%s"' % MessageServiceBase.format_comment(comment['body'])
     }
Exemplo n.º 3
0
    def get_post_data(self, data):
        """
        Take payload data and format it appropriately to post to Slack
        """

        # Set default data 

        message = MessageServiceBase.message(data)

        default_data = {
            'color': SPRINTLY_DEFAULT_COLOR,
            'fallback': message
        }

        # Get activity model-specific attachment data-formatting method name and call it

        format_method = 'get_%s_attachment' % data['model'].lower()
        attachment = getattr(self, format_method, lambda data: None)(data)

        # Merged returned data with default
        
        default_data.update(attachment)

        return {
            'icon_url': 'https://s3.amazonaws.com/sprintly-marketing-assets/integrations/slack-bot-icon.png',
            'attachments': [default_data]
        }
Exemplo n.º 4
0
    def get_post_data(self, data):
        """
        Take payload data and format it appropriately to post to Slack
        """

        # Set default data

        message = MessageServiceBase.message(data)

        default_data = {'color': SPRINTLY_DEFAULT_COLOR, 'fallback': message}

        # Get activity model-specific attachment data-formatting method name and call it

        format_method = 'get_%s_attachment' % data['model'].lower()
        attachment = getattr(self, format_method, lambda data: None)(data)

        # Merged returned data with default

        default_data.update(attachment)

        return {
            'icon_url':
            'https://s3.amazonaws.com/sprintly-marketing-assets/integrations/slack-bot-icon.png',
            'attachments': [default_data]
        }
Exemplo n.º 5
0
def test_format_name_no_last_name():
    data = {
        'first_name': 'Julia',
        'last_name': ''
    }

    assert MessageServiceBase.format_name(data) == 'Julia'
Exemplo n.º 6
0
    def extract_item_attachment_data(self, item):
        """
        Extract item data from passed in item dict for use in an attachment
        """
        item_attachment = {
            'color': self.get_attachment_color(item),
            'text': self.format_item_link(item),
            'fields': []
        }

        if item['assigned_to']:
            item_attachment['fields'].append({
                'title': 'Assigned to',
                'value': '%s' % MessageServiceBase.format_name(item['assigned_to']),
                'short': True
            })

        if item['status']:
            item_attachment['fields'].append({
                'title': 'Status',
                'value': ' '.join(item['status'].split('-')).capitalize(),
                'short': True
            })

        if item['score']:
            item_attachment['fields'].append({
                'title': 'Score',
                'value': item['score'],
                'short': True
            })

        return item_attachment
Exemplo n.º 7
0
 def get_item_attachment(self, data):
     """
     Return a dict with attachment data for Item activity
     """
     item = data['attributes']
     attachment = self.extract_item_attachment_data(item)
     attachment['pretext'] = '%s created the %s:' % (MessageServiceBase.format_name(item['created_by']), item['type'])
     return attachment
Exemplo n.º 8
0
 def get_item_attachment(self, data):
     """
     Return a dict with attachment data for Item activity
     """
     item = data['attributes']
     attachment = self.extract_item_attachment_data(item)
     attachment['pretext'] = '%s created the %s:' % (
         MessageServiceBase.format_name(item['created_by']), item['type'])
     return attachment
Exemplo n.º 9
0
 def get_favorite_attachment(self, data):
     """
     Return a dict with attachment data for Favorite activity
     """
     fave = data['attributes']
     attachment = self.extract_item_attachment_data(fave['item'])
     attachment['pretext'] = '%s favorited the %s:' % (
         MessageServiceBase.format_name(fave['user']), fave['item']['type'])
     return attachment
Exemplo n.º 10
0
 def get_favorite_attachment(self, data):
     """
     Return a dict with attachment data for Favorite activity
     """
     fave = data['attributes']
     attachment = self.extract_item_attachment_data(fave['item'])
     attachment['pretext'] = '%s favorited the %s:' % (
         MessageServiceBase.format_name(fave['user']), fave['item']['type'])
     return attachment
Exemplo n.º 11
0
 def get_block_attachment(self, data):
     """
     Return a dict with attachment data for Block activity
     """
     block = data['attributes']
     attachment = self.extract_item_attachment_data(block['item'])
     attachment[
         'pretext'] = '%s indicated the %s %s is blocked by the %s:' % (
             MessageServiceBase.format_name(
                 block['user']), block['blocked']['type'],
             self.format_item_link(block['blocked']), block['item']['type'])
     return attachment
Exemplo n.º 12
0
 def get_block_attachment(self, data):
     """
     Return a dict with attachment data for Block activity
     """
     block = data['attributes']
     attachment = self.extract_item_attachment_data(block['item'])
     attachment[
         'pretext'] = '%s indicated the %s %s is blocked by the %s:' % (
             MessageServiceBase.format_name(
                 block['user']), block['blocked']['type'],
             self.format_item_link(block['blocked']), block['item']['type'])
     return attachment
Exemplo n.º 13
0
 def get_deploy_attachment(self, data):
     """
     Return a dict with attachment data for Deploy activity
     """
     deploy = data['attributes']
     items = deploy['items']
     return {
         'color':
         self.get_attachment_color(),
         'text':
         '%s deployed %d item%s to %s' %
         (MessageServiceBase.format_name(deploy['user']), len(items),
          '' if len(items) == 1 else 's', deploy['environment'])
     }
Exemplo n.º 14
0
 def get_deploy_attachment(self, data):
     """
     Return a dict with attachment data for Deploy activity
     """
     deploy = data['attributes']
     items = deploy['items']
     return {
         'color':
         self.get_attachment_color(),
         'text':
         '%s deployed %d item%s to %s' % (MessageServiceBase.format_name(
             deploy['user']), len(items), '' if len(items) == 1 else 's',
                                          deploy['environment'])
     }
Exemplo n.º 15
0
    def send(self, payload):
        campfire = pinder.Campfire(self.options['subdomain'], self.options['token'])
        room = campfire.find_room_by_name(self.options['room'])
        if room is None:
            logger.error("Could not join the room %s to send payload %r Options: %r",
                         self.options['room'], payload, self.options)
            return

        message = MessageServiceBase.message(payload)
        if not message:
            return

        room.join()
        room.speak(message)
Exemplo n.º 16
0
    def send(self, payload):
        message = MessageServiceBase.message(payload)
        if not message:
            return

        data = {
            "auth_token": self.options["auth_token"],
            "format": "json",
            "room_id": self.options["room_id"],
            "from": "Sprint.ly",
            "message": message,
            "message_format": "text",
        }

        url = "https://api.hipchat.com/v1/rooms/message"
        _ = requests.post(url, data=data)
Exemplo n.º 17
0
    def send(self, payload):
        message = MessageServiceBase.message(payload)
        if not message:
            return

        data = {
            'auth_token': self.options['auth_token'],
            'format': 'json',
            'room_id': self.options['room_id'],
            'from': 'Sprint.ly',
            'message': message,
            'message_format': 'text',
        }

        url = 'https://api.hipchat.com/v1/rooms/message'
        _ = requests.post(url, data=data)
Exemplo n.º 18
0
    def extract_item_attachment_data(self, item):
        """
        Extract item data from passed in item dict for use in an attachment
        """
        item_attachment = {
            'color': self.get_attachment_color(item),
            'text': self.format_item_link(item),
            'fields': []
        }

        if item['assigned_to']:
            item_attachment['fields'].append({
                'title': 'Assigned to',
                'value': '<https://sprint.ly/reports?assignee={1}|{0}>'.format(MessageServiceBase.format_name(item['assigned_to']),
                    item['assigned_to']['id']),
                'short': True
            })

        if item['status']:
            item_attachment['fields'].append({
                'title': 'Status',
                'value': '<https://sprint.ly/reports?status={1}|{0}>'.format(' '.join(item['status'].split('-')).capitalize(), item['status']),
                'short': True
            })

        if item['score']:
            item_attachment['fields'].append({
                'title': 'Score',
                'value': item['score'],
                'short': True
            })

        if len(item['tags']):
            item_attachment['fields'].append({
                'title': 'Tags',
                'value': ', '.join(['<https://sprint.ly/reports?tag={0}|{0}>'.format(tag) for tag in item['tags']]),
                'short': True
            })

        item_attachment['fields'].append({
            'title': 'Product',
            'value': '<https://sprint.ly/reports?product={1}|{0}>'.format(item['product']['name'], item['product']['id']),
            'short': True
        })

        return item_attachment
Exemplo n.º 19
0
    def extract_item_attachment_data(self, item):
        """
        Extract item data from passed in item dict for use in an attachment
        """
        item_attachment = {
            'color': self.get_attachment_color(item),
            'text': self.format_item_link(item),
            'fields': []
        }

        if item['assigned_to']:
            item_attachment['fields'].append({
                'title':
                'Assigned to',
                'value':
                '<https://sprint.ly/reports?assignee={1}|{0}>'.format(
                    MessageServiceBase.format_name(item['assigned_to']),
                    item['assigned_to']['id']),
                'short':
                True
            })

        if item['status']:
            item_attachment['fields'].append({
                'title':
                'Status',
                'value':
                '<https://sprint.ly/reports?status={1}|{0}>'.format(
                    ' '.join(item['status'].split('-')).capitalize(),
                    item['status']),
                'short':
                True
            })

        if item['score']:
            item_attachment['fields'].append({
                'title': 'Score',
                'value': item['score'],
                'short': True
            })

        if len(item['tags']):
            item_attachment['fields'].append({
                'title':
                'Tags',
                'value':
                ', '.join([
                    '<https://sprint.ly/reports?tag={0}|{0}>'.format(tag)
                    for tag in item['tags']
                ]),
                'short':
                True
            })

        item_attachment['fields'].append({
            'title':
            'Product',
            'value':
            '<https://sprint.ly/reports?product={1}|{0}>'.format(
                item['product']['name'], item['product']['id']),
            'short':
            True
        })

        return item_attachment
Exemplo n.º 20
0
def test_format_comment_trunc():
    comment = 'a' * 51
    assert MessageServiceBase.format_comment(comment)[-3:] == '...'
Exemplo n.º 21
0
def test_format_comment():
    comment = 'Hello'
    assert MessageServiceBase.format_comment(comment) == comment
Exemplo n.º 22
0
def test_clean_mentions():
    comment = "Hello there @[Joe Stump](pk:1)"
    assert MessageServiceBase.clean_mentions(comment) == "Hello there Joe Stump"