Skip to content

Instantly share code, notes, and snippets.

@ljstrnadiii
Created December 2, 2025 19:54
Show Gist options
  • Select an option

  • Save ljstrnadiii/090fcbab6d86a481cf67d718d8ab1051 to your computer and use it in GitHub Desktop.

Select an option

Save ljstrnadiii/090fcbab6d86a481cf67d718d8ab1051 to your computer and use it in GitHub Desktop.
Summarize Work Over A Week
import json
import subprocess
import sys
from datetime import UTC, datetime, timedelta
from typing import Any
def gh_query(args: list[str]) -> Any:
"""Run gh CLI and return parsed JSON"""
result = subprocess.check_output(["gh"] + args)
return json.loads(result)
def get_merged_prs(org: str, days: int = 7, author: str | None = None) -> list[dict[str, Any]]:
since = (datetime.now(UTC) - timedelta(days=days)).strftime("%Y-%m-%dT%H:%M:%SZ")
args = [
"search",
"prs",
"--owner",
org,
"--merged",
"--json",
"title,url,closedAt,repository,author",
]
if author:
args.extend(["--author", author])
prs = gh_query(args)
return [
{
"title": pr["title"],
"url": pr["url"],
"repo": pr["repository"]["name"],
"author": pr["author"]["login"] if pr.get("author") else "unknown",
"date": datetime.fromisoformat(pr["closedAt"]).date(),
}
for pr in prs
if pr.get("closedAt") and pr["closedAt"] >= since
]
def get_open_prs(org: str, author: str | None = None) -> list[dict[str, Any]]:
args = [
"search",
"prs",
"--owner",
org,
"--state",
"open",
"--json",
"title,url,createdAt,repository,author",
]
if author:
args.extend(["--author", author])
prs = gh_query(args)
return [
{
"title": pr["title"],
"url": pr["url"],
"repo": pr["repository"]["name"],
"author": pr["author"]["login"] if pr.get("author") else "unknown",
"date": datetime.fromisoformat(pr["createdAt"]).date(),
}
for pr in prs
]
def get_closed_prs(org: str, days: int = 7, author: str | None = None) -> list[dict[str, Any]]:
since = (datetime.now(UTC) - timedelta(days=days)).strftime("%Y-%m-%dT%H:%M:%SZ")
args = [
"search",
"prs",
"--owner",
org,
"--state",
"closed",
"--json",
"title,url,closedAt,repository,author",
]
if author:
args.extend(["--author", author])
prs = gh_query(args)
return [
{
"title": pr["title"],
"url": pr["url"],
"repo": pr["repository"]["name"],
"author": pr["author"]["login"] if pr.get("author") else "unknown",
"date": datetime.fromisoformat(pr["closedAt"]).date(),
}
for pr in prs
if pr.get("closedAt") and pr["closedAt"] >= since
]
if __name__ == "__main__":
# Require org and username as command line arguments
if len(sys.argv) != 3:
print("Usage: python3 work.py <org> <github_username>")
print("Example: python3 work.py wherobots ljstrnadiii")
sys.exit(1)
org = sys.argv[1]
author = sys.argv[2]
merged = get_merged_prs(org, days=7, author=author)
closed = get_closed_prs(org, days=7, author=author)
open_prs = get_open_prs(org, author=author)
# Get all repos that have any PRs
all_repos = sorted({pr["repo"] for pr in merged + closed + open_prs})
if not all_repos:
print(f"No PRs found for @{author} in {org}.\n")
sys.exit(0)
for repo in all_repos:
repo_merged = [pr for pr in merged if pr["repo"] == repo]
repo_closed = [pr for pr in closed if pr["repo"] == repo]
repo_open = [pr for pr in open_prs if pr["repo"] == repo]
# Filter out merged PRs from closed PRs to avoid duplication
repo_closed_only = [pr for pr in repo_closed if pr not in repo_merged]
if repo_merged or repo_closed_only or repo_open:
print(f"### **{repo}**")
# Show merged PRs first
if repo_merged:
print(f"\n✅ **Merged** ({len(repo_merged)})")
for pr in repo_merged:
print(f"- [{pr['title']}]({pr['url']}) - merged `{pr['date']}`")
# Show closed (non-merged) PRs
if repo_closed_only:
print(f"\n❌ **Closed** ({len(repo_closed_only)})")
for pr in repo_closed_only:
print(f"- [{pr['title']}]({pr['url']}) - closed `{pr['date']}`")
# Show open PRs
if repo_open:
print(f"\n📖 **Open** ({len(repo_open)})")
for pr in repo_open:
print(f"- [{pr['title']}]({pr['url']}) - opened `{pr['date']}`")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment