Skip to content

Instantly share code, notes, and snippets.

@poetix
Created December 15, 2025 10:42
Show Gist options
  • Select an option

  • Save poetix/8d395c56e18b4d756c0dbf54237a7c7c to your computer and use it in GitHub Desktop.

Select an option

Save poetix/8d395c56e18b4d756c0dbf54237a7c7c to your computer and use it in GitHub Desktop.
commit_analysis.py
from datetime import datetime
GITLAB_URL = "https://gitlab.example.com" # adjust
PRIVATE_TOKEN = "your-token-here"
AUTHOR_EMAIL = "your.email@company.com"
SINCE = "2025-01-01T00:00:00Z"
UNTIL = "2025-12-31T23:59:59Z"
# Add project IDs you contribute to
PROJECT_IDS = [123, 456]
headers = {"PRIVATE-TOKEN": PRIVATE_TOKEN}
def get_commits(project_id):
commits = []
page = 1
while True:
resp = requests.get(
f"{GITLAB_URL}/api/v4/projects/{project_id}/repository/commits",
headers=headers,
params={
"author": AUTHOR_EMAIL,
"since": SINCE,
"until": UNTIL,
"per_page": 100,
"page": page
}
)
batch = resp.json()
if not batch:
break
commits.extend(batch)
page += 1
return commits
def get_commit_stats(project_id, sha):
resp = requests.get(
f"{GITLAB_URL}/api/v4/projects/{project_id}/repository/commits/{sha}",
headers=headers
)
return resp.json().get("stats", {})
total_additions = 0
total_deletions = 0
commit_count = 0
for project_id in PROJECT_IDS:
commits = get_commits(project_id)
for commit in commits:
stats = get_commit_stats(project_id, commit["id"])
additions = stats.get("additions", 0)
deletions = stats.get("deletions", 0)
total_additions += additions
total_deletions += deletions
commit_count += 1
print(f"{commit['short_id']} | +{additions:4d} -{deletions:4d} | {commit['title'][:50]}")
print(f"\n{'='*60}")
print(f"Commits: {commit_count}")
print(f"Additions: {total_additions:,}")
print(f"Deletions: {total_deletions:,}")
print(f"Net change: {total_additions - total_deletions:,}")
print(f"Total LOC touched: {total_additions + total_deletions:,}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment