Skip to content

Commit 0c4a96f

Browse files
authored
List Co-Committers as Learning Path Contributors (InnerSourceCommons#380)
* When someone leaves a commit suggestion that is merged, they show up as a 'co-author' on that commit * GitHub exposes this information in their graph API (https://bit.ly/3cdyYQQ)
1 parent 6f3b801 commit 0c4a96f

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

scripts/get_contributors.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ const graphqlWithAuth = graphql.defaults({
88
})
99

1010
module.exports = async function (filepath) {
11-
const contributors = await graphqlWithAuth(
11+
const { repository: { object: { history }}} = await graphqlWithAuth(
1212
`{
1313
repository(owner: "InnerSourceCommons", name: "InnerSourceLearningPath") {
1414
object(expression: "master") {
1515
... on Commit {
1616
history(first: 100, path: "${filepath}") {
1717
totalCount
1818
nodes {
19-
author {
20-
name
21-
user {
19+
authors(first: 100) {
20+
nodes {
2221
name
23-
url
22+
user {
23+
name
24+
url
25+
}
2426
}
2527
}
2628
}
@@ -31,18 +33,22 @@ module.exports = async function (filepath) {
3133
}`
3234
)
3335

34-
const history = contributors.repository.object.history
35-
3636
if (history.totalCount > 100) {
3737
throw Error('This script needs updating to handle >100 commits')
3838
}
3939

40-
return Object.values(history.nodes.reduce((acc, { author }) => {
41-
const name = (author.user && author.user.name) || author.name
42-
acc[name] = {
43-
name,
44-
url: author.user && author.user.url
45-
}
46-
return acc
47-
}, {}))
48-
}
40+
return Object.values(
41+
history.nodes.flatMap(({ authors }) => {
42+
return authors.nodes.map(author => {
43+
return {
44+
name: (author.user && author.user.name) || author.name,
45+
url: author.user && author.user.url
46+
}
47+
})
48+
}).reduce((accumulator, user) => {
49+
// Dedupe users
50+
accumulator[user.name] = user
51+
return accumulator
52+
}, {})
53+
)
54+
}

0 commit comments

Comments
 (0)