예제 #1
0
def team_24_recommend_allocation_handler() -> Response:
    """ TEAM_24_RECOMMEND_ALLOCATION handler

    :return:
    """
    allocation_table = list()
    jira_account = get_jira_account()
    users = get_project_users_without_pm()

    q = "project = {project} AND assignee = '{user}' AND status IN ('To Do', 'In Progress') ORDER BY issuekey"
    total = 0
    for user in users:
        q_user = q.format(project=config.get('jira', 'project'), user=user)
        tasks, tasks_count_msg = get_jira_tasks(q_user, jira_account)
        allocation_table.append((user, len(tasks)))
        total += len(tasks)

    tasks, tasks_count_msg = get_backlog(jira_account)
    if tasks_count_msg == _("NONE"):
        return _("NO_BACKLOG")

    summary = allocate_backlog(tasks, allocation_table, total, users)
    msg = _("RECOMMENDER_INTRO")
    for usr, ts in summary.items():
        msg += _("RECOMMENDER_SG",
                 tasks=format_enumeration(ts)) if len(ts) == 1 else _(
                     "RECOMMENDER_PL",
                     tasks=format_enumeration(ts)) + _("TO") + " " + usr + ". "

    response = Response(msg)
    return response
예제 #2
0
def team_24_assign_task_handler(username: str, taskname: str) -> Response:
    """ TEAM_24_ASSIGN_TASK handler

    :param username: str
    :param taskname: str
    :return:
    """

    chosen_user = clarify_user(username)

    jira_account = get_jira_account()
    tasks, tasks_count_msg = get_all_jira_tasks_with_keys(jira_account)
    if tasks_count_msg == _("NONE"):
        return Response(_("EMPTY_PROJECT", intent="TEAM_24_NEW_TASK"))

    chosen_task = choose_entity_from_tuples(tasks, taskname)

    if chosen_task is None or chosen_user is None:
        return Response(_("CANNOT_UNDERSTAND", intent="TEAM_24_NEW_TASK"))

    assignable_users = jira_account.get_assignable_users_for_issue(chosen_task[0])
    user_with_account_id = next(filter(lambda user: user['displayName'] == chosen_user, assignable_users), None)

    if user_with_account_id is None:
        return Response(_("CANNOT_UNDERSTAND", intent="TEAM_24_NEW_TASK"))

    account_id_user = user_with_account_id['accountId']
    jira_account.issue_update(chosen_task[0], fields={"assignee": {"accountId": account_id_user}})

    response = Response(_("ASSIGN_TASK", intent="TEAM_24_NEW_TASK", username=chosen_user))
    return response
예제 #3
0
def team_24_project_status_handler() -> Response:
    overdue_q = 'project = {project} AND assignee = "{user}" AND duedate < Now() and status in ("In Progress", "To Do")'
    jira_account = get_jira_account()
    users = get_project_users()
    overdue_msg = ""
    for user in users:
        overdue_q_user = overdue_q.format(project=config.get(
            'jira', 'project'),
                                          user=user)
        overdue_tasks = get_jira_tasks_with_due_dates(overdue_q_user,
                                                      jira_account)
        overdue_tasks_count = len(overdue_tasks)
        if overdue_tasks_count > 0:
            overdue_msg += user + _("ASSIGNED") + " "
            for idx, tpl in enumerate(overdue_tasks):
                overdue_msg += _("OVERDUE_TASK",
                                 task=tpl[0],
                                 days=(datetime.now() - parse(tpl[1])).days)
                overdue_msg += ", " if idx != overdue_tasks_count - 1 else "."

    if overdue_msg == "":
        overdue_msg = _("NO_OVERDUE_TASKS")

    response = Response(overdue_msg)
    return response
예제 #4
0
def get_urgent_tasks():
    urgent_q = 'project = {project} AND status IN ("To Do") and priority in (Highest)'. \
        format(project=config.get('jira', 'project'))
    account = get_jira_account()
    q_res = account.jql(urgent_q)
    tasks = [(t['fields']['summary'], t['fields']['assignee']['displayName'])
             for t in q_res['issues']]
    return tasks
예제 #5
0
def team_24_call_handler() -> Response:
    """ TEAM_24_CALL handler
    :return:
    """

    jira_account = get_jira_account()
    tasks, tasks_count_msg = get_backlog(jira_account)
    if tasks_count_msg == _("NONE"):
        return _("NO_BACKLOG")

    msg = _("BACKLOG_INTRO")
    msg += format_enumeration(tasks) + "."

    response = Response(msg)
    return response
예제 #6
0
def team_24_project_status_handler() -> Response:
    """ TEAM_24_PROJECT_STATUS handler

    :return:
    """

    urgent_q = 'project = {project} AND status IN ("To Do") and priority in (Highest)'.\
        format(project=config.get('jira', 'project'))

    overdue_q = 'project = {project} AND duedate < Now() and status in ("In Progress", "To Do")'.\
        format(project=config.get('jira', 'project'))

    jira_account = get_jira_account()
    todo_tasks, todo_tasks_count_msg = get_jira_tasks(get_board_query("To Do"),
                                                      jira_account)
    inprogress_tasks, inprogress_tasks_count_msg = get_jira_tasks(
        get_board_query("In Progress"), jira_account)
    done_tasks, done_tasks_count_msg = get_jira_tasks(get_board_query("Done"),
                                                      jira_account)
    urgent_tasks, urgent_tasks_count_msg = get_jira_tasks(
        urgent_q, jira_account)
    overdue_tasks, overdue_tasks_count_msg = get_jira_tasks(
        overdue_q, jira_account)
    idle_users = get_idle_users(jira_account)

    msg = _("SPRINT_STATUS",
            project=config.get('jira', 'project'),
            todos=todo_tasks_count_msg,
            inprogress=inprogress_tasks_count_msg,
            done=done_tasks_count_msg)

    msg += " " + _("PROJECT_STATUS_INTRO",
                   project=config.get('jira', 'project'),
                   urgent_tasks=urgent_tasks_count_msg,
                   overdue_tasks=overdue_tasks_count_msg)

    if len(idle_users) > 0:
        verb = _("ARE")
        if len(idle_users) == 1:
            verb = _("IS")
        user_str = format_enumeration(idle_users)
        msg_idle = " " + _("IDLE_USERS", users=user_str, verb=verb)
        msg += msg_idle

    response = Response(msg)
    return response
예제 #7
0
def team_24_new_task_handler(taskname: str) -> Response:
    """ TEAM_24_NEW_TASK handler

    :param taskname: str
    :return:
    """

    jira_account = get_jira_account()
    my_project = get_current_project(jira_account)

    issue_dict = {
        'project': {'key': '{project}'.format(project=my_project['key'])},
        'issuetype': {'name': 'Story'},
        'summary': '{taskname}'.format(taskname=taskname)
    }
    jira_account.issue_create_or_update(fields=issue_dict)

    response = Response(_("NEW_TASK", taskname=taskname))
    return response
예제 #8
0
def team_24_call_handler(username: str) -> Response:
    """ TEAM_24_COWORKER_STATUS handler

    :param username: str
    :return:
    """

    user = clarify_user(username)

    jira_account = get_jira_account()
    todo_tasks, todo_tasks_count_msg = get_jira_tasks(
        get_user_board_query("To Do", user), jira_account)
    inprogress_tasks, inprogress_tasks_count_msg = get_jira_tasks(
        get_user_board_query("In Progress", user), jira_account)
    done_tasks, done_tasks_count_msg = get_jira_tasks(
        get_user_board_query("Done", user), jira_account)

    msg = _("COWORKER_STATUS",
            username=username,
            todos=todo_tasks_count_msg,
            inprogress=inprogress_tasks_count_msg,
            done=done_tasks_count_msg)

    if inprogress_tasks_count_msg != _("NONE"):
        msg += " " + _("COWORKER_INPROGRESS",
                       username=user,
                       tasks=format_enumeration(inprogress_tasks))

    urgent_q = 'project = {project} AND assignee = "{username}" AND status IN ("To Do") and priority in (Highest)'. \
        format(project=config.get('jira', 'project'), username=user)

    overdue_q = 'project = {project} AND assignee = "{username}" AND duedate < Now() and status in ("In Progress", ' \
                '"To Do")'. \
        format(project=config.get('jira', 'project'), username=user)

    urgent_tasks, urgent_tasks_count_msg = get_jira_tasks(
        urgent_q, jira_account)
    if urgent_tasks_count_msg != _("NONE"):
        msg += _("COWORKER_URGENT",
                 username=user,
                 tasks=format_enumeration(urgent_tasks)) + "."

    overdue_tasks = get_jira_tasks_with_due_dates(overdue_q, jira_account)
    overdue_tasks_count = len(overdue_tasks)
    if overdue_tasks_count > 0:
        msg += _("COWORKER_OVERDUE", username=user)
        for idx, tpl in enumerate(overdue_tasks):
            msg += _("OVERDUE_TASK",
                     task=tpl[0],
                     days=(datetime.now() - parse(tpl[1])).days)
            msg += ", " if idx != overdue_tasks_count - 1 else "."

    no_tasks_q = "project = {project} AND assignee = '{user}' AND status IN ('In Progress', 'To Do') ORDER BY issuekey".format(
        project=config.get('jira', 'project'), user=user)
    tasks, tasks_count_msg = get_jira_tasks(no_tasks_q, jira_account)
    if len(tasks) == 0:
        msg += " " + _("COWORKER_EMPTY")
    else:
        idle_tasks_q = "project = {project} AND assignee = '{user}' AND status IN ('In Progress') ORDER BY " \
                       "issuekey".format(project=config.get('jira', 'project'), user=user)
        idle_tasks, idle_tasks_count_msg = get_jira_tasks(
            idle_tasks_q, jira_account)
        if len(idle_tasks) == 0:
            msg += " " + _("COWORKER_IDLE")

    response = Response(msg)
    return response