def issue_assigned(self, item, template):
     data = {
         'user': item.get('toString'),
     }
     data.update(self.generic_data)
     template = read_template(template)
     self.messages.append(template.substitute(**data))
Exemple #2
0
    def notify(self):
        if self.update['issue_event_type_name'] not in self.supported_actions:
            return

        self.generic_data = {
            'username': self.update['user']['displayName'],
            'link': f'{self.host}/browse/{self.issue.upper()}',
            'link_name': self.issue.upper(),
        }

        # in one issue update may be coming several items
        for item in self.update['changelog']['items']:
            field = item.get('field')
            template = self.message_template.get(field)
            if not template:
                continue

            if self.update['issue_event_type_name'] == self.assigned:
                self.issue_assigned(item, template)
            elif self.update['issue_event_type_name'] == self.generic and field == self.status_action:
                self.issue_status(item, template)
            elif self.update['issue_event_type_name'] == self.generic and field == self.resolution_action:
                self.issue_resolution(item, template)
            elif self.update['issue_event_type_name'] == self.updated and field == self.attachment_action:
                self.file_attachment(item, template)
            elif self.update['issue_event_type_name'] in (self.updated, self.generic) and field == self.assignee_action:
                self.issue_reassigned(item, template)
            else:
                text = read_template(template)
                self.messages.append(text.substitute(**self.generic_data))

        urls = self.prepare_messages(self.messages)
        broadcast(urls)
 def issue_reassigned(self, item, template):
     username = item.get('toString')
     data = {
         'user': username or 'Unassigned',
     }
     data.update(self.generic_data)
     template = read_template(template)
     self.messages.append(template.substitute(**data))
 def issue_status(self, item, template):
     data = {
         'old_status': item.get('fromString'),
         'new_status': item.get('toString'),
     }
     data.update(self.generic_data)
     template = read_template(template)
     self.messages.append(template.substitute(**data))
 def notify(self):
     data = {
         'action': self.update.get('webhookEvent').replace('project_', ''),
         'link': f"{self.host}/browse/{self.update['project']['key']}",
         'link_name': self.update['project']['key'].upper(),
     }
     text = read_template(self.message_template)
     message = text.substitute(**data)
     urls = self.prepare_messages(message)
     broadcast(urls)
 def issue_resolution(self, item, template):
     old_resolution = item.get('fromString')
     new_resolution = item.get('toString')
     data = {
         'old_resolution': old_resolution or 'Unresolved',
         'new_resolution': new_resolution or 'Unresolved',
     }
     data.update(self.generic_data)
     template = read_template(template)
     self.messages.append(template.substitute(**data))
 def file_attachment(self, item, template):
     filename = item.get('toString')
     if filename:
         data = {
             'filename': filename,
             'action': 'attached',
         }
     else:
         data = {
             'filename': item.get('fromString'),
             'action': 'deleted',
         }
     data.update(self.generic_data)
     template = read_template(template)
     self.messages.append(template.substitute(**data))
 def notify(self):
     issue = self.update['issue']['key']
     _, action = self.update['webhookEvent'].split(":")
     for chat_id in self.chat_ids:
         if action == 'issue_deleted':
             issue_subscribed = self.db.get_subscription(chat_id, issue)
             if issue_subscribed:
                 action = 'issue_deleted_unsubscribed'
                 self.db.delete_subscription(chat_id, issue)
         template = self.message_template[action]
         text = read_template(template)
         data = {
             "issue_link": f"{self.host}/browse/{issue}",
             "issue_name": issue
         }
         message = text.substitute(**data)
         self.messages.append(message)
     urls = self.prepare_messages(self.messages)
     broadcast(urls)