@@ -5,6 +5,7 @@ const path = require('path')
55const  yargs  =  require ( 'yargs' ) 
66const  chalk  =  require ( 'chalk' ) 
77const  inquirer  =  require ( 'inquirer' ) 
8+ const  didYouMean  =  require ( 'didyoumean' ) 
89
910const  init  =  require ( './init' ) 
1011const  generate  =  require ( './generate' ) 
@@ -24,12 +25,22 @@ const yargv = yargs
2425  . alias ( 'v' ,  'version' ) 
2526  . version ( ) 
2627  . recommendCommands ( ) 
27-   . command ( 'generate' ,  `Generate the list of contributors\n\nUSAGE: all-contributors generate` ) 
28-   . command ( 'add' ,  `Add a new contributor\n\nUSAGE: all-contributors add <username> <comma-separated contributions>` ) 
29-   . command ( 'init' ,  `Prepare the project to be used with this tool\n\nUSAGE: all-contributors init` ) 
28+   . command ( 
29+     'generate' , 
30+     `Generate the list of contributors\n\nUSAGE: all-contributors generate` , 
31+   ) 
32+   . command ( 
33+     'add' , 
34+     `Add a new contributor\n\nUSAGE: all-contributors add <username> <comma-separated contributions>` , 
35+   ) 
36+   . command ( 
37+     'init' , 
38+     `Prepare the project to be used with this tool\n\nUSAGE: all-contributors init` , 
39+   ) 
3040  . command ( 
3141    'check' , 
32-     `Compare contributors from the repository with the ones credited in .all-contributorsrc'\n\nUSAGE: all-contributors check` ) 
42+     `Compare contributors from the repository with the ones credited in .all-contributorsrc'\n\nUSAGE: all-contributors check` , 
43+   ) 
3344  . boolean ( 'commit' ) 
3445  . default ( 'files' ,  [ 'README.md' ] ) 
3546  . default ( 'contributorsPerLine' ,  7 ) 
@@ -177,10 +188,11 @@ async function checkContributors(argv) {
177188} 
178189
179190async  function  fetchContributors ( argv )  { 
180-   const  { reviewers,  commitAuthors,  issueCreators}  =  await  getContributors ( 
181-     argv . projectOwner , 
182-     argv . projectName , 
183-   ) 
191+   const  { 
192+     reviewers, 
193+     commitAuthors, 
194+     issueCreators /* , prCreators */ , 
195+   }  =  await  getContributors ( argv . projectOwner ,  argv . projectName ,  true ) 
184196  const  args  =  { ...argv ,  _ : [ ] } 
185197  const  contributorsToAdd  =  [ ] 
186198  const  learner  =  await  getLearner ( ) 
@@ -193,35 +205,40 @@ async function fetchContributors(argv) {
193205    ) 
194206  } ) 
195207
208+   const  guessCategories  =  ( item ,  itemType ,  contributor )  =>  { 
209+     const  guessedCategory  =  learner 
210+       . classify ( item ) 
211+       . find ( ctr  =>  ctr  &&  ctr  !==  'null' ) 
212+ 
213+     if  ( ! guessedCategory )  { 
214+       console . warn ( 
215+         `Oops, I couldn't find any category for the "${ item } ${ itemType }  , 
216+       ) 
217+ 
218+       return 
219+     } 
220+ 
221+     if  ( ! contributor . contributions . includes ( guessedCategory ) )  { 
222+       contributor . contributions . push ( guessedCategory ) 
223+ 
224+       console . log ( 
225+         `Adding ${ chalk . blue ( contributor . login ) } ${ chalk . underline (  
226+           guessedCategory ,  
227+         ) }  `, 
228+       ) 
229+     } 
230+   } 
231+ 
196232  issueCreators . forEach ( usr  =>  { 
197233    const  contributor  =  { 
198234      login : usr . login , 
199235      contributions : [ ] , 
200236    } 
237+     //TODO: Look at the titles field and categories based on that. 
201238
202-     usr . labels . forEach ( lbl  =>  { 
203-       const  guessedCategory  =  learner 
204-         . classify ( lbl ) 
205-         . find ( ctr  =>  ctr  &&  ctr  !==  'null' ) 
206- 
207-       if  ( ! guessedCategory )  { 
208-         console . warn ( 
209-           `Oops, I couldn't find any category for the "${ lbl }  , 
210-         ) 
211- 
212-         return 
213-       } 
214- 
215-       if  ( ! contributor . contributions . includes ( guessedCategory ) )  { 
216-         contributor . contributions . push ( guessedCategory ) 
239+     usr . labels . forEach ( label  =>  guessCategories ( label ,  'label' ,  contributor ) ) 
217240
218-         console . log ( 
219-           `Adding ${ chalk . blue ( usr . login ) } ${ chalk . underline (  
220-             guessedCategory ,  
221-           ) }  `, 
222-         ) 
223-       } 
224-     } ) 
241+     usr . titles . forEach ( title  =>  guessCategories ( title ,  'title' ,  contributor ) ) 
225242
226243    const  existingContributor  =  contributorsToAdd . find ( 
227244      ctr  =>  ctr . login  ===  usr . login , 
@@ -234,6 +251,7 @@ async function fetchContributors(argv) {
234251    } 
235252  } ) 
236253
254+   //TODO Look at prCreators (including its titles field) and add contributions from there 
237255  commitAuthors . forEach ( usr  =>  { 
238256    const  existingContributor  =  contributorsToAdd . find ( 
239257      ctr  =>  ctr . login  ===  usr . login , 
@@ -331,6 +349,7 @@ promptForCommand(yargv)
331349      case  'fetch' :
332350        return  fetchContributors ( yargv ) 
333351      default :
352+         suggestCommands ( command ) 
334353        throw  new  Error ( `Unknown command ${ command }  ) 
335354    } 
336355  } ) 
0 commit comments