Skip to content

Commit b0e1213

Browse files
committed
feat(cli): include pr based contributions
1 parent ace4970 commit b0e1213

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"json-fixer": "^1.6.8",
5454
"lodash": "^4.11.2",
5555
"name-your-contributors": "^3.10.0",
56+
"nclr": "^2.2.5",
5657
"node-fetch": "^2.6.0",
5758
"pify": "^5.0.0",
5859
"yargs": "^15.0.1",

src/cli.js

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const yargs = require('yargs')
66
const chalk = require('chalk')
77
const inquirer = require('inquirer')
88
const didYouMean = require('didyoumean')
9+
const {info, warn, use} = require('nclr')
910

1011
const init = require('./init')
1112
const generate = require('./generate')
@@ -191,7 +192,8 @@ async function fetchContributors(argv) {
191192
const {
192193
reviewers,
193194
commitAuthors,
194-
issueCreators /* , prCreators */,
195+
issueCreators,
196+
prCreators,
195197
} = await getContributors(argv.projectOwner, argv.projectName, true)
196198
const args = {...argv, _: []}
197199
const contributorsToAdd = []
@@ -201,18 +203,21 @@ async function fetchContributors(argv) {
201203
contributorsToAdd.push({login: usr.login, contributions: ['review']})
202204

203205
console.log(
204-
`Adding ${chalk.underline('Reviewer')} ${chalk.blue(usr.login)}`,
206+
`Including ${chalk.underline('Reviewer')} ${use('info', usr.login)}`,
205207
)
206208
})
207209

208210
const guessCategories = (item, itemType, contributor) => {
209211
const guessedCategory = learner
210212
.classify(item)
211-
.find(ctr => ctr && ctr !== 'null')
213+
.find(ctr => ctr && ctr !== 'null' && ctr !== 'undefined')
212214

213215
if (!guessedCategory) {
214-
console.warn(
215-
`Oops, I couldn't find any category for the "${item}" ${itemType}`,
216+
warn(
217+
`Oops, I couldn't find any category for the "${use(
218+
'inp',
219+
item,
220+
)}" ${itemType}`,
216221
)
217222

218223
return
@@ -222,22 +227,21 @@ async function fetchContributors(argv) {
222227
contributor.contributions.push(guessedCategory)
223228

224229
console.log(
225-
`Adding ${chalk.blue(contributor.login)} for ${chalk.underline(
230+
`Including ${use('info', contributor.login)} for ${chalk.underline(
226231
guessedCategory,
227-
)}`,
232+
)}, based on "${use('inp', item)}"`,
228233
)
229234
}
230235
}
231236

237+
info('Looking at issue creators')
232238
issueCreators.forEach(usr => {
233239
const contributor = {
234240
login: usr.login,
235241
contributions: [],
236242
}
237-
//TODO: Look at the titles field and categories based on that.
238243

239244
usr.labels.forEach(label => guessCategories(label, 'label', contributor))
240-
241245
usr.titles.forEach(title => guessCategories(title, 'title', contributor))
242246

243247
const existingContributor = contributorsToAdd.find(
@@ -251,14 +255,35 @@ async function fetchContributors(argv) {
251255
}
252256
})
253257

254-
//TODO Look at prCreators (including its titles field) and add contributions from there
258+
info('Looking at PR creators')
259+
prCreators.forEach(usr => {
260+
const contributor = {
261+
login: usr.login,
262+
contributions: [],
263+
}
264+
265+
usr.labels.forEach(label => guessCategories(label, 'PR label', contributor))
266+
usr.titles.forEach(title => guessCategories(title, 'PR title', contributor))
267+
268+
const existingContributor = contributorsToAdd.find(
269+
ctr => ctr.login === usr.login,
270+
)
271+
272+
if (existingContributor) {
273+
existingContributor.contributions.push(...contributor.contributions)
274+
} else {
275+
contributorsToAdd.push(contributor)
276+
}
277+
})
278+
279+
info('Looking at commit authors')
255280
commitAuthors.forEach(usr => {
256281
const existingContributor = contributorsToAdd.find(
257282
ctr => ctr.login === usr.login,
258283
)
259284

260285
if (existingContributor) {
261-
// There's no label or commit message info so use only code for now
286+
// TODO: See how the commit message could be added (this may require the full output) to not just assume it's a code contribution
262287
if (!existingContributor.contributions.includes('code')) {
263288
existingContributor.contributions.push('code')
264289
}
@@ -269,8 +294,12 @@ async function fetchContributors(argv) {
269294

270295
// TODO: Roll onto other contribution categories following https://www.draw.io/#G1uL9saIuZl3rj8sOo9xsLOPByAe28qhwa
271296

297+
info('Finalising')
272298
for (const contributor of contributorsToAdd) {
273-
if (!contributor.contributions.length) {
299+
const isDependabotDuplicates = /dependabot(\[bot\]|-\w+)/.test(
300+
contributor.login,
301+
)
302+
if (!contributor.contributions.length || isDependabotDuplicates) {
274303
console.log('Skipping', contributor.login)
275304

276305
continue
@@ -280,7 +309,7 @@ async function fetchContributors(argv) {
280309
const contributions = contributor.contributions.join('/')
281310

282311
console.log(
283-
`Adding ${chalk.blue(contributor.login)} for ${chalk.underline(
312+
`Adding ${use('info', contributor.login)} for ${chalk.underline(
284313
contributions,
285314
)}`,
286315
)
@@ -292,7 +321,7 @@ async function fetchContributors(argv) {
292321
await addContribution(args)
293322
} catch (error) {
294323
console.error(
295-
`Adding ${chalk.blue(contributor.login)} for ${chalk.underline(
324+
`Adding ${use('info', contributor.login)} for ${chalk.underline(
296325
contributions,
297326
)} Failed: ${JSON.stringify(error)}`,
298327
)

0 commit comments

Comments
 (0)