Exemplo n.º 1
0
    def edit_task_dialog(self, issue=None):
        if not issue:
            task_number = yield from self.get_task_number()
            try:
                issue = self.jira.issue(task_number)
            except Exception as e:
                notify_error(e)
                self.answer = f'Sorry, task {task_number} does not exist.'
                return

        msg = f'Edit task {issue.key} ? (`{issue.fields.summary}`)'
        confirm_edit = yield (Markdown(msg), YES_NO_QUESTION)
        if confirm_edit.text != YES:
            return

        edit_question = 'What you want to edit ?'
        TITLE = 'Title'
        DESCRIPTION = 'Description'
        edit_option = [TITLE, DESCRIPTION, CANCEL]
        to_edit = yield (edit_question, edit_option)
        while not (to_edit.text in edit_option):
            to_edit = yield ('Please, choose a valid option', edit_option)

        if to_edit.text == TITLE:
            response = yield from self.edit_task_title(issue)
        elif to_edit.text == DESCRIPTION:
            response = yield from self.edit_task_description(issue)
        elif to_edit.text == CANCEL:
            return
        else:
            return
        return response
Exemplo n.º 2
0
    def create_task_dialog(self):
        project = self.get_user_project()

        confirmation = f'Create new task for project `{project.name}` ?'
        confirm_creation = yield (Markdown(confirmation), YES_NO_QUESTION)

        if confirm_creation.text != YES:
            return
        task_summary = yield HTML('Enter task <b>title</b>:')
        task_description = yield HTML('Enter task <b>description</b>:')

        try:
            new_issue = self.jira.create_issue(
                project={'id': project.id},
                summary=task_summary.text,
                description=task_description.text,
                issuetype={'name': 'Story'}
            )
        except Exception as e:
            notify_error(e)
            self.answer = 'Error. Task is not created.'
            return

        task_url = self.get_task_url(new_issue.key)
        send_sticker(self.user.profile.chat_id, 'ok')
        self.answer = f'Task {new_issue.key} created.\n{task_url}'
Exemplo n.º 3
0
 def edit_task_description(self, issue):
     new_desc_question = 'What description do you want to set ?\n' + \
         f'Previous description - \n`{issue.fields.description}`.'
     new_description = yield Markdown(new_desc_question)
     try:
         issue.update(description=new_description.text)
     except Exception as e:
         notify_error(e)
         self.answer = 'Error. Description for task ' + \
             f'{issue.key} is not updated.'
         return
     self.answer = f'Description for task {issue.key} updated !'
Exemplo n.º 4
0
 def edit_task_title(self, issue):
     prev_title_question = 'What title do you want to set ?\n' + \
         f'Previous title - \n`{issue.fields.summary}`.'
     new_title = yield Markdown(prev_title_question)
     try:
         issue.update(summary=new_title.text)
     except Exception as e:
         notify_error(e)
         self.answer = f'Error. Title for task {issue.key} ' + \
             'is not updated.'
         return
     self.answer = f'Title for task {issue.key} updated !'
Exemplo n.º 5
0
    def check_jira_connection(self):
        debug('[Checking jira connection]')

        try:
            url = f'https://{self.user.profile.company_name}.atlassian.net'
            self.jira = JIRA(url, basic_auth=(
                self.user.profile.jira_login, self.user.profile.jira_token)
            )
            users = self.jira.search_users(self.user.profile.jira_login)
            if users:
                self.user.profile.jira_username_key = users[0].key
                self.user.profile.jira_username_display = users[0].displayName
                self.user.profile.save()
                return True
        except Exception as e:
            notify_error(e)

        return False
Exemplo n.º 6
0
    def get_or_create_user(self, update):
        try:
            user, created = apps.get_model(
                settings.AUTH_USER_MODEL).objects.get_or_create(
                    username=update.effective_user.username)
        except Exception as e:
            notify_error('get_or_create_user error: ' + str(e))

        debug('[{action} user {user}]'.format(action=created and 'Created'
                                              or 'Get',
                                              user=user))

        if created:
            apps.get_model('core.Profile').objects.create(
                user=user, chat_id=update.message.chat_id)
        else:
            user.profile.chat_id = update.message.chat_id
            user.profile.save()

        return user