Exemplo n.º 1
0
def print_toggl(api_key):
    """
    Print currently running timer detail.
    """
    running_timer = get_running_timer_data(api_key)
    if running_timer:
        for k, v in running_timer.items():
            click.echo("    {:<15}\t{}".format(k + ':', v))
    else:
        click.echo('No running timer')
Exemplo n.º 2
0
def start_task(jira_url, jira_username, jira_api_key, jira_project_key,
               toggl_api_key, toggl_workspace_id, toggl_project_id, issue_key):
    running_timer = get_running_timer_data(toggl_api_key)
    if running_timer:
        # Do not stop timer if toggl workspace or project is invalid
        check_workspace_and_project(toggl_api_key, toggl_workspace_id,
                                    toggl_project_id)
        if confirm('Timer is already running do you want to log it?'):
            stop_task(jira_url, jira_username, jira_api_key, toggl_api_key)

    issue_key = clean_issue_key(issue_key, jira_project_key)
    issue_data = get_issue_fields(jira_url, jira_username, jira_api_key,
                                  issue_key, jira_project_key)
    toggl_description = '{} {}'.format(issue_key, issue_data.summary)
    start_timer(toggl_api_key, toggl_description, toggl_workspace_id,
                toggl_project_id)
    return 'Toggle was started with description "{}"'.format(toggl_description)
Exemplo n.º 3
0
def stop_task(jira_url, jira_username, jira_api_key, toggl_api_key):
    running_timer = get_running_timer_data(toggl_api_key)
    if running_timer:
        match = ISSUE_KEY_PATTERN.match(running_timer.description)
        if match:
            issue_key = match.group('issue_key')
            get_issue_fields(jira_url, jira_username, jira_api_key, issue_key)
            stopped_timer = stop_running_timer(toggl_api_key)
            log_issue_time(
                jira_url,
                jira_username,
                jira_api_key,
                issue_key,
                time_spend=timedelta(seconds=stopped_timer.duration),
                comment=_get_timer_comment(stopped_timer),
            )
            return 'Timner was stopped and time was logged'
        else:
            ClickException('Invalid running task description')
    else:
        ClickException('No running task')