|
5 | 5 | Input: Project data in csv format. Use FIRST column as repo (owner/repo). |
6 | 6 |
|
7 | 7 | Outputs per repo: |
| 8 | +- repo |
| 9 | +- latest_sha |
| 10 | +- commits (total in last year) |
8 | 11 | - stars |
9 | | -- latest commit SHA |
10 | 12 | - commits per month for past 12 months (12 columns, YYYY-MM) |
11 | 13 | (computed from /stats/commit_activity weekly totals; fast) |
12 | 14 | - average commits/month over last 6 months |
@@ -201,22 +203,25 @@ def get_commit_activity_weeks(session: requests.Session, repo: str, max_retries: |
201 | 203 | raise RuntimeError(f"stats/commit_activity not ready after {max_retries} retries for {repo}") |
202 | 204 |
|
203 | 205 |
|
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]: |
205 | 207 | """ |
206 | 208 | weeks: list of 52 objects: {"total": int, "week": unix_ts, "days":[...]} |
207 | 209 | We attribute each week's 'total' to the month containing the week start date. |
| 210 | + Also returns total commits (sum of all weeks). |
208 | 211 | """ |
209 | 212 | totals = {m: 0 for m in month_labels} |
| 213 | + total_commits = 0 |
210 | 214 | for w in weeks: |
211 | 215 | ts = w.get("week") |
212 | 216 | total = int(w.get("total", 0)) |
| 217 | + total_commits += total |
213 | 218 | if ts is None: |
214 | 219 | continue |
215 | 220 | dt = datetime.fromtimestamp(int(ts), tz=timezone.utc) |
216 | 221 | mk = month_label(dt) |
217 | 222 | if mk in totals: |
218 | 223 | totals[mk] += total |
219 | | - return [totals[m] for m in month_labels] |
| 224 | + return [totals[m] for m in month_labels], total_commits |
220 | 225 |
|
221 | 226 |
|
222 | 227 | def main() -> int: |
@@ -251,8 +256,9 @@ def main() -> int: |
251 | 256 |
|
252 | 257 | fieldnames = [ |
253 | 258 | "repo", |
254 | | - "stars", |
255 | 259 | "latest_sha", |
| 260 | + "commits", |
| 261 | + "stars", |
256 | 262 | *[f"commits_{m}" for m in labels], |
257 | 263 | "avg_commits_last_6_months", |
258 | 264 | "top1_login", |
@@ -287,7 +293,8 @@ def main() -> int: |
287 | 293 |
|
288 | 294 | log(" fetching commit_activity stats (fast)") |
289 | 295 | 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 |
291 | 298 | for m, c in zip(labels, counts): |
292 | 299 | row[f"commits_{m}"] = c |
293 | 300 | row["avg_commits_last_6_months"] = sum(counts[-6:]) / 6.0 |
|
0 commit comments