Ejemplo n.º 1
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')
Ejemplo n.º 2
0
def create_or_update_pull_request(jira_url, jira_username, jira_api_key,
                                  bitbucket_username, bitbucket_password,
                                  bitbucket_destination_branch_name,
                                  bitbucket_repository_name):
    issue_key = clean_issue_key()
    issue_data = get_issue_fields(jira_url, jira_username, jira_api_key,
                                  issue_key)
    return bitbucket_create_pull_request(
        bitbucket_username, bitbucket_password,
        '{} {}'.format(issue_key, issue_data.summary), '',
        get_current_branch_name(), bitbucket_destination_branch_name,
        bitbucket_repository_name)
Ejemplo n.º 3
0
def sync_timer_to_jira(jira_url, jira_username, jira_api_key, toggl_api_key,
                       toggl_workspace_id, toggl_project_id, from_date,
                       to_date):
    def get_timer_worklog(timer, issue_data):
        for worklog in issue_data.worklog.worklogs:
            if hasattr(worklog, 'comment'
                       ) and worklog.comment == _get_timer_comment(timer):
                return worklog
        return None

    timers = get_full_timer_report(toggl_api_key,
                                   workspace_id=toggl_workspace_id,
                                   project_id=toggl_project_id,
                                   from_date=from_date,
                                   to_date=to_date).data
    for timer in timers:
        match = ISSUE_KEY_PATTERN.match(timer.description)
        if match:
            issue_key = match.group('issue_key')
            issue_data = get_issue_fields(jira_url, jira_username,
                                          jira_api_key, issue_key)
            timer_worklog = get_timer_worklog(timer, issue_data)

            timer_seconds = math.ceil(
                timer.dur / 1000 / 60) * 60  # Rounded on minutes
            if timer_worklog and timer_worklog.timeSpentSeconds != timer_seconds:
                timer_worklog.delete()
                LOGGER.info('Updating issue "{}" worklog "{}"'.format(
                    issue_key, pretty_time_delta(timer_seconds)))
                log_issue_time(
                    jira_url,
                    jira_username,
                    jira_api_key,
                    issue_key,
                    time_spend=timedelta(seconds=timer_seconds),
                    comment=_get_timer_comment(timer),
                )
            elif not timer_worklog:
                LOGGER.info('Adding issue "{}" worklog "{}"'.format(
                    issue_key, pretty_time_delta(timer_seconds)))
                log_issue_time(
                    jira_url,
                    jira_username,
                    jira_api_key,
                    issue_key,
                    time_spend=timedelta(seconds=timer_seconds),
                    comment=_get_timer_comment(timer),
                )
Ejemplo n.º 4
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)