Basic implementation for commit provider

This commit is contained in:
Dima Gerasimov 2018-10-09 22:38:58 +01:00
parent abe825dee6
commit f3278ec1db
3 changed files with 79 additions and 0 deletions

73
commits/__init__.py Normal file
View file

@ -0,0 +1,73 @@
from datetime import datetime
from typing import List, NamedTuple, Optional
from os.path import basename, islink, isdir, join
from os import listdir
import git # type: ignore
# TODO do something smarter... later
# TODO def run against bitbucket and gh backups
SOURCES = [
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
]
THINGS = [
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
'***REMOVED***',
]
def by_me(actor):
aa = actor.email + " " + actor.name
if actor.email in ('***REMOVED***', '***REMOVED***@gmail.com'):
return True
if actor.name in ('***REMOVED***',):
return True
for thing in THINGS:
if thing in aa:
print("WARNING!!!", actor)
return True
return False
class Commit(NamedTuple):
dt: datetime
message: str
repo: str
# TODO filter so they are authored by me
def iter_commits(repo: str):
# TODO other branches?
rr = basename(repo)
gr = git.Repo(repo)
for c in gr.head.reference.log():
if by_me(c.actor):
yield Commit(
dt=c.time,
message=c.message, # TODO strip off 'commit: '? (there are also 'merge')
repo=rr,
)
def is_git_repo(d: str):
dotgit = join(d, '.git')
return isdir(dotgit)
# TODO eh. traverse all of filesystem?? or only specific dirs for now?
def iter_all_commits():
for src in SOURCES:
# TODO warn if doesn't exist?
for d in listdir(src):
pr = join(src, d)
if is_git_repo(pr):
for c in iter_commits(pr):
yield c
def get_all_commits():
ss = set(iter_all_commits())
return list(sorted(ss, key=lambda c: c.dt))

View file

@ -0,0 +1,5 @@
from commits import iter_commits, iter_all_commits, get_all_commits
# TODO cache?
for c in get_all_commits(): # ('***REMOVED***'):
print(c)

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
gitpython