Skip to content

Commit cd83f2f

Browse files
author
Oleksandr Korol
committed
Add argument to support optional time-tracking
1 parent 5cb3aa3 commit cd83f2f

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ repos:
3131
rev: v1.0.2
3232
hooks:
3333
- id: auto-smart-commit
34+
# Optional argument to enable time tracking behavior
35+
args: [--time-tracking]
3436
```
3537
3638
and make sure to run `pre-commit install --hook-type prepare-commit-msg` to install the hook type necessary for this hook.

auto-smart-commit.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import sys
55
from datetime import datetime
66
from math import floor
7+
import argparse
78
from subprocess import check_output
8-
from typing import NoReturn, Optional
9+
from typing import NoReturn, Optional, Sequence
910

1011

1112
def run_command(command: str) -> str:
@@ -82,9 +83,15 @@ def time_worked_on_commit() -> Optional[str]:
8283
return None
8384

8485

85-
def main() -> NoReturn:
86+
def main(argv: Sequence[str] | None = None) -> NoReturn:
8687
# https://confluence.atlassian.com/fisheye/using-smart-commits-960155400.html
8788
# 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)
8895
git_branch_name = current_git_branch_name()
8996
jira_issue_key = extract_jira_issue_key(git_branch_name)
9097
if not jira_issue_key:
@@ -104,10 +111,11 @@ def main() -> NoReturn:
104111
if "#comment" not in commit_msg and commit_body:
105112
commit_body = f"{jira_issue_key} #comment {commit_body}"
106113
# 2. Add the time worked to the Work Log in the commit body.
107-
work_time = time_worked_on_commit()
108-
if "#time" not in commit_msg and work_time:
109-
work_log = f"{jira_issue_key} #time {work_time} {commit_subject}"
110-
commit_body = f"{commit_body}\n\n{work_log}" if commit_body else work_log
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
111119
# 3. Make sure the subject starts with a Jira issue key.
112120
if not extract_jira_issue_key(commit_subject):
113121
commit_subject = f"{jira_issue_key} {commit_subject}"

0 commit comments

Comments
 (0)