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

40 lines
1.2 KiB
Python

import argparse
import time
import dataclasses
import git
import datetime
from collections.abc import Iterator, Sequence
from pathlib import Path
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument('repositories', action='extend', nargs='+', type=Path)
return parser.parse_args()
@dataclasses.dataclass(frozen=True)
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')
print(repo.remotes.origin.repo)
# TODO: Branch on main or master or default
for commit in repo.iter_commits('main'):
yield WorkSample(datetime.datetime.fromtimestamp(commit.authored_date, tz=datetime.UTC), tuple(labels))
yield WorkSample(datetime.datetime.fromtimestamp(commit.committed_date, tz=datetime.UTC), tuple(labels))
def main():
args = parse_arguments()
shared_time_stamps: set[WorkSample] = set()
for repo_path in args.repositories:
repo = git.Repo(repo_path)
shared_time_stamps |= set(get_samples_from_project(repo))
print('derp', shared_time_stamps)