示例#1
0
def handle(command, args):
    # we don't need api connection to show help :/
    if command == "help":
        return usage()

    jira_username = config.get("jira_user")
    jira_password = config.get("jira_pass")

    options = {"server": config.get("jira_server")}

    jira = JIRA(options, basic_auth=(jira_username, jira_password))

    if commands.get(command):
        return commands[command](jira, args)
示例#2
0
def fires(jira, args):
    m = re.match(r'(\w+)?', args)

    if not m:
        return utils.not_valid_args(args)

    project_key = m.group(1) or config.get('jira_default_project')

    if not project_key:
        return utils.error('Project name is required')

    if not utils.check_project(jira, project_key):
        return utils.error('Project {} does not exist'.format(project_key))

    try:
        query = 'project={0} and labels in (fire)'.format(project_key)
        issues = jira.search_issues(query)

        if not issues:
            return 'No issues found'

        return '\n'.join([utils.issue_info(issue) for issue in issues])
    except JIRAError as e:
        response = utils.error('{} {}'.format(str(e.status_code), str(e.text)))
        return response
示例#3
0
def create(jira, args):
    m = re.match(r'(\w+)? ?(?:@(\w+))? (.*)', args)

    if not m:
        return utils.not_valid_args(args)

    project_key = m.group(1) or config.get('jira_default_project')

    if not project_key:
        return utils.error('Project name is required')

    assignee = m.group(2)
    summary = m.group(3)

    fields = {
        'project': {'key': project_key},
        'summary': summary,
        'issuetype': {'name': config.get('jira_default_issue_type')},
    }

    try:
        if assignee:
            jira.user(assignee)

        issue = jira.create_issue(fields=fields)

        issue.fields.labels = config.get('jira_default_labels')
        issue.update(fields={"labels": issue.fields.labels})

        # weird, but user cannot be assigned during creation
        if assignee:
            issue.update(assignee={'name': assignee})

        return utils.issue_info(issue)
    except JIRAError as e:
        response = utils.error('{} {}'.format(str(e.status_code), str(e.text)))
        return response
示例#4
0
def users(jira, args):
    m = re.match(r'(\w+)?', args)

    if not m:
        return utils.not_valid_args(args)

    project_key = m.group(1) or config.get('jira_default_project')

    if not project_key:
        return utils.error('Project name is required')

    if not utils.check_project(jira, project_key):
        return utils.error('Project {} does not exist'.format(project_key))

    try:
        users = jira.search_assignable_users_for_projects('', project_key)
        return '\n'.join([utils.user_info(user) for user in users])
    except JIRAError as e:
        response = utils.error('{} {}'.format(str(e.status_code), str(e.text)))
        return response
示例#5
0
def done_issues(jira, args):  # todo
    m = re.match(r'(\w+)?', args)

    if not m:
        return utils.not_valid_args(args)

    project_key = m.group(1) or config.get('jira_default_project')

    if not project_key:
        return utils.error('Project name is required')

    if not utils.check_project(jira, project_key):
        return utils.error('Project {} does not exist'.format(project_key))

    query = 'project={} and status in (\'Done\', \'Closed\', \'Resolved\')'.format(project_key)
    issues = jira.search_issues(query)

    if not issues:
        return 'No issues found'

    return '\n\n'.join([utils.issue_info(issue) for issue in issues])
示例#6
0
def issue_info(issue):
    issue_summary = issue.fields.summary
    issue_description = issue.fields.description or 'No description'
    issue_key = issue.key
    issue_labels = ','.join(issue.fields.labels or ['no labels', ])
    issue_type = issue.fields.issuetype
    issue_status = issue.fields.status
    issue_link = '{}/browse/{}'.format(config.get('jira_server'), issue_key)

    assignee = issue.fields.assignee

    if assignee:
        assignee = '@' + user_info(assignee)
    else:
        assignee = 'not assigned'

    return '{}\n{}\n{}|{}|{}|{}|{}\n{}'.format(issue_summary,
                                           issue_description,
                                           issue_key,
                                           issue_labels,
                                           issue_type,
                                           issue_status,
                                           assignee,
                                           issue_link)
示例#7
0
import logging
import sys

import asyncio
import discord
import yaml

from bot.bot import DungeonBot
from bot.config import config

log = logging.getLogger(__name__)


if __name__ == "__main__":
    bot_config = config.get("bot", {})
    token = bot_config.pop("token", "")
    prefix = bot_config.get("prefix")

    if not token or token == "Replace me":
        log.critical("No token given, add your token in config.yml!")
        print("No token given, add your token in config.yml!")
        sys.exit(1)

    kwargs = {
        "command_prefix": prefix,
        "config": bot_config
    }

    bot = DungeonBot(**kwargs)

    bot.load_cogs()