1
0
This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
git-time-tracker/git_time_tracker/__init__.py

38 lines
951 B
Python
Raw Normal View History

2024-06-03 20:42:05 +00:00
import argparse
2024-06-03 21:01:45 +00:00
import time
import dataclasses
import git
import datetime
from collections.abc import Iterator, Sequence
2024-06-03 20:42:05 +00:00
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("repo")
return parser.parse_args()
2024-06-03 21:01:45 +00:00
@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))
2024-06-03 20:42:05 +00:00
def main():
args = parse_arguments()
2024-06-03 21:01:45 +00:00
repo = git.Repo(args.repo)
print(repo)
# TODO: Branch on main or master or default
2024-06-03 20:42:05 +00:00
2024-06-03 21:01:45 +00:00
print(list(get_samples_from_project(repo)))