Basic time stamp from git detection
This commit is contained in:
parent
4446cfbc87
commit
4edd3eecd0
|
@ -1,16 +1,37 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import time
|
||||||
|
import dataclasses
|
||||||
|
import git
|
||||||
|
import datetime
|
||||||
|
from collections.abc import Iterator, Sequence
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("repo")
|
parser.add_argument("repo")
|
||||||
return parser.parse_args()
|
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():
|
def main():
|
||||||
args = parse_arguments()
|
args = parse_arguments()
|
||||||
print(args.repo)
|
|
||||||
|
|
||||||
|
repo = git.Repo(args.repo)
|
||||||
|
print(repo)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
# TODO: Branch on main or master or default
|
||||||
main()
|
|
||||||
|
print(list(get_samples_from_project(repo)))
|
||||||
|
|
5
git_time_tracker/__main__.py
Normal file
5
git_time_tracker/__main__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from git_time_tracker import main
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
Reference in New Issue
Block a user