예제 #1
0
 def directSlack(self, person, msg=None, as_user=False, *args, **kwargs):
     if self.config.is_debug:
         person = self.config.debug_folks
     LOG.info("\n************** NOTIFYING ******************\n"
              "**************  %s      *************\n"
              "Message= %s\n"
              "******************************************* " %
              (person, msg))
     self.slack.chat.post_message(channel=person,
                                  text=msg,
                                  icon_url=self.icon,
                                  username="******",
                                  as_user=as_user,
                                  *args,
                                  **kwargs)
예제 #2
0
 def postToSlack(self, channel, msg=None, as_user=True, *args, **kwargs):
     LOG.info("\n************** NOTIFYING ******************\n"
              "**************  %s      *************\n"
              "Message= %s\n"
              "******************************************* " %
              (channel, msg))
     try:
         self.slack.chat.post_message(channel=channel,
                                      text=msg,
                                      icon_url=self.icon,
                                      as_user=as_user,
                                      *args,
                                      **kwargs)
     except Exception as ex:
         LOG.error("Error while posting alert to slack, please check if: \n1. The provided slack/hubot token for alice is correct " \
               "and it has access to the channel=%s" \
               "\n2.The channel name is correct\n" %(channel))
         raise ex
예제 #3
0
    def handle_issue_create(self):
        assignee_slack_channel_id = self.slack_dict.get(
            self.parsed_data.assignee_email)
        LOG.info(
            '*********** assigne slack channel id create handler ************ %s'
            % assignee_slack_channel_id)
        attachment = list()
        fields = list()
        for change in self.parsed_data.change_log:
            field_item = dict()
            field_list = ['assignee', 'description', 'priority', 'Status']
            if str(change.get("field")) in field_list:
                field_item["title"] = str(change.get("field"))
                field_item["value"] = str(change.get("toString"))
                fields.append(field_item)

        attach = JIRA_ISSUE_UPDATE.copy()
        attach[
            'pretext'] = '*{issue_reporter}* reported issue *{issue_key}*'.format(
                issue_reporter=self.parsed_data.issue_reporter,
                issue_key=self.parsed_data.issue_key)
        attach["title"] = attach.get("title").format(
            issue_key=self.parsed_data.issue_key,
            issue_title=self.parsed_data.issue_title)
        attach["title_link"] = attach.get("title_link").format(
            issue_url=self.parsed_data.issue_url)
        attach["text"] = ''
        attach["fields"] = fields
        attachment.append(attach)
        slack = Slacker(self.slack_token)
        # resp = slack.chat.post_message(channel="@Nagaraj", text="", username="******", as_user=True, attachments=attachment)
        slack.chat.post_message(channel=str(assignee_slack_channel_id),
                                text="",
                                username="******",
                                as_user=True,
                                attachments=attachment)
예제 #4
0
 def handle_issue_update(self):
     assignee_slack_channel_id = self.slack_dict.get(
         self.parsed_data.assignee_email)
     reporter_slack_channel_id = self.slack_dict.get(
         self.parsed_data.issue_reporter_email)
     issue_reporter_email_id = self.parsed_data.issue_reporter_email
     issue_updated_email_id = self.parsed_data.issue_updated_by_email
     assignee_email_id = self.parsed_data.assignee_email
     LOG.info(
         '*********** assigne slack channel id update handler ************ %s'
         % assignee_slack_channel_id)
     LOG.info(
         '*********** reporter slack channel id update handler ************ %s'
         % reporter_slack_channel_id)
     attachment = list()
     for change in self.parsed_data.change_log:
         attach = JIRA_ISSUE_UPDATE.copy()
         if change.get("field") == "description":
             attach[
                 'pretext'] = "*{issue_updated_by}* updated {issue_key} `{field}`".format(
                     issue_updated_by=self.parsed_data.issue_updated_by,
                     issue_key=self.parsed_data.issue_key,
                     field=change.get('field'),
                 )
         else:
             if change.get('fromString'):
                 attach['pretext'] = attach.get("pretext").format(
                     issue_updated_by=self.parsed_data.issue_updated_by,
                     issue_key=self.parsed_data.issue_key,
                     field=change.get('field'),
                     from_string=change.get('fromString'),
                     to_string=change.get('toString'))
             else:
                 attach[
                     'pretext'] = "*{issue_updated_by}* updated {issue_key} `{field}` to `{to_string}`".format(
                         issue_updated_by=self.parsed_data.issue_updated_by,
                         issue_key=self.parsed_data.issue_key,
                         field=change.get('field'),
                         to_string=change.get('toString'))
         attach["title"] = attach.get("title").format(
             issue_key=self.parsed_data.issue_key,
             issue_title=self.parsed_data.issue_title)
         attach["title_link"] = attach.get("title_link").format(
             issue_url=self.parsed_data.issue_url)
         attach["text"] = attach.get("text").format(
             issue_desc=self.description)
         attachment.append(attach)
     slack = Slacker(self.slack_token)
     # resp = slack.chat.post_message(channel="@Nagaraj", text="", username="******", as_user=True, attachments=attachment)
     if issue_updated_email_id == issue_reporter_email_id and issue_updated_email_id != assignee_email_id:
         slack.chat.post_message(channel=str(assignee_slack_channel_id),
                                 text="",
                                 username="******",
                                 as_user=True,
                                 attachments=attachment)
     elif issue_updated_email_id == assignee_email_id and issue_updated_email_id != issue_reporter_email_id:
         slack.chat.post_message(channel=str(reporter_slack_channel_id),
                                 text="",
                                 username="******",
                                 as_user=True,
                                 attachments=attachment)
예제 #5
0
 def __init__(self, request, payload):
     self.request = request
     self.payload = payload
     self.pr = payload["pull_request"]
     LOG.debug("Repo=" + self.repo)
     self.config = ConfigProvider(self.repo)