Skip to content

Commit

Permalink
Removed unecessary requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
Luboš Mátl committed Jun 20, 2024
1 parent dbacdb7 commit 3064b2b
Show file tree
Hide file tree
Showing 4 changed files with 555 additions and 515 deletions.
29 changes: 24 additions & 5 deletions developers_chamber/bin/pydev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down
316 changes: 160 additions & 156 deletions developers_chamber/project_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,6 +25,166 @@
ISSUE_KEY_PATTERN = re.compile(r"(?P<issue_key>[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))
Expand Down Expand Up @@ -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),
)
Loading

0 comments on commit 3064b2b

Please sign in to comment.