From 7d02fe55a403cfbd69c816454b638fa322734b86 Mon Sep 17 00:00:00 2001 From: Tyler Reitz Date: Mon, 28 May 2018 14:25:55 -0700 Subject: [PATCH 1/3] adds ability to remove contribution types when editing existing user --- src/.cli.js.swp | Bin 0 -> 16384 bytes src/cli.js | 32 ++++++++++++++++++------------ src/contributors/__tests__/add.js | 19 ++++++++++++++++++ src/contributors/add.js | 31 ++++++++++++++++++++--------- 4 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 src/.cli.js.swp diff --git a/src/.cli.js.swp b/src/.cli.js.swp new file mode 100644 index 0000000000000000000000000000000000000000..3789bba5e716e8efad3946207f74d0c62cd62688 GIT binary patch literal 16384 zcmeI2ON<;x8OJ-0F%axv#j+3x$+dCt^f5fDV;5Cj(>0!8ALM3Exp0r)@!2TmwR;o_V)AVmU+1MvUq(T^Fg zF%pL$RZG8}oqBxr)xRFy_4Rb8A3ZbA4tvuMuAPqa)30q`*xBE{fS*1!yS0DK1Q2LIaOIPZZ!g6F|g;5^s^-r4RruY+HJ zAA-|h4!B?!`0K~u1NaHJ3PSK0*avok_wI0<--B!54e&B}349wo4Z7fd@VAdT&X2$< z=z_<#69vlR_!TTS99WVs*U=P>^-ubZO`~kcTu7O{JUxDv~5Cq@?xV{Z};3_x- zwt@FQ1V6zG;0nk=20jPw09(MDTk+cq@C=v-p8z|+R&YCb7Xg?zz&c35yeUjPq)L*Rb!X+UGV9c+3r7A-TEXIYxH*%fEGNCFY12}_fclvd?98xF&@ z(Uu?hM}IOl$kKr4xtEJDErd7BBEj9Id#?1OJdcu+08S_Y?>@bEB|#j=ao#&ZvHPjSb8?z!Akn-KkAhf9{o{2(7}Aj z7gqWDq8BAWT!cJ#TY~4J)vnia|8u1v4SB20o_x}wM$|QtVQ!R7;kQ6lBWSYC_U&^_ z(Ts~COPH$@FfVe!Mn;hx9dVv4E=RH8nG1XD=rN41GFUmUGbWln81uzUtwzH}T{Jw_ z6Wy+vPgR4kV1D~V9@V}s1U(+CJ_NC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XsXE0SLM{I$DH@defsH38WI!Q%baPI66 z#Hlo!)jYK)S4d`h|JXDB$P@Q1yYfLp33M) z{q%hE@Jtz*p*W3>!;nGq+GG z3e(S*MzjZdqLs1FX}KLpUmNKM U^rBS}08hTxRqt>;-J`biZ%g=96#xJL literal 0 HcmV?d00001 diff --git a/src/cli.js b/src/cli.js index 636881dc..b83a5b6b 100755 --- a/src/cli.js +++ b/src/cli.js @@ -76,7 +76,12 @@ function checkContributors(argv) { const configData = util.configFile.readConfig(argv.config) return repo - .getContributors(configData.projectOwner, configData.projectName, configData.repoType, configData.repoHost) + .getContributors( + configData.projectOwner, + configData.projectName, + configData.repoType, + configData.repoHost, + ) .then(repoContributors => { const checkKey = repo.getCheckKey(configData.repoType) const knownContributions = configData.contributors.reduce((obj, item) => { @@ -130,7 +135,7 @@ function promptForCommand(argv) { message: 'What do you want to do?', choices: [ { - name: 'Add a new contributor or add a new contribution type', + name: 'Add new contributor or edit contribution type', value: 'add', }, { @@ -138,7 +143,8 @@ function promptForCommand(argv) { value: 'generate', }, { - name: 'Compare contributors from the repository with the credited ones', + name: + 'Compare contributors from the repository with the credited ones', value: 'check', }, ], @@ -155,16 +161,16 @@ function promptForCommand(argv) { promptForCommand(yargv) .then(command => { switch (command) { - case 'init': - return init() - case 'generate': - return startGeneration(yargv) - case 'add': - return addContribution(yargv) - case 'check': - return checkContributors(yargv) - default: - throw new Error(`Unknown command ${command}`) + case 'init': + return init() + case 'generate': + return startGeneration(yargv) + case 'add': + return addContribution(yargv) + case 'check': + return checkContributors(yargv) + default: + throw new Error(`Unknown command ${command}`) } }) .catch(onError) diff --git a/src/contributors/__tests__/add.js b/src/contributors/__tests__/add.js index b5cbbdf2..2e8f71ce 100644 --- a/src/contributors/__tests__/add.js +++ b/src/contributors/__tests__/add.js @@ -188,3 +188,22 @@ test(`should update an existing contributor's contributions if a new type is add }, ) }) + +test(`should update an existing contributor's contributions if an existing type is removed`, () => { + const {options} = fixtures() + const username = 'login2' + const contributions = ['code'] + + return addContributor(options, username, contributions, mockInfoFetcher).then( + contributors => { + expect(contributors.length).toBe(options.contributors.length) + expect(contributors[1]).toEqual({ + login: 'login2', + name: 'Some name', + avatar_url: 'www.avatar.url', + profile: 'www.profile.url', + contributions: ['code'], + }) + }, + ) +}) diff --git a/src/contributors/add.js b/src/contributors/add.js index a23a2ddf..568f71b5 100644 --- a/src/contributors/add.js +++ b/src/contributors/add.js @@ -4,15 +4,26 @@ function uniqueTypes(contribution) { return contribution.type || contribution } -function formatContributions(options, existing, types) { +function formatContributions(options, existing = [], types) { + const same = _.intersectionBy(uniqueTypes, existing, types) + const diff = _.differenceBy(uniqueTypes, existing, types) + + const keep = same.length + const remove = same.length && diff.length + if (options.url) { - return (existing || []).concat( + return existing.concat( types.map(type => { return {type, url: options.url} }), ) } - return _.uniqBy(uniqueTypes, (existing || []).concat(types)) + + if (remove || keep) { + return same + } + + return _.uniqBy(uniqueTypes, existing.concat(types)) } function updateContributor(options, contributor, contributions) { @@ -38,12 +49,14 @@ function updateExistingContributor(options, username, contributions) { } function addNewContributor(options, username, contributions, infoFetcher) { - return infoFetcher(username, options.repoType, options.repoHost).then(userData => { - const contributor = _.assign(userData, { - contributions: formatContributions(options, [], contributions), - }) - return options.contributors.concat(contributor) - }) + return infoFetcher(username, options.repoType, options.repoHost).then( + userData => { + const contributor = _.assign(userData, { + contributions: formatContributions(options, [], contributions), + }) + return options.contributors.concat(contributor) + }, + ) } module.exports = function addContributor( From a5fc93866b881b805df3e15870701378baa9e167 Mon Sep 17 00:00:00 2001 From: Tyler Reitz Date: Sat, 2 Jun 2018 12:28:05 -0700 Subject: [PATCH 2/3] removes .swp file --- src/.cli.js.swp | Bin 16384 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/.cli.js.swp diff --git a/src/.cli.js.swp b/src/.cli.js.swp deleted file mode 100644 index 3789bba5e716e8efad3946207f74d0c62cd62688..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001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q z-6-!s<+xNmrwP#av(*syHGQKb|IYfNH^~w{q-jA7@I+22j07&_dNUX9t*CL~dQ`^- zVN!N|#F`m`h9fi&UE_yVo4)G0M)b-TQx;wf;JUiy1;bD^sdSM3P(igH(SOE}cH%4^ z45FOVjohsyzTuox_vDSXM^+tj#LRW`iH)rB#3Bo+ha2dJ6-OGgiKCdAeAzEzac=e$ zTrv}Wg9W|_dbKAZYNR=E$_~}4uiVPI>bJ<&1!#%Ct10;4Xd0! z@pEjI*qEZ@TR`guPv&Sq)x{=3HS~!A-{7gvQakyqQI@6=JyJbUL>Z=_*MWg*`Wt&R zznaA;rEHFFfX!@5DYK2h%_1hXEJib_Swv4a?Rk_)C$oAPlU5p$C!2Z+nNVg+h3nZe zq0FXjww_Dhk?C~yGoHs$BBsJ9_q*6*lazj0pJOqz{T*lTM5oBJPB%(AJXu3#$Q?TW zzl!tm4{(;I^S^n&|1QqWeUj+gzfiqwaxD!x3;4Pf@e+<3{o&!FZ z0~8PFfIs2P|0Z}Dya=8H&wvfE4laWe;8S2X*ahwa|3EC@I`|!U4ZHxp1qNUV90B{m zR`7T9bM4-=yXKM z#5_bVONa7^sovErRc}n>85l1o^l5lQzi!b-w;9-?O9x`c!;JFWr%w2RpL3?q;Uo1% zqhVvU=qNl=XEeMsR;N6DjZ~x~mps-YASPXsXE0SLM{I$DH@defsH38WI!Q%baPI66 z#Hlo!)jYK)S4d`h|JXDB$P@Q1yYfLp33M) z{q%hE@Jtz*p*W3>!;nGq+GG z3e(S*MzjZdqLs1FX}KLpUmNKM U^rBS}08hTxRqt>;-J`biZ%g=96#xJL From 8a7c8b024e88e68dd38d97fd104f475610703d2b Mon Sep 17 00:00:00 2001 From: Tyler Reitz Date: Sat, 2 Jun 2018 16:17:54 -0700 Subject: [PATCH 3/3] refactor: concat types in all cases except when removing --- src/contributors/add.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/contributors/add.js b/src/contributors/add.js index 568f71b5..d45a2d6f 100644 --- a/src/contributors/add.js +++ b/src/contributors/add.js @@ -6,10 +6,7 @@ function uniqueTypes(contribution) { function formatContributions(options, existing = [], types) { const same = _.intersectionBy(uniqueTypes, existing, types) - const diff = _.differenceBy(uniqueTypes, existing, types) - - const keep = same.length - const remove = same.length && diff.length + const remove = types.length < existing.length && same.length if (options.url) { return existing.concat( @@ -19,7 +16,7 @@ function formatContributions(options, existing = [], types) { ) } - if (remove || keep) { + if (remove) { return same }