-
Notifications
You must be signed in to change notification settings - Fork 2
/
count_committers.js
36 lines (26 loc) · 1.46 KB
/
count_committers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// count the number of committers for the GHAS billing
// https://docs.github.com/en/billing/managing-billing-for-github-advanced-security/about-billing-for-github-advanced-security
const fetch = require("node-fetch");
// https://github.com/settings/tokens/new
// Scope: role
var TOKEN = "...";
var owner = "ThibaudLopez";
var repo = "GHAS-canary";
// Get all contributor commit activity
// https://docs.github.com/en/rest/reference/repos#get-all-contributor-commit-activity
var url = `https://api.github.com/repos/${owner}/${repo}/stats/contributors`;
var contributors = (await (await fetch(url, { headers: { Authorization: `token ${TOKEN}` }})).json());
// calculate from/to weeks; convert from ms to s to match GitHub format
var from = Math.round(((new Date()).getTime() - 90*24*3600*1000) / 1000); // 90 days ago
var to = Math.round((new Date()) / 1000); // today
// filter from/to
var committers = contributors.filter(contributor => contributor.weeks.find(week => week.w >= from && week.w <= to && week.c > 0)).map(contributor => contributor.author.login);
/*
compare with:
repo > Insights > Contributors > Contributions: Commits
https://github.com/{owner}/{repo}/graphs/contributors?from={yyyy-mm-dd}&to={yyyy-mm-dd}&type=c
owner > Billing & plans > GitHub Advanced Security
https://github.com/organizations/{owner}/settings/billing
owner > Security & analysis > Configure security and analysis features
https://github.com/organizations/{owner}/settings/security_analysis
*/