-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add metrics #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Add metrics #2
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/node_modules | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
This directory contains some scripts and data for generating metrics about the work of Open Web Docs. | ||||||
|
||||||
It's got three subdirectories: *query*, *data*, and *analyse*. | ||||||
|
||||||
## query | ||||||
|
||||||
This contains a script that will fetch all PRs from mdn/content and just log them as a huge JSON array. It takes a few minutes to run. You will need a [personal access token from GitHub](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) to use this script. | ||||||
|
||||||
Then you pass the token in like this: | ||||||
|
||||||
``` | ||||||
node query-prs.js MY-TOKEN-HERE | ||||||
``` | ||||||
|
||||||
It's (obviously) advisable not to run this again and again, but to run it once, then analyse the results at your leisure. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
## data | ||||||
|
||||||
This contains a data file called "organizations.json". | ||||||
|
||||||
The "organizations.json" file contains an object each of whose keys represents an organization. The key is the organization name. Each organization object lists the GitHub usernames for people in that organization for each month we are interested in. | ||||||
|
||||||
## analyse | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
This contains a script that figures out, month by month, which PRs were files by members of a particular organization listed in "organizations.json". Note that it expects to see "prs.json" in "data", but that file is not checked into GitHub because it's too big. You'll need to get your own copy of that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const fs = require('fs'); | ||
|
||
function initializeBuckets(json) { | ||
|
||
const buckets = { | ||
'2021-01': [], | ||
'2021-02': [], | ||
'2021-03': [], | ||
'2021-04': [], | ||
'2021-05': [], | ||
'2021-06': [], | ||
'2021-07': [], | ||
'2021-08': [], | ||
'2021-09': [], | ||
'2021-10': [], | ||
'2021-11': [], | ||
'2021-12': [], | ||
'2022-01': [], | ||
'2022-02': [], | ||
'2022-03': [] | ||
} | ||
|
||
for (const pr of json) { | ||
const prefix = pr.created_at.slice(0, 7); | ||
const bucket = buckets[prefix]; | ||
if (!bucket) continue; | ||
const creatorIndex = bucket.findIndex(contributor => contributor.name === pr.user.login); | ||
if (creatorIndex === -1) { | ||
bucket.push({ | ||
name: pr.user.login, | ||
count: 1 | ||
}); | ||
} else { | ||
bucket[creatorIndex].count++; | ||
} | ||
} | ||
|
||
return buckets; | ||
} | ||
|
||
function analyse(buckets, organization) { | ||
|
||
for (const bucketName of Object.keys(buckets)) { | ||
const team = organization[bucketName]; | ||
const users = buckets[bucketName].filter(user => team.includes(user.name)); | ||
const contributions = users.reduce((previousValue, currentValue) => previousValue + currentValue.count, 0) | ||
console.log(`${bucketName}: ${contributions}`); | ||
} | ||
|
||
} | ||
|
||
const prJSON = fs.readFileSync('../data/prs.json', 'utf8'); | ||
const prs = JSON.parse(prJSON); | ||
|
||
const buckets = initializeBuckets(prs); | ||
|
||
const orgJSON = fs.readFileSync('../data/organizations.json', 'utf8'); | ||
const organizations = JSON.parse(orgJSON); | ||
|
||
analyse(buckets, organizations['owd']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"owd": { | ||
"2021-01": ["Elchi3"], | ||
"2021-02": ["Elchi3", "wbamberg"], | ||
"2021-03": ["Elchi3", "wbamberg"], | ||
"2021-04": ["Elchi3", "wbamberg"], | ||
"2021-05": ["Elchi3", "wbamberg"], | ||
"2021-06": ["Elchi3", "wbamberg", "teoli2003"], | ||
"2021-07": ["Elchi3", "wbamberg", "teoli2003"], | ||
"2021-08": ["Elchi3", "wbamberg", "teoli2003", "estelle"], | ||
"2021-09": ["Elchi3", "wbamberg", "teoli2003", "estelle"], | ||
"2021-10": ["Elchi3", "wbamberg", "teoli2003", "estelle"], | ||
"2021-11": ["Elchi3", "wbamberg", "teoli2003", "estelle"], | ||
"2021-12": ["Elchi3", "wbamberg", "teoli2003", "estelle"], | ||
"2022-01": ["Elchi3", "wbamberg", "teoli2003", "estelle", "queengooborg"], | ||
"2022-02": ["Elchi3", "wbamberg", "teoli2003", "estelle", "queengooborg"], | ||
"2022-03": ["Elchi3", "wbamberg", "teoli2003", "estelle", "queengooborg"] | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "openwebdocs/metrics/query", | ||
"version": "0.0.1", | ||
"repository": "https://github.com/openwebdocs/scripts/", | ||
"license": "MPL-2.0", | ||
"author": "Open Web Docs", | ||
"dependencies": { | ||
"node-fetch": "^2.6.7" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fetch = require('node-fetch'); | ||
|
||
const startURL = 'https://api.github.com/repos/mdn/content/pulls?state=all&per_page=100'; | ||
|
||
function getNextURL(link) { | ||
const bits = link.split(",").map(bit => bit.trim()); | ||
const next = bits.find( bit => bit.split(';')[1] === ' rel=\"next\"'); | ||
if (next) { | ||
return next.split(';')[0].slice(1, -1); | ||
} | ||
return null; | ||
} | ||
|
||
let all = []; | ||
|
||
async function get(url, token) { | ||
|
||
const requestHeaders = { | ||
Authorization: `token ${token}` | ||
}; | ||
|
||
const r = await fetch(url, {method:'GET', headers: requestHeaders}); | ||
const json = await r.json(); | ||
all = all.concat(json); | ||
|
||
const link = r.headers.get("Link"); | ||
const next = getNextURL(link); | ||
if (next) { | ||
get(next, token); | ||
} else { | ||
console.log(JSON.stringify(all, null, '\t')); | ||
} | ||
|
||
} | ||
|
||
const token = process.argv[2]; | ||
|
||
get(startURL, token); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.