|
#!/usr/bin/env python3 |
|
|
|
# GitPython is required |
|
|
|
import git |
|
import datetime |
|
|
|
listOfRepos = [] |
|
|
|
days = 3 |
|
|
|
commits_by_author = {} |
|
|
|
def main(): |
|
for repo in listOfRepos: |
|
fetchRepo(repo) |
|
|
|
printCommits() |
|
|
|
|
|
def printCommits(): |
|
print() |
|
for author_name, commits in commits_by_author.items(): |
|
print(f"Commits by {author_name}") |
|
for commit in commits: |
|
repo = commit["repo"] |
|
branch = commit["branch"] |
|
summary = commit["summary"] |
|
committed_date = datetime.datetime.fromtimestamp( |
|
commit["date"]).strftime('%d-%m-%Y %H:%M') |
|
print(f"{repo} {branch} {committed_date} {summary}") |
|
print() |
|
|
|
|
|
def fetchRepo(path): |
|
try: |
|
repo = git.Repo(path) |
|
except git.InvalidGitRepositoryError: |
|
print(f"{path} is not a valid Git repository") |
|
else: |
|
repo_name = path.split("/")[-1] |
|
|
|
for remote in repo.remotes: |
|
remote.fetch(prune=True) |
|
|
|
find_commits(repo, repo_name) |
|
|
|
|
|
def find_commits(repo, repo_name): |
|
days_ago = datetime.datetime.now() - datetime.timedelta(days=days) |
|
print(f"{repo_name}: Checking commits from {days} day(s) ago") |
|
|
|
for ref in repo.refs: |
|
if ref.is_remote(): |
|
if "HEAD" not in ref.name: |
|
branch_name = ref.name.split("/")[-1] |
|
|
|
for commit in repo.iter_commits(ref, since=days_ago): |
|
pack_per_author(repo_name, branch_name, commit) |
|
|
|
|
|
def pack_per_author(repo_name, branch_name, commit): |
|
commit_info = { |
|
"repo": repo_name, |
|
"branch": branch_name, |
|
"date": commit.committed_date, |
|
"summary": commit.summary |
|
} |
|
author_name = commit.author.name |
|
if author_name in commits_by_author: |
|
commits_by_author[author_name].append(commit_info) |
|
else: |
|
commits_by_author[author_name] = [commit_info] |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |