Initial commit: Odoo timesheet automation scripts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
87
git_commits.py
Normal file
87
git_commits.py
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Ambil commit dari beberapa repo dan tampilkan per project."""
|
||||
|
||||
import subprocess
|
||||
import argparse
|
||||
from datetime import date, timedelta
|
||||
from collections import defaultdict
|
||||
|
||||
REPOS = [
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_CPONE/BE_CPONE", "project": "CPONE"},
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_CPONE/FE_CPONE", "project": "CPONE"},
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_CPONE_DASHBOARD", "project": "CPONE"},
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_IBL", "project": "IBL"},
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_KD", "project": "Support Kedungdoro"},
|
||||
{"path": "/Users/fajrihardhitamurti/REPO_GITLAB_PRAMITA/bisone", "project": "Support Pramita"},
|
||||
]
|
||||
|
||||
|
||||
def get_commits(repo_path: str, author: str, since: str, until: str) -> list[dict]:
|
||||
cmd = [
|
||||
"git", "-C", repo_path,
|
||||
"log",
|
||||
f"--author={author}",
|
||||
f"--after={since}",
|
||||
f"--before={until}",
|
||||
"--format=%h|%ad|%s",
|
||||
"--date=short",
|
||||
]
|
||||
try:
|
||||
out = subprocess.check_output(cmd, stderr=subprocess.DEVNULL, text=True)
|
||||
except subprocess.CalledProcessError:
|
||||
return []
|
||||
|
||||
commits = []
|
||||
for line in out.strip().splitlines():
|
||||
if not line:
|
||||
continue
|
||||
parts = line.split("|", 2)
|
||||
if len(parts) == 3:
|
||||
commits.append({"hash": parts[0], "date": parts[1], "message": parts[2]})
|
||||
return commits
|
||||
|
||||
|
||||
def main():
|
||||
today = date.today().isoformat()
|
||||
yesterday = (date.today() - timedelta(days=1)).isoformat()
|
||||
|
||||
parser = argparse.ArgumentParser(description="Ambil commit dari semua repo per project")
|
||||
parser.add_argument("--author", required=True, help="Filter by git author name/email, e.g. 'fajri'")
|
||||
parser.add_argument("--since", default=today, help=f"Tanggal mulai YYYY-MM-DD (default: hari ini {today})")
|
||||
parser.add_argument("--until", default=today, help=f"Tanggal akhir YYYY-MM-DD (default: hari ini {today})")
|
||||
args = parser.parse_args()
|
||||
|
||||
# --until perlu +1 hari karena git --before bersifat eksklusif
|
||||
until_exclusive = (date.fromisoformat(args.until) + timedelta(days=1)).isoformat()
|
||||
|
||||
print(f"Author : {args.author}")
|
||||
print(f"Periode: {args.since} s/d {args.until}")
|
||||
print("=" * 60)
|
||||
|
||||
grouped = defaultdict(list)
|
||||
for repo in REPOS:
|
||||
commits = get_commits(repo["path"], args.author, args.since, until_exclusive)
|
||||
repo_name = repo["path"].split("/")[-1]
|
||||
for c in commits:
|
||||
grouped[repo["project"]].append({**c, "repo": repo_name})
|
||||
|
||||
if not any(grouped.values()):
|
||||
print("Tidak ada commit ditemukan.")
|
||||
return
|
||||
|
||||
total = 0
|
||||
for project, commits in grouped.items():
|
||||
if not commits:
|
||||
continue
|
||||
print(f"\n[{project}] — {len(commits)} commit")
|
||||
print("-" * 60)
|
||||
for c in commits:
|
||||
print(f" {c['date']} {c['hash']} ({c['repo']})")
|
||||
print(f" {c['message']}")
|
||||
total += len(commits)
|
||||
|
||||
print(f"\nTotal: {total} commit dari {len([p for p in grouped if grouped[p]])} project")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user