@@ -29,69 +29,9 @@ def extract_jira_issue_key(message: str) -> Optional[str]:
2929 return None
3030
3131
32- def last_commit_datetime () -> datetime :
33- # https://git-scm.com/docs/git-log#_pretty_formats
34- git_log = "git log -1 --branches --format=%aI"
35- author = run_command ("git config user.email" )
36- last_author_datetime = run_command (f"{ git_log } --author={ author } " ) or run_command (git_log )
37- if "+" in last_author_datetime :
38- return datetime .strptime (last_author_datetime .split ("+" )[0 ], "%Y-%m-%dT%H:%M:%S" )
39- return datetime .now ()
40-
41-
42- def num_lunches (start : datetime , end : datetime ) -> int :
43- n = (end .date () - start .date ()).days - 1
44- if start < start .replace (hour = 12 , minute = 0 , second = 0 ):
45- n += 1
46- if end > end .replace (hour = 12 , minute = 45 , second = 0 ):
47- n += 1
48- return max (n , 0 )
49-
50-
51- def num_nights (start : datetime , end : datetime ) -> int :
52- n = (end .date () - start .date ()).days - 1
53- if start < start .replace (hour = 1 , minute = 0 , second = 0 ):
54- n += 1
55- if end > end .replace (hour = 5 , minute = 0 , second = 0 ):
56- n += 1
57- return max (n , 0 )
58-
59-
60- def time_worked_on_commit () -> Optional [str ]:
61- now = datetime .now ()
62- last = last_commit_datetime ()
63- # Determine the number of minutes worked on this commit as the number of
64- # minutes since the last commit minus the lunch breaks and nights.
65- working_hours_per_day = 8
66- working_days_per_week = 5
67- minutes = max (
68- round ((now - last ).total_seconds () / 60 )
69- - num_nights (last , now ) * (24 - working_hours_per_day ) * 60
70- - num_lunches (last , now ) * 45 ,
71- 0 ,
72- )
73- # Convert the number of minutes worked to working weeks, days, hours,
74- # minutes.
75- if minutes > 0 :
76- hours = floor (minutes / 60 )
77- minutes -= hours * 60
78- days = floor (hours / working_hours_per_day )
79- hours -= days * working_hours_per_day
80- weeks = floor (days / working_days_per_week )
81- days -= weeks * working_days_per_week
82- return f"{ weeks } w { days } d { hours } h { minutes } m"
83- return None
84-
85-
86- def main (argv : Sequence [str ] | None = None ) -> NoReturn :
32+ def main () -> NoReturn :
8733 # https://confluence.atlassian.com/fisheye/using-smart-commits-960155400.html
8834 # Exit if the branch name does not contain a Jira issue key.
89- parser = argparse .ArgumentParser ()
90- parser .add_argument (
91- '--time-tracking' ,
92- help = 'Optional time tracking argument' ,
93- )
94- args = parser .parse_args (argv )
9535 git_branch_name = current_git_branch_name ()
9636 jira_issue_key = extract_jira_issue_key (git_branch_name )
9737 if not jira_issue_key :
@@ -110,12 +50,6 @@ def main(argv: Sequence[str] | None = None) -> NoReturn:
11050 # 1. If there is a body, turn it into a comment on the issue.
11151 if "#comment" not in commit_msg and commit_body :
11252 commit_body = f"{ jira_issue_key } #comment { commit_body } "
113- # 2. Add the time worked to the Work Log in the commit body.
114- if args .time_tracking :
115- work_time = time_worked_on_commit ()
116- if "#time" not in commit_msg and work_time :
117- work_log = f"{ jira_issue_key } #time { work_time } { commit_subject } "
118- commit_body = f"{ commit_body } \n \n { work_log } " if commit_body else work_log
11953 # 3. Make sure the subject starts with a Jira issue key.
12054 if not extract_jira_issue_key (commit_subject ):
12155 commit_subject = f"{ jira_issue_key } { commit_subject } "
0 commit comments