Skip to content

Commit dc4ec6f

Browse files
author
Jérémie Parker
committed
feat(contributors): remove contributor
1 parent 8b81e5c commit dc4ec6f

File tree

4 files changed

+62
-29
lines changed

4 files changed

+62
-29
lines changed

cli.js

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
viewProject,
1414
listContributors,
1515
addContributor,
16+
removeContributor,
1617
} = require('./gitpo')
1718

1819
const {
@@ -23,7 +24,7 @@ const {
2324
CONTRIBUTORS,
2425
CONTRIBUTORS_LIST,
2526
CONTRIBUTORS_ADD,
26-
CONTRIBUTORS_DELETE,
27+
CONTRIBUTORS_REMOVE,
2728
} = require('./utils/konstants')
2829

2930
let languages = []
@@ -33,7 +34,7 @@ inquirer
3334
{
3435
type: 'list',
3536
name: 'action',
36-
message: 'What would you like to do',
37+
message: 'What would you like to do:',
3738
choices: [
3839
{ name: 'View Project Details', value: PROJECT_VIEW },
3940
{ name: 'Update Code (POEditor → GitHub)', value: PROJECT_UPDATE },
@@ -46,61 +47,61 @@ inquirer
4647
when: ({ action }) => action === CONTRIBUTORS,
4748
type: 'list',
4849
name: 'action',
49-
message: 'What would you like to do',
50+
message: 'What would you like to do:',
5051
choices: [
5152
{ name: 'List collaborators', value: CONTRIBUTORS_LIST },
5253
{ name: 'Add collaborator', value: CONTRIBUTORS_ADD },
53-
{ name: 'Delete collaborator', value: CONTRIBUTORS_DELETE },
54+
{ name: 'Remove collaborator', value: CONTRIBUTORS_REMOVE },
5455
],
5556
},
5657
{
5758
when: ({ action }) => action === CONTRIBUTORS_ADD,
5859
type: 'input',
60+
name: 'fullname',
61+
message: 'Full Name:',
62+
},
63+
{
64+
when: ({ action }) => [CONTRIBUTORS_ADD, CONTRIBUTORS_REMOVE].includes(action),
65+
type: 'input',
5966
name: 'email',
6067
message: 'Email:',
6168
},
6269
{
63-
when: ({ action }) => action === CONTRIBUTORS_ADD,
64-
type: 'input',
65-
name: 'fullname',
66-
message: 'Full Name:',
70+
when: ({ action }) => [CONTRIBUTORS_ADD, CONTRIBUTORS_REMOVE].includes(action),
71+
type: 'checkbox',
72+
name: 'projects',
73+
message: 'Select project(s):',
74+
choices: async () => {
75+
const projects = await listProjects()
76+
return projects.map(({ name, id: value }) => ({ name, value }))
77+
},
6778
},
6879
{
6980
when: ({ action }) => action === PROJECT_CLEAN,
7081
type: 'input',
7182
name: 'file',
72-
message: 'Where is the file to work on ?',
83+
message: 'Where is the file to work on?',
7384
},
7485
{
7586
when: ({ action }) => action === PROJECT_CLEAN,
7687
type: 'confirm',
7788
name: 'override',
78-
message: 'Override existing file ? (if not, a file will be created next to the existing one)',
89+
message: 'Override existing file? (if not, a file will be created next to the existing one)',
7990
default: false,
8091
},
8192
{
82-
when: ({ action }) => action !== PROJECT_CLEAN && action !== CONTRIBUTORS_LIST && action !== CONTRIBUTORS_ADD,
93+
when: ({ action }) => [PROJECT_VIEW, PROJECT_UPDATE, PROJECT_TERMS].includes(action),
8394
type: 'list',
8495
name: 'project',
85-
message: 'Select a project',
86-
choices: async () => {
87-
const projects = await listProjects()
88-
return projects.map(({ name, id: value }) => ({ name, value }))
89-
},
90-
},
91-
{
92-
when: ({ action }) => action === CONTRIBUTORS_ADD,
93-
type: 'checkbox',
94-
name: 'projects',
95-
message: 'Select project(s)',
96+
message: 'Select a project:',
9697
choices: async () => {
9798
const projects = await listProjects()
9899
return projects.map(({ name, id: value }) => ({ name, value }))
99100
},
100101
},
101102
{
102103
when: async ({ action, project, projects }) => {
103-
if ([PROJECT_UPDATE, CONTRIBUTORS_ADD].includes(action)) {
104+
if ([PROJECT_UPDATE, CONTRIBUTORS_ADD, CONTRIBUTORS_REMOVE].includes(action)) {
104105
if (projects && !project) {
105106
project = projects[0] // NOTE: assuming all projects have the same language set here
106107
}
@@ -111,7 +112,7 @@ inquirer
111112
},
112113
type: 'checkbox',
113114
name: 'languages',
114-
message: 'Select Language(s)',
115+
message: 'Select Language(s):',
115116
choices: async () => languages.map(({ name, code }) => ({ name, value: code })),
116117
},
117118
{
@@ -152,6 +153,9 @@ inquirer
152153
case CONTRIBUTORS_ADD:
153154
addContributor(email, fullname, projects, languages).then(() => console.log('Contributor added'))
154155
break
156+
case CONTRIBUTORS_REMOVE:
157+
removeContributor(email, projects, languages).then(() => console.log('Contributor removed'))
158+
break
155159
default:
156160
console.log('Sorry, I did not get what it is that you want...')
157161
}

gitpo.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
const conf = require('./config')
2+
const addContributor = require('./lib/addContributor')(conf)
23
const cleanTranslationJSON = require('./lib/cleanTranslationJSON')
34
const importNewTerms = require('./lib/importNewTerms')(conf)
5+
const listContributors = require('./lib/listContributors')(conf)
46
const listProjectLanguages = require('./lib/listProjectLanguages')(conf)
57
const listProjects = require('./lib/listProjects')(conf)
8+
const removeContributor = require('./lib/removeContributor')(conf)
69
const synchronizeTerms = require('./lib/synchronizeTerms')(conf)
710
const updateTranslations = require('./lib/updateTranslations')(conf)
811
const viewProject = require('./lib/viewProject')(conf)
9-
const listContributors = require('./lib/listContributors')(conf)
10-
const addContributor = require('./lib/addContributor')(conf)
1112

1213
module.exports = {
14+
addContributor,
1315
cleanTranslationJSON,
1416
importNewTerms,
17+
listContributors,
1518
listProjectLanguages,
1619
listProjects,
20+
removeContributor,
1721
synchronizeTerms,
1822
updateTranslations,
1923
viewProject,
20-
listContributors,
21-
addContributor,
2224
}

lib/removeContributor.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const rp = require('request-promise')
2+
3+
// NOTE: An assumption is made here that may require some changes to support a more general use case:
4+
// All projects have all the same languages OR poeditor API will ignore deletion to non existing languages for a given project
5+
// this cases where not tested
6+
module.exports = ({ API_TOKEN }) => (email, projects, languages) =>
7+
Promise.all(
8+
projects.map(async (id) =>
9+
Promise.all(
10+
languages.map(async (language) =>
11+
rp({
12+
method: 'POST',
13+
url: 'https://api.poeditor.com/v2/contributors/remove',
14+
headers: {
15+
'content-type': 'application/x-www-form-urlencoded',
16+
},
17+
form: {
18+
api_token: API_TOKEN,
19+
id,
20+
email,
21+
language,
22+
},
23+
})
24+
)
25+
)
26+
)
27+
)

utils/konstants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ module.exports = {
66
CONTRIBUTORS: 'CONTRIBUTORS',
77
CONTRIBUTORS_LIST: 'CONTRIBUTORS_LIST',
88
CONTRIBUTORS_ADD: 'CONTRIBUTORS_ADD',
9-
CONTRIBUTORS_DELETE: 'CONTRIBUTORS_DELETE',
9+
CONTRIBUTORS_REMOVE: 'CONTRIBUTORS_REMOVE',
1010
}

0 commit comments

Comments
 (0)