diff --git a/developers_chamber/bin/pydev.py b/developers_chamber/bin/pydev.py index 95da201..ee6ce4c 100644 --- a/developers_chamber/bin/pydev.py +++ b/developers_chamber/bin/pydev.py @@ -22,15 +22,34 @@ from developers_chamber.scripts import cli from developers_chamber.scripts.bitbucket import * from developers_chamber.scripts.docker import * -from developers_chamber.scripts.ecs import * + +try: + from developers_chamber.scripts.ecs import * +except ImportError: + pass + from developers_chamber.scripts.git import * from developers_chamber.scripts.gitlab import * -from developers_chamber.scripts.jira import * +try: + from developers_chamber.scripts.jira import * +except ImportError: + pass from developers_chamber.scripts.project import * -from developers_chamber.scripts.qa import * + +try: + from developers_chamber.scripts.qa import * +except ImportError: + pass from developers_chamber.scripts.sh import * -from developers_chamber.scripts.slack import * -from developers_chamber.scripts.toggle import * + +try: + from developers_chamber.scripts.slack import * +except ImportError: + pass +try: + from developers_chamber.scripts.toggle import * +except ImportError: + pass from developers_chamber.scripts.version import * from developers_chamber.scripts.init_aliasses import * diff --git a/developers_chamber/project_utils.py b/developers_chamber/project_utils.py index 447b7a9..bb9a9f4 100644 --- a/developers_chamber/project_utils.py +++ b/developers_chamber/project_utils.py @@ -12,22 +12,7 @@ from python_hosts.exception import UnableToWriteHosts from python_hosts.hosts import Hosts, HostsEntry -from developers_chamber.bitbucket_utils import ( - create_pull_request as bitbucket_create_pull_request, -) from developers_chamber.git_utils import get_current_branch_name -from developers_chamber.jira_utils import ( - clean_issue_key, - get_issue_fields, - log_issue_time, -) -from developers_chamber.toggle_utils import ( - check_workspace_and_project, - get_full_timer_report, - get_running_timer_data, - start_timer, - stop_running_timer, -) from developers_chamber.utils import ( call_command, call_compose_command, @@ -40,6 +25,166 @@ ISSUE_KEY_PATTERN = re.compile(r"(?P[A-Z][A-Z]+-\d+).*") +try: + from developers_chamber.jira_utils import ( + clean_issue_key, + get_issue_fields, + log_issue_time, + ) + from developers_chamber.toggle_utils import ( + check_workspace_and_project, + get_full_timer_report, + get_running_timer_data, + start_timer, + stop_running_timer, + ) + from developers_chamber.bitbucket_utils import ( + create_pull_request as bitbucket_create_pull_request, + ) + + def _get_timer_comment(timer): + return "Toggl #{}".format(timer["id"]) + + 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) + + + 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, + ) + + 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") + + 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), + ) +except ImportError: + pass + + + def get_command_output(command): try: LOGGER.info(command if isinstance(command, str) else " ".join(command)) @@ -204,144 +349,3 @@ def compose_install( compose_stop(project_name, compose_files, None) -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) - - -def _get_timer_comment(timer): - return "Toggl #{}".format(timer["id"]) - - -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") - - -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, - ) - - -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), - ) diff --git a/developers_chamber/scripts/project.py b/developers_chamber/scripts/project.py index 2fec34c..49a7a78 100644 --- a/developers_chamber/scripts/project.py +++ b/developers_chamber/scripts/project.py @@ -3,7 +3,6 @@ import click -from developers_chamber.bitbucket_utils import get_commit_builds from developers_chamber.click.options import ( ContainerCommandType, ContainerDirToCopyType, @@ -11,7 +10,6 @@ ) from developers_chamber.git_utils import create_branch as create_branch_func from developers_chamber.git_utils import get_commit_hash, get_current_branch_name -from developers_chamber.jira_utils import get_branch_name from developers_chamber.project_utils import bind_library as bind_library_func from developers_chamber.project_utils import ( compose_build, @@ -25,15 +23,9 @@ from developers_chamber.project_utils import ( copy_containers_dirs as copy_containers_dirs_func, ) -from developers_chamber.project_utils import ( - create_or_update_pull_request as create_or_update_pull_request_func, -) from developers_chamber.project_utils import ( docker_clean, - set_hosts, - start_task, - stop_task, - sync_timer_to_jira, + set_hosts ) from developers_chamber.scripts import cli @@ -467,360 +459,374 @@ def clean(all): docker_clean(all) -@project.group() -def task(): - """Helpers to work with project task in Jira and Toggle""" - - -@task.command() -@click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) -@click.option( - "--jira-username", - help="Jira username", - type=str, - required=True, - default=jira_username, -) -@click.option( - "--jira-api-key", - help="Jira API key/password", - type=str, - required=True, - default=jira_api_key, -) -@click.option( - "--jira_project-key", - help="Jira project key", - type=str, - required=False, - default=jira_project_key, -) -@click.option( - "--toggl-api-key", - help="toggle API key", - type=str, - required=True, - default=toggl_api_key, -) -@click.option( - "--toggl-workspace-id", - "-w", - help="toggl workspace ID", - type=str, - required=False, - default=toggl_workspace_id, -) -@click.option( - "--toggl-project-id", - "-p", - help="toggl project ID", - type=str, - required=False, - default=toggl_project_id, -) -@click.option("--issue-key", "-i", help="key of the task", type=str) -def start( - jira_url, - jira_username, - jira_api_key, - jira_project_key, - toggl_api_key, - toggl_workspace_id, - toggl_project_id, - issue_key, -): - """ - Get information from Jira about issue and start Toggle timer. - """ - click.echo( - start_task( - jira_url, - jira_username, - jira_api_key, - jira_project_key, - toggl_api_key, - toggl_workspace_id, - toggl_project_id, - issue_key, - ) +try: + from developers_chamber.jira_utils import get_branch_name + from developers_chamber.bitbucket_utils import get_commit_builds + from developers_chamber.project_utils import ( + start_task, + stop_task, + sync_timer_to_jira, + ) + from developers_chamber.project_utils import ( + create_or_update_pull_request as create_or_update_pull_request_func, ) - -@task.command() -@click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) -@click.option( - "--jira-username", - help="Jira username", - type=str, - required=True, - default=jira_username, -) -@click.option( - "--jira-api-key", - help="Jira API key/password", - type=str, - required=True, - default=jira_api_key, -) -@click.option( - "--toggl-api-key", - help="toggle API key", - type=str, - required=True, - default=toggl_api_key, -) -def stop(jira_url, jira_username, jira_api_key, toggl_api_key): - """ - Stop Toggle timer and logs time to the Jira issue. - """ - click.echo(stop_task(jira_url, jira_username, jira_api_key, toggl_api_key)) + @project.group() + def task(): + """Helpers to work with project task in Jira and Toggle""" -@task.command() -@click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) -@click.option( - "--jira-username", - help="Jira username", - type=str, - required=True, - default=jira_username, -) -@click.option( - "--jira-api-key", - help="Jira API key/password", - type=str, - required=True, - default=jira_api_key, -) -@click.option( - "--jira-project-key", - help="Jira project key", - type=str, - required=False, - default=jira_project_key, -) -@click.option( - "--source_branch_name", - "-s", - help="source branch name", - type=str, - default=source_branch_name, -) -@click.option("--issue-key", "-i", help="key of the task", type=str, required=True) -def create_branch_from_issue( - jira_url, jira_username, jira_api_key, project_key, source_branch_name, issue_key -): - """ - Create a new git branch from the source branch with name generated from the Jira issue. - """ - click.echo( - 'Branch "{}" was created'.format( - create_branch_func( - source_branch_name, - get_branch_name( - jira_url, jira_username, jira_api_key, issue_key, project_key - ), - ) - ) + @task.command() + @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-username", + help="Jira username", + type=str, + required=True, + default=jira_username, ) - - -@task.command() -@click.option( - "--jira-url", "-u", help="Jira URL", type=str, required=True, default=jira_url -) -@click.option( - "--jira-username", - "-a", - help="Jira username", - type=str, - required=True, - default=jira_username, -) -@click.option( - "--jira-api-key", - "-p", - help="Jira API key/password", - type=str, - required=True, - default=jira_api_key, -) -@click.option( - "--bitbucket-username", - help="username", - type=str, - required=True, - default=bitbucket_username, -) -@click.option( - "--bitbucket-password", - help="password", - type=str, - required=True, - default=bitbucket_password, -) -@click.option( - "--bitbucket-destination-branch-name", - help="destination bitbucket branch name", - type=str, - required=True, - default=bitbucket_destination_branch_name, -) -@click.option( - "--bitbucket-repository-name", - "-r", - help="bitbucket repository name", - type=str, - required=True, - default=bitbucket_repository_name, -) -def create_or_update_pull_request( - jira_url, - jira_username, - jira_api_key, - bitbucket_username, - bitbucket_password, - bitbucket_destination_branch_name, - bitbucket_repository_name, -): - """ - Create a Bitbucket pull request named according to the Jira issue. - """ - click.echo( - 'Pull request "{}" was created or updated'.format( - create_or_update_pull_request_func( + @click.option( + "--jira-api-key", + help="Jira API key/password", + type=str, + required=True, + default=jira_api_key, + ) + @click.option( + "--jira_project-key", + help="Jira project key", + type=str, + required=False, + default=jira_project_key, + ) + @click.option( + "--toggl-api-key", + help="toggle API key", + type=str, + required=True, + default=toggl_api_key, + ) + @click.option( + "--toggl-workspace-id", + "-w", + help="toggl workspace ID", + type=str, + required=False, + default=toggl_workspace_id, + ) + @click.option( + "--toggl-project-id", + "-p", + help="toggl project ID", + type=str, + required=False, + default=toggl_project_id, + ) + @click.option("--issue-key", "-i", help="key of the task", type=str) + def start( + jira_url, + jira_username, + jira_api_key, + jira_project_key, + toggl_api_key, + toggl_workspace_id, + toggl_project_id, + issue_key, + ): + """ + Get information from Jira about issue and start Toggle timer. + """ + click.echo( + start_task( jira_url, jira_username, jira_api_key, - bitbucket_username, - bitbucket_password, - bitbucket_destination_branch_name, - bitbucket_repository_name, + jira_project_key, + toggl_api_key, + toggl_workspace_id, + toggl_project_id, + issue_key, ) ) + + + @task.command() + @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-username", + help="Jira username", + type=str, + required=True, + default=jira_username, + ) + @click.option( + "--jira-api-key", + help="Jira API key/password", + type=str, + required=True, + default=jira_api_key, + ) + @click.option( + "--toggl-api-key", + help="toggle API key", + type=str, + required=True, + default=toggl_api_key, + ) + def stop(jira_url, jira_username, jira_api_key, toggl_api_key): + """ + Stop Toggle timer and logs time to the Jira issue. + """ + click.echo(stop_task(jira_url, jira_username, jira_api_key, toggl_api_key)) + + + @task.command() + @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-username", + help="Jira username", + type=str, + required=True, + default=jira_username, + ) + @click.option( + "--jira-api-key", + help="Jira API key/password", + type=str, + required=True, + default=jira_api_key, ) + @click.option( + "--jira-project-key", + help="Jira project key", + type=str, + required=False, + default=jira_project_key, + ) + @click.option( + "--source_branch_name", + "-s", + help="source branch name", + type=str, + default=source_branch_name, + ) + @click.option("--issue-key", "-i", help="key of the task", type=str, required=True) + def create_branch_from_issue( + jira_url, jira_username, jira_api_key, project_key, source_branch_name, issue_key + ): + """ + Create a new git branch from the source branch with name generated from the Jira issue. + """ + click.echo( + 'Branch "{}" was created'.format( + create_branch_func( + source_branch_name, + get_branch_name( + jira_url, jira_username, jira_api_key, issue_key, project_key + ), + ) + ) + ) -@task.command() -@click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) -@click.option( - "--jira-username", - help="Jira username", - type=str, - required=True, - default=jira_username, -) -@click.option( - "--jira-api-key", - help="Jira API key/password", - type=str, - required=True, - default=jira_api_key, -) -@click.option( - "--toggl-api-key", - help="toggle API key", - type=str, - required=True, - default=toggl_api_key, -) -@click.option( - "--toggl-workspace-id", - "-w", - help="toggl workspace ID", - type=str, - required=False, - default=toggl_workspace_id, -) -@click.option( - "--toggl-project-id", - "-p", - help="toggl project ID", - type=str, - required=False, - default=toggl_project_id, -) -@click.option( - "--from-date", - "-f", - help="report from", - type=click.DateTime(formats=["%Y-%m-%d"]), - default=str(date.today()), -) -@click.option( - "--to-date", - "-t", - help="report to", - type=click.DateTime(formats=["%Y-%m-%d"]), - default=str(date.today()), -) -def sync_timer_log_to_issues( - jira_url, - jira_username, - jira_api_key, - toggl_api_key, - toggl_workspace_id, - toggl_project_id, - from_date, - to_date, -): - """ - Synchronize logged time in Toggle timer with issues worklog in Jira. - """ - sync_timer_to_jira( + @task.command() + @click.option( + "--jira-url", "-u", help="Jira URL", type=str, required=True, default=jira_url + ) + @click.option( + "--jira-username", + "-a", + help="Jira username", + type=str, + required=True, + default=jira_username, + ) + @click.option( + "--jira-api-key", + "-p", + help="Jira API key/password", + type=str, + required=True, + default=jira_api_key, + ) + @click.option( + "--bitbucket-username", + help="username", + type=str, + required=True, + default=bitbucket_username, + ) + @click.option( + "--bitbucket-password", + help="password", + type=str, + required=True, + default=bitbucket_password, + ) + @click.option( + "--bitbucket-destination-branch-name", + help="destination bitbucket branch name", + type=str, + required=True, + default=bitbucket_destination_branch_name, + ) + @click.option( + "--bitbucket-repository-name", + "-r", + help="bitbucket repository name", + type=str, + required=True, + default=bitbucket_repository_name, + ) + def create_or_update_pull_request( + jira_url, + jira_username, + jira_api_key, + bitbucket_username, + bitbucket_password, + bitbucket_destination_branch_name, + bitbucket_repository_name, + ): + """ + Create a Bitbucket pull request named according to the Jira issue. + """ + click.echo( + 'Pull request "{}" was created or updated'.format( + create_or_update_pull_request_func( + jira_url, + jira_username, + jira_api_key, + bitbucket_username, + bitbucket_password, + bitbucket_destination_branch_name, + bitbucket_repository_name, + ) + ) + ) + + + @task.command() + @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-username", + help="Jira username", + type=str, + required=True, + default=jira_username, + ) + @click.option( + "--jira-api-key", + help="Jira API key/password", + type=str, + required=True, + default=jira_api_key, + ) + @click.option( + "--toggl-api-key", + help="toggle API key", + type=str, + required=True, + default=toggl_api_key, + ) + @click.option( + "--toggl-workspace-id", + "-w", + help="toggl workspace ID", + type=str, + required=False, + default=toggl_workspace_id, + ) + @click.option( + "--toggl-project-id", + "-p", + help="toggl project ID", + type=str, + required=False, + default=toggl_project_id, + ) + @click.option( + "--from-date", + "-f", + help="report from", + type=click.DateTime(formats=["%Y-%m-%d"]), + default=str(date.today()), + ) + @click.option( + "--to-date", + "-t", + help="report to", + type=click.DateTime(formats=["%Y-%m-%d"]), + default=str(date.today()), + ) + def sync_timer_log_to_issues( jira_url, jira_username, jira_api_key, toggl_api_key, toggl_workspace_id, toggl_project_id, - from_date.date(), - to_date.date(), - ) - click.echo("Issue times were synchronized with the timer") + from_date, + to_date, + ): + """ + Synchronize logged time in Toggle timer with issues worklog in Jira. + """ + sync_timer_to_jira( + jira_url, + jira_username, + jira_api_key, + toggl_api_key, + toggl_workspace_id, + toggl_project_id, + from_date.date(), + to_date.date(), + ) + click.echo("Issue times were synchronized with the timer") -@task.command() -@click.option( - "--bitbucket-username", - help="username", - type=str, - required=True, - default=bitbucket_username, -) -@click.option( - "--bitbucket-password", - help="password", - type=str, - required=True, - default=bitbucket_password, -) -@click.option( - "--bitbucket-repository-name", - "-r", - help="bitbucket repository name", - type=str, - required=True, - default=bitbucket_repository_name, -) -@click.option("--branch-name", help="git branch name", type=str, required=False) -def print_last_commit_build( - bitbucket_username, bitbucket_password, bitbucket_repository_name, branch_name -): - """ - Print the last commit test results in Bitbucket of the selected branch. - """ - branch_name = branch_name or get_current_branch_name() - commit_builds = get_commit_builds( - bitbucket_username, - bitbucket_password, - bitbucket_repository_name, - get_commit_hash(branch_name), - ) - if commit_builds: - for build_data in commit_builds: - click.echo(build_data["name"]) - click.echo(" Description: {}".format(build_data["description"])) - click.echo(" URL: {}\n".format(build_data["url"])) - else: - click.echo("Builds weren't found") + @task.command() + @click.option( + "--bitbucket-username", + help="username", + type=str, + required=True, + default=bitbucket_username, + ) + @click.option( + "--bitbucket-password", + help="password", + type=str, + required=True, + default=bitbucket_password, + ) + @click.option( + "--bitbucket-repository-name", + "-r", + help="bitbucket repository name", + type=str, + required=True, + default=bitbucket_repository_name, + ) + @click.option("--branch-name", help="git branch name", type=str, required=False) + def print_last_commit_build( + bitbucket_username, bitbucket_password, bitbucket_repository_name, branch_name + ): + """ + Print the last commit test results in Bitbucket of the selected branch. + """ + branch_name = branch_name or get_current_branch_name() + commit_builds = get_commit_builds( + bitbucket_username, + bitbucket_password, + bitbucket_repository_name, + get_commit_hash(branch_name), + ) + if commit_builds: + for build_data in commit_builds: + click.echo(build_data["name"]) + click.echo(" Description: {}".format(build_data["description"])) + click.echo(" URL: {}\n".format(build_data["url"])) + else: + click.echo("Builds weren't found") +except ImportError: + pass \ No newline at end of file diff --git a/setup.py b/setup.py index 2993df2..3657a9c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='developers-chamber', - version='0.1.6', + version='0.1.8', description='A small plugin which help with development, deployment, git', keywords='django, skripts, easy live, git, bitbucket, Jira', author='Druids team', @@ -13,23 +13,34 @@ include_package_data=True, packages=find_packages(), install_requires=[ - 'oauthlib==3.1.0', 'gitpython==3.1.30', 'click>=8.1', 'requests>=2.23.0', 'python-dotenv==0.14.0', - 'boto3<2', 'python-hosts==0.4.6', - 'isort==5.12.0', 'coloredlogs==10.0', 'click-completion==0.5.2', - 'jira==2.0.0', - 'unidecode==1.1.1', - 'TogglPy==0.1.2', - 'flake8>=7.0.0', - 'slack-sdk==3.21.3', 'toml>=0.10.2', ], + extras_require={ + 'slack': [ + 'slack-sdk==3.21.3', + ], + 'aws': [ + 'boto3<2', + ], + 'qa': [ + 'isort==5.12.0', + 'flake8>=7.0.0', + ], + 'jira': [ + 'jira==2.0.0', + 'unidecode==1.1.1', + ], + 'toggle': [ + 'TogglPy==0.1.2', + ] + }, entry_points={'console_scripts': [ 'pydev=developers_chamber.bin.pydev:cli', ]},