diff --git a/git_time_tracker/__init__.py b/git_time_tracker/__init__.py index 992e307..b8098ee 100644 --- a/git_time_tracker/__init__.py +++ b/git_time_tracker/__init__.py @@ -7,6 +7,10 @@ import datetime from collections.abc import Iterator, Sequence from pathlib import Path +import logging + +logger = logging.getLogger(__name__) + def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument('repositories', action='extend', nargs='+', type=Path) @@ -28,9 +32,17 @@ def determine_default(repo: git.Repo): HIDDEN_LABEL_PREFIX = '__' HIDDEN_LABEL_TOTAL = HIDDEN_LABEL_PREFIX + 'TOTAL' +def determine_project_name(repo: git.Repo) -> str: + remotes = repo.remotes + if len(remotes) > 0: + return remotes.origin.url.removeprefix('git@gitfub.space:') + return Path(repo.working_tree_dir).name + def get_samples_from_project(repo: git.Repo) -> Iterator[WorkSample]: labels = [HIDDEN_LABEL_TOTAL] - labels.append(repo.remotes.origin.url.removeprefix('git@gitfub.space:')) + name = determine_project_name(repo) + assert name is not None + labels.append(name) # TODO: Branch on main or master or default @@ -79,11 +91,18 @@ def generate_report(samples: list[WorkSample]) -> Iterator[str]: yield ' {label:40} {hours:-4.0f} hours\n'.format(label='TOTAL', hours = time_per_label[HIDDEN_LABEL_TOTAL] / HOUR) def main(): + logging.basicConfig() + args = parse_arguments() shared_time_stamps: set[WorkSample] = set() for repo_path in args.repositories: - repo = git.Repo(repo_path) + try: + repo = git.Repo(repo_path) + except git.exc.InvalidGitRepositoryError: + logger.warning('Ignoring non-repo %s', repo_path) + continue + logger.warning('Visit %s', repo_path) shared_time_stamps |= set(get_samples_from_project(repo)) shared_time_stamps = sorted(shared_time_stamps)