Exemplo n.º 1
0
    def run(self):
        """
        Execução de comentário para card no JIRA.
        """
        args = self._handle_args(self.arguments)
        if args.help:
            self._help()
            return

        # verifica se já foi aberto um card para esta thread
        card = self.session.query(Card).filter_by(
            slack_ts=self.thread_ts).first()
        if card:
            self.logger.debug("Adding comment to a card.")
            if args.point:
                try:
                    pointed_msg = self._get_pointed_up_message()
                    pointed_user = pointed_msg.get('user')
                    user = user_info(pointed_user).get('user')
                    comment = pointed_msg.get('text')
                except:
                    self.logger.error("Comment: error to ger previous message")
                    user = user_info(self.msg_from).get('user')
                    comment = self.cmd_text
            else:
                user = user_info(self.msg_from).get('user')
                comment = self.cmd_text

            self._comment(user=user,
                          issue_id=card.jira_issue,
                          comment=for_humans_text(comment))
        else:
            self.logger.debug("No card to comment.")
            self.text = "Não existe card aberto para comentar."
            self.send()
Exemplo n.º 2
0
    def run(self):
        """
        Executa o processo de fechamento de card no JIRA
        """
        args = self._handle_args(self.arguments)
        if args.help:
            self._help()
            return

        user = user_info(self.msg_from).get('user')
        ch = Channel().find(channel=self.channel)
        if not ch:
            self.text = "Canal não configurado!"
            self.send()
            raise PlannedException("Canal não configurado.")

        # Verifica se já foi aberto um card para esta thread
        card = self.session.query(Card).filter_by(slack_ts=self.thread_ts).first()
        if card:
            self.logger.debug("Closing card.")
            self._close(
                user=user,
                issue_id=card.jira_issue,
                transiction=ch.id_tr_close,
                comment=for_humans_text(self.cmd_text),
                status=args.status
            )
            self.text = "Card `{}` finalizado!".format(card.jira_issue)
            self.send()
        else:
            self.logger.debug("No card to close.")
            self.text = "Não existe card associado a esta thread."
            self.send()
Exemplo n.º 3
0
    def _open_card(self, ts, text, requester, operator, project, issue_type,
                   priority):
        if self.channel.startswith('C'):
            ch_info = channel_info(self.channel)
            channel = ch_info.get('channel').get('name')
        elif self.channel.startswith('G'):
            gp_info = group_info(self.channel)
            channel = gp_info.get('group').get('name')
        elif self.channel.startswith('D'):
            us_info = user_info(self.msg_from)
            channel = us_info.get('user').get('name')

        req_name = requester.get('profile').get('real_name_normalized')
        req_mail = requester.get('profile').get('email')
        req_id = requester.get('id')
        oper_mail = operator.get('profile').get('email')
        permalink = message_permalink(channel=self.channel, ts=self.thread_ts)

        # Montagem de mensagem legível
        issue_fulltext = [
            "*Solicitante:* {}".format(req_name),
            "*E-mail:* {}".format(req_mail),
            "*Msg Origem:* {}".format(permalink),
            "*Solicitação:* \r{}".format(text)
        ]

        summary = "Solicitado via Slack: Channel #{}".format(channel)
        issue = open_issue(project=project,
                           summary=summary,
                           text="\r".join(issue_fulltext),
                           issue_type=issue_type,
                           priority=priority)

        # Adiciona o operador como responsavel
        try:
            assign_issue(issue_id=issue.key, user_email=oper_mail)
        except Exception as e:
            self.logger.error("Erro em adição de responsável: {}".format(e))

        # Adiciona o solicitante como watcher
        try:
            add_watcher(issue_id=issue.key, user_email=req_mail)
        except Exception as e:
            self.logger.error("Erro na adição de visualizador: {}".format(e))

        card = Card(slack_ts=ts,
                    jira_issue=issue.key,
                    status='opened',
                    requester=req_id)
        self.session.add(card)
        self.session.commit()

        self.text = "Card `{}` criado.\n{}".format(issue.key,
                                                   issue.permalink())
        self.send()
Exemplo n.º 4
0
    def _requester_from_echo(self):
        """ 
        Retorna usuário em caso de menção
        """

        re_atuser = re.compile(r'<@[A-Z0-9]*>')
        echo_line = self.mthread_text.split('\n')[0]
        self.logger.debug("\n\n{}".format(echo_line))
        mentioned_user = re_atuser.findall(echo_line)[0]
        self.logger.debug("\n\n{}".format(echo_line))
        return user_info(mentioned_user[2:-1]).get('user')
Exemplo n.º 5
0
 def run(self):
     """
     Método de execução das ações da classe
     """
     try:
         pointed_msg = self._get_pointed_up_message()
         pointed_user = pointed_msg.get('user')
         user = user_info(pointed_user).get('user').get('name')
         text = "*{}:* {}".format(user, pointed_msg.get('text'))
     except Exception as e:
         text = "Ops, parece não ter nenhuma mensagem acima dessa. :{}:".format(
             settings.REACTION_SURPRISE)
     self.text = text
     self.send()
Exemplo n.º 6
0
    def run(self):
        """
        Método de abertura de cards no JIRA via Slack
        """
        # Verifica se eh uma mensagem normal, ou dentro da thread
        args = self._handle_args(self.arguments)

        if args.help:
            self._help()
            return

        # Captura de Dados
        ts = self.msg_ts
        issue_text = self.cmd_text
        requester = user_info(self.msg_from).get('user')
        operator = user_info(self.msg_from).get('user')
        channel_conf = Channel().find(channel=self.channel)

        # Validação de configuração
        if not channel_conf:
            self.text = "Canal não configurado!"
            self.send()
            raise PlannedException("canal não configurado")

        # Define com qual issue type o card será aberto
        if args.issue_type:
            if args.issue_type in channel_conf.issue_types:
                issue_type = channel_conf.dict_issuetypes.get(args.issue_type)
            else:
                self.text = " ".join([
                    "`ISSUE_TYPE` incorreto, esperado um dos valores: ",
                    "`{}`".format(channel_conf.issue_types)
                ])
                self.send()
                raise PlannedException("Tipo de card incorreto.")
        elif channel_conf.issuetype:
            issue_type = channel_conf.issuetype
        else:
            self.text = " ".join([
                "Não existe issue type configurado, favor informar",
                "```{}```".format(self.usage)
            ])
            self.send()
            raise PlannedException("Tipo de card não informado/configurado.")

        if args.priority:
            if args.priority in channel_conf.priorities:
                priority = channel_conf.dict_priorities.get(args.priority)
            else:
                self.text = " ".join([
                    "`PRIORITY` incorreto, Esperado um dos valores:",
                    "`{}`".format(channel_conf.priorities)
                ])
                self.send()
                raise PlannedException("Prioridade incorreta.")
        elif channel_conf.priority:
            priority = channel_conf.priority
        else:
            self.text = " ".join([
                "Não existe priority configurado, favor informar",
                "```{}```".format(self.usage)
            ])
            self.send()
            raise PlannedException("Prioridade não informada/configurada.")

        # Verifica se já foi aberto um card para esta thread
        card = self.session.query(Card).filter_by(slack_ts=ts).first()
        if card:
            self.logger.debug("Card existente.")
            self.text = "\n".join([
                "Já existe um card para esta thread:",
                "Card `{}`.".format(card.jira_issue)
            ])
            self.send()
        else:
            self.logger.debug("Criando novo card.")
            self._open_card(ts=ts,
                            text=for_humans_text(issue_text),
                            requester=requester,
                            operator=operator,
                            project=channel_conf.project,
                            issue_type=issue_type,
                            priority=priority)