mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: adds ability to remove contribution types when editing existing user (#94)
* adds ability to remove contribution types when editing existing user * removes .swp file * refactor: concat types in all cases except when removing
This commit is contained in:
parent
4f7bbdf56f
commit
2c9f47629b
3 changed files with 31 additions and 4 deletions
|
@ -135,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',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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'],
|
||||
})
|
||||
},
|
||||
)
|
||||
})
|
||||
|
|
|
@ -4,15 +4,23 @@ function uniqueTypes(contribution) {
|
|||
return contribution.type || contribution
|
||||
}
|
||||
|
||||
function formatContributions(options, existing, types) {
|
||||
function formatContributions(options, existing = [], types) {
|
||||
const same = _.intersectionBy(uniqueTypes, existing, types)
|
||||
const remove = types.length < existing.length && same.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) {
|
||||
return same
|
||||
}
|
||||
|
||||
return _.uniqBy(uniqueTypes, existing.concat(types))
|
||||
}
|
||||
|
||||
function updateContributor(options, contributor, contributions) {
|
||||
|
|
Loading…
Reference in a new issue