@@ -6,6 +6,7 @@ const yargs = require('yargs')
66const chalk = require ( 'chalk' )
77const inquirer = require ( 'inquirer' )
88const didYouMean = require ( 'didyoumean' )
9+ const { info, warn, use} = require ( 'nclr' )
910
1011const init = require ( './init' )
1112const generate = require ( './generate' )
@@ -192,7 +193,8 @@ async function fetchContributors(argv) {
192193 const {
193194 reviewers,
194195 commitAuthors,
195- issueCreators /* , prCreators */ ,
196+ issueCreators,
197+ prCreators,
196198 } = await getContributors ( argv . projectOwner , argv . projectName , true )
197199 const args = { ...argv , _ : [ ] }
198200 const contributorsToAdd = [ ]
@@ -202,18 +204,21 @@ async function fetchContributors(argv) {
202204 contributorsToAdd . push ( { login : usr . login , contributions : [ 'review' ] } )
203205
204206 console . log (
205- `Adding ${ chalk . underline ( 'Reviewer' ) } ${ chalk . blue ( usr . login ) } ` ,
207+ `Including ${ chalk . underline ( 'Reviewer' ) } ${ use ( 'info' , usr . login ) } ` ,
206208 )
207209 } )
208210
209211 const guessCategories = ( item , itemType , contributor ) => {
210212 const guessedCategory = learner
211213 . classify ( item )
212- . find ( ctr => ctr && ctr !== 'null' )
214+ . find ( ctr => ctr && ctr !== 'null' && ctr !== 'undefined' )
213215
214216 if ( ! guessedCategory ) {
215- console . warn (
216- `Oops, I couldn't find any category for the "${ item } " ${ itemType } ` ,
217+ warn (
218+ `Oops, I couldn't find any category for the "${ use (
219+ 'inp' ,
220+ item ,
221+ ) } " ${ itemType } `,
217222 )
218223
219224 return
@@ -223,22 +228,21 @@ async function fetchContributors(argv) {
223228 contributor . contributions . push ( guessedCategory )
224229
225230 console . log (
226- `Adding ${ chalk . blue ( contributor . login ) } for ${ chalk . underline (
231+ `Including ${ use ( 'info' , contributor . login ) } for ${ chalk . underline (
227232 guessedCategory ,
228- ) } `,
233+ ) } , based on " ${ use ( 'inp' , item ) } " `,
229234 )
230235 }
231236 }
232237
238+ info ( 'Looking at issue creators' )
233239 issueCreators . forEach ( usr => {
234240 const contributor = {
235241 login : usr . login ,
236242 contributions : [ ] ,
237243 }
238- //TODO: Look at the titles field and categories based on that.
239244
240245 usr . labels . forEach ( label => guessCategories ( label , 'label' , contributor ) )
241-
242246 usr . titles . forEach ( title => guessCategories ( title , 'title' , contributor ) )
243247
244248 const existingContributor = contributorsToAdd . find (
@@ -252,14 +256,35 @@ async function fetchContributors(argv) {
252256 }
253257 } )
254258
255- //TODO Look at prCreators (including its titles field) and add contributions from there
259+ info ( 'Looking at PR creators' )
260+ prCreators . forEach ( usr => {
261+ const contributor = {
262+ login : usr . login ,
263+ contributions : [ ] ,
264+ }
265+
266+ usr . labels . forEach ( label => guessCategories ( label , 'PR label' , contributor ) )
267+ usr . titles . forEach ( title => guessCategories ( title , 'PR title' , contributor ) )
268+
269+ const existingContributor = contributorsToAdd . find (
270+ ctr => ctr . login === usr . login ,
271+ )
272+
273+ if ( existingContributor ) {
274+ existingContributor . contributions . push ( ...contributor . contributions )
275+ } else {
276+ contributorsToAdd . push ( contributor )
277+ }
278+ } )
279+
280+ info ( 'Looking at commit authors' )
256281 commitAuthors . forEach ( usr => {
257282 const existingContributor = contributorsToAdd . find (
258283 ctr => ctr . login === usr . login ,
259284 )
260285
261286 if ( existingContributor ) {
262- // There's no label or commit message info so use only code for now
287+ // TODO: See how the commit message could be added (this may require the full output) to not just assume it's a code contribution
263288 if ( ! existingContributor . contributions . includes ( 'code' ) ) {
264289 existingContributor . contributions . push ( 'code' )
265290 }
@@ -270,8 +295,12 @@ async function fetchContributors(argv) {
270295
271296 // TODO: Roll onto other contribution categories following https://www.draw.io/#G1uL9saIuZl3rj8sOo9xsLOPByAe28qhwa
272297
298+ info ( 'Finalising' )
273299 for ( const contributor of contributorsToAdd ) {
274- if ( ! contributor . contributions . length ) {
300+ const isDependabotDuplicates = / d e p e n d a b o t ( \[ b o t \] | - \w + ) / . test (
301+ contributor . login ,
302+ )
303+ if ( ! contributor . contributions . length || isDependabotDuplicates ) {
275304 console . log ( 'Skipping' , contributor . login )
276305
277306 continue
@@ -281,7 +310,7 @@ async function fetchContributors(argv) {
281310 const contributions = contributor . contributions . join ( '/' )
282311
283312 console . log (
284- `Adding ${ chalk . blue ( contributor . login ) } for ${ chalk . underline (
313+ `Adding ${ use ( 'info' , contributor . login ) } for ${ chalk . underline (
285314 contributions ,
286315 ) } `,
287316 )
@@ -293,7 +322,7 @@ async function fetchContributors(argv) {
293322 await addContribution ( args )
294323 } catch ( error ) {
295324 console . error (
296- `Adding ${ chalk . blue ( contributor . login ) } for ${ chalk . underline (
325+ `Adding ${ use ( 'info' , contributor . login ) } for ${ chalk . underline (
297326 contributions ,
298327 ) } Failed: ${ JSON . stringify ( error ) } `,
299328 )
0 commit comments