Skip to content

Commit 41a7ba0

Browse files
committed
Update script
1 parent 1531e78 commit 41a7ba0

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

repo_activity_and_contributors/repo_activity_and_contributors.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
Input: Project data in csv format. Use FIRST column as repo (owner/repo).
66
77
Outputs per repo:
8+
- repo
9+
- latest_sha
10+
- commits (total in last year)
811
- stars
9-
- latest commit SHA
1012
- commits per month for past 12 months (12 columns, YYYY-MM)
1113
(computed from /stats/commit_activity weekly totals; fast)
1214
- average commits/month over last 6 months
@@ -201,22 +203,25 @@ def get_commit_activity_weeks(session: requests.Session, repo: str, max_retries:
201203
raise RuntimeError(f"stats/commit_activity not ready after {max_retries} retries for {repo}")
202204

203205

204-
def monthly_counts_from_weeks(weeks: List[Dict[str, Any]], month_labels: List[str]) -> List[int]:
206+
def monthly_counts_from_weeks(weeks: List[Dict[str, Any]], month_labels: List[str]) -> Tuple[List[int], int]:
205207
"""
206208
weeks: list of 52 objects: {"total": int, "week": unix_ts, "days":[...]}
207209
We attribute each week's 'total' to the month containing the week start date.
210+
Also returns total commits (sum of all weeks).
208211
"""
209212
totals = {m: 0 for m in month_labels}
213+
total_commits = 0
210214
for w in weeks:
211215
ts = w.get("week")
212216
total = int(w.get("total", 0))
217+
total_commits += total
213218
if ts is None:
214219
continue
215220
dt = datetime.fromtimestamp(int(ts), tz=timezone.utc)
216221
mk = month_label(dt)
217222
if mk in totals:
218223
totals[mk] += total
219-
return [totals[m] for m in month_labels]
224+
return [totals[m] for m in month_labels], total_commits
220225

221226

222227
def main() -> int:
@@ -251,8 +256,9 @@ def main() -> int:
251256

252257
fieldnames = [
253258
"repo",
254-
"stars",
255259
"latest_sha",
260+
"commits",
261+
"stars",
256262
*[f"commits_{m}" for m in labels],
257263
"avg_commits_last_6_months",
258264
"top1_login",
@@ -287,7 +293,8 @@ def main() -> int:
287293

288294
log(" fetching commit_activity stats (fast)")
289295
weeks = get_commit_activity_weeks(session, repo)
290-
counts = monthly_counts_from_weeks(weeks, labels)
296+
counts, total_commits = monthly_counts_from_weeks(weeks, labels)
297+
row["commits"] = total_commits
291298
for m, c in zip(labels, counts):
292299
row[f"commits_{m}"] = c
293300
row["avg_commits_last_6_months"] = sum(counts[-6:]) / 6.0

0 commit comments

Comments
 (0)