89 lines
3.4 KiB
Python
89 lines
3.4 KiB
Python
#!/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/LIVE_CPONE", "project": "CPONE"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_CPONE_DASHBOARD", "project": "CPONE"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_IBL/BE_IBL/one-api-lab", "project": "IBL"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_IBL/FE_IBL", "project": "IBL"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_IBL/MERGE_REPORT/ibl_merge_report_service", "project": "IBL"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_GITEA_KD", "project": "Support Kedungdoro"},
|
|
{"path": "/Users/fajrihardhitamurti/REPO_GITLAB_PRAMITA/bisone", "project": "Support Pramita"},
|
|
{"path": "/Users/fajrihardhitamurti/SAS_TASK", "project": "SAS"},
|
|
]
|
|
|
|
|
|
def get_commits(repo_path: str, author: str, since: str, until: str) -> list[dict]:
|
|
cmd = [
|
|
"git", "-C", repo_path,
|
|
"log",
|
|
f"--author={author}",
|
|
f"--since={since} 00:00:00",
|
|
f"--until={until} 23:59:59",
|
|
"--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()
|
|
|
|
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, args.until)
|
|
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()
|