From 4edd3eecd00e6efe5928717b78f54823c62e69fb Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 3 Jun 2024 23:01:45 +0200 Subject: [PATCH] Basic time stamp from git detection --- README.md | 2 ++ git_time_tracker/__init__.py | 29 +++++++++++++++++++++++++---- git_time_tracker/__main__.py | 5 +++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 git_time_tracker/__main__.py diff --git a/README.md b/README.md index 5d92c08..e8065e8 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ # Git-based Time Tracker + +TODO. diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index dea667f..96ca511 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -1,16 +1,37 @@ import argparse - +import time +import dataclasses +import git +import datetime +from collections.abc import Iterator, Sequence def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument("repo") return parser.parse_args() +@dataclasses.dataclass +class WorkSample: + registered_at: datetime.datetime + labels: Sequence[str] + + +def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: + labels = [] + labels.append('project:git_time_tracker') + + for commit in repo.iter_commits('main'): + assert commit.authored_date == commit.committed_date, 'Not yet supported' + + committed_at = datetime.datetime.fromtimestamp(commit.authored_date, tz=datetime.UTC) + yield WorkSample(committed_at, tuple(labels)) def main(): args = parse_arguments() - print(args.repo) + repo = git.Repo(args.repo) + print(repo) -if __name__ == "__main__": - main() + # TODO: Branch on main or master or default + + print(list(get_samples_from_project(repo))) diff --git a/git_time_tracker/__main__.py b/git_time_tracker/__main__.py new file mode 100644 index 0000000..c0668b9 --- /dev/null +++ b/git_time_tracker/__main__.py @@ -0,0 +1,5 @@ +from git_time_tracker import main + +if __name__ == '__main__': + main() +