Skip to content

Commit f1c2861

Browse files
committed
Add 'column-{allow/deny}-list' optional inputs
This adds the `column-allow-list` and `column-deny-list` optional inputs. If neither is set the behavior of the action is identical to before. `column-allow-list` may be set to a string or list of strings (separated by comma or newline character) which specifes columns that the action may move cards from only. That is, if `column-deny-list` is set to `todo,wip` then only cards in `todo` and `wip` can be moved by the job. If unset all cards in all columns may be moved (assuming `column-deny-list` is also unset). `column-deny-list` may also be set to a string or list of strings (again, separated by a comma or newline character) which specifies columns that the action may never move cards. That is, if `column-deny-list` is set to `todo,wip` then cards in `todo` and `wip` will not be moved by the job. If unset all the cards in all the columns may be moved (assuming `column-allow-list` is also unset). from. This addresses: #41. Tests have been added to verify previous behavior is preserved and these new inputs function as intended.
1 parent 7ffb872 commit f1c2861

File tree

4 files changed

+104
-10
lines changed

4 files changed

+104
-10
lines changed

Diff for: action.yml

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ inputs:
1111
column:
1212
description: 'The name of the column to move the issue or pull request to'
1313
required: true
14+
column-allow-list:
15+
type: string
16+
description: 'Columns which cards are allowed to be moved from. If not specified, all columns are allowed. Multiple columns separated by newline or comma.'
17+
required: false
18+
default: ''
19+
column-deny-list:
20+
type: string
21+
description: 'Columns which cards are not allowed to be moved from. If not specified, no columns are denied. Multiple columns separated by newline or comma.'
22+
required: false
23+
default: ''
1424
action:
1525
description: |
1626
Can be `update`, `delete` or `archive` or `add`. This determines the type of the action

Diff for: src/generate-mutation-query.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
* @param {string} projectName - The user inputted project name
66
* @param {string} columnName - The user inputted column name
77
* @param {string} contentId - The id of the issue or pull request
8+
* @param {list} columnAllowList - List of columns allowed to move from. If unset, any.
9+
* @param {list} columnDenyList - List of columns to deny movement from. If unset, none.
810
* @param {"delete"|"archive"|"update"} action - the action to be performed on the card
911
*/
1012
// if this is important, we will need to refactor the function
1113
// eslint-disable-next-line max-params
12-
const generateMutationQuery = (data, projectName, columnName, contentId, action) => {
14+
const generateMutationQuery = (data, projectName, columnName, contentId, columnAllowList, columnDenyList, action) => {
1315
// All the projects found in organisation and repositories
1416
const repoProjects = data.repository.projects.nodes || [];
1517
const orgProjects = (data.repository.owner &&
@@ -50,10 +52,23 @@ const generateMutationQuery = (data, projectName, columnName, contentId, action)
5052
for (const card of currentLocation) {
5153
cardLocations[card.project.id].cardId = card.id;
5254
cardLocations[card.project.id].isArchived = card.isArchived;
55+
cardLocations[card.project.id].curColumnName = (card.column && card.column.name) ? card.column.name : undefined;
5356
}
5457

5558
// If the card already exists in the project move it otherwise add a new card
5659
const mutations = Object.keys(cardLocations).map(mutation => {
60+
// If the column allow list is specified, and this card's current
61+
// column is not in it, skip.
62+
if (cardLocations[mutation].curColumnName && columnAllowList && columnAllowList.length && !columnAllowList.includes(cardLocations[mutation].curColumnName)) {
63+
return undefined;
64+
}
65+
66+
// If the column deny list is specified, and this card's current column
67+
// is in it, skip.
68+
if (cardLocations[mutation].curColumnName && columnDenyList && columnDenyList.length && columnDenyList.includes(cardLocations[mutation].curColumnName)) {
69+
return undefined;
70+
}
71+
5772
if (action === 'update') {
5873
// Othervise keep default procedure
5974
return cardLocations[mutation].cardId ?

Diff for: src/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const generateMutationQuery = require('./generate-mutation-query');
1010
const token = core.getInput('repo-token');
1111
const project = core.getInput('project');
1212
const column = core.getInput('column');
13+
const columnAllowList = core.getInput('column-allow-list').split("/,|\n/").filter(x => x !== "");
14+
const columnDenyList = core.getInput('column-deny-list').split("/,|\n/").filter(x => x !== "");
1315
const action = core.getInput('action') || 'update';
1416

1517
// Get data from the current action
@@ -28,7 +30,7 @@ const generateMutationQuery = require('./generate-mutation-query');
2830
core.debug(JSON.stringify(resource));
2931

3032
// A list of columns that line up with the user entered project and column
31-
const mutationQueries = generateMutationQuery(resource, project, column, nodeId, action);
33+
const mutationQueries = generateMutationQuery(resource, project, column, nodeId, columnAllowList, columnDenyList, action);
3234
if ((action === 'delete' || action === 'archive' || action === 'add') && mutationQueries.length === 0) {
3335
console.log('✅ There is nothing to do with card');
3436
return;

Diff for: tests/generate-mutation-query.js

+75-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const generateMutationQuery = require('../src/generate-mutation-query');
55
const project = 'Backlog';
66
const column = 'To do';
77
const nodeId = 'MDU6SXNzdWU1ODc4NzU1Mjk=';
8+
const columnAllowList = [];
9+
const columnDenyList = [];
810

911
const moveData = {
1012
projectCards: {
@@ -14,6 +16,9 @@ const moveData = {
1416
project: {
1517
name: project,
1618
id: 'MDc6UHJvamVjdDQwNzU5MDI='
19+
},
20+
column: {
21+
name: 'Hotbox'
1722
}
1823
}
1924
]
@@ -30,6 +35,10 @@ const moveData = {
3035
id: 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ6',
3136
name: 'Icebox'
3237
},
38+
{
39+
id: 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ7',
40+
name: 'Hotbox'
41+
},
3342
{
3443
id: 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5',
3544
name: column
@@ -48,7 +57,7 @@ const moveData = {
4857
};
4958

5059
test('generateMutationQuery move the card when in the correct project and wrong column', t => {
51-
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, 'update'), [
60+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, columnDenyList, 'update'), [
5261
`mutation {
5362
moveProjectCard( input: {
5463
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM=",
@@ -58,7 +67,7 @@ test('generateMutationQuery move the card when in the correct project and wrong
5867
});
5968

6069
test('generateMutationQuery delete the card when it is in the project already', t => {
61-
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, 'delete'), [
70+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, columnDenyList, 'delete'), [
6271
`mutation {
6372
deleteProjectCard( input: {
6473
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM="
@@ -67,7 +76,65 @@ test('generateMutationQuery delete the card when it is in the project already',
6776
});
6877

6978
test('generateMutationQuery skip issue addition when the card already exists in the project', t => {
70-
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, 'add'), []);
79+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, columnDenyList, 'add'), []);
80+
});
81+
82+
denyListShouldSkip = ["Hotbox"];
83+
test('generateMutationQuery skip move of card when card in column in the deny list', t => {
84+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, denyListShouldSkip, 'update'), []);
85+
});
86+
87+
test('generateMutationQuery skip deletion when the card in column in the deny list', t => {
88+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, denyListShouldSkip, 'delete'), []);
89+
});
90+
91+
denyListShouldntSkip = ["Icebox"];
92+
test('generateMutationQuery move the card when in the correct project, wrong column and other columns denied', t => {
93+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, denyListShouldntSkip, 'update'), [
94+
`mutation {
95+
moveProjectCard( input: {
96+
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM=",
97+
columnId: "MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5"
98+
}) { clientMutationId } }`
99+
]);
100+
});
101+
102+
test('generateMutationQuery delete the card when it is in the project already and other columns denied', t => {
103+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, columnAllowList, denyListShouldntSkip, 'delete'), [
104+
`mutation {
105+
deleteProjectCard( input: {
106+
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM="
107+
}) { clientMutationId } }`
108+
]);
109+
});
110+
111+
allowListShouldSkip = ["Icebox"]
112+
test('generateMutationQuery skip move of card when card in column not in the allow list', t => {
113+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, allowListShouldSkip, columnDenyList, 'update'), []);
114+
});
115+
116+
test('generateMutationQuery skip deletion when the card in column not in the allow list', t => {
117+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, allowListShouldSkip, columnDenyList, 'delete'), []);
118+
});
119+
120+
allowListShouldntSkip = ["Hotbox"]
121+
test('generateMutationQuery move the card when in the correct project, wrong column and column allowed', t => {
122+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, allowListShouldntSkip, columnDenyList, 'update'), [
123+
`mutation {
124+
moveProjectCard( input: {
125+
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM=",
126+
columnId: "MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5"
127+
}) { clientMutationId } }`
128+
]);
129+
});
130+
131+
test('generateMutationQuery delete the card when it is in the project already and column allowed', t => {
132+
t.deepEqual(generateMutationQuery(moveData, project, column, nodeId, allowListShouldntSkip, columnDenyList, 'delete'), [
133+
`mutation {
134+
deleteProjectCard( input: {
135+
cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM="
136+
}) { clientMutationId } }`
137+
]);
71138
});
72139

73140
const addData = {
@@ -104,7 +171,7 @@ const addData = {
104171
};
105172

106173
test('generateMutationQuery add the card when the card does not exist in the project', t => {
107-
t.deepEqual(generateMutationQuery(addData, project, column, nodeId, 'update'), [
174+
t.deepEqual(generateMutationQuery(addData, project, column, nodeId, columnAllowList, columnDenyList, 'update'), [
108175
`mutation {
109176
addProjectCard( input: {
110177
contentId: "MDU6SXNzdWU1ODc4NzU1Mjk=",
@@ -114,7 +181,7 @@ test('generateMutationQuery add the card when the card does not exist in the pro
114181
});
115182

116183
test('generateMutationQuery skip issue deletion when the card does not exist in the project', t => {
117-
t.deepEqual(generateMutationQuery(addData, project, column, nodeId, 'delete'), []);
184+
t.deepEqual(generateMutationQuery(addData, project, column, nodeId, columnAllowList, columnDenyList, 'delete'), []);
118185
});
119186

120187
const archiveData = {
@@ -160,7 +227,7 @@ const archiveData = {
160227
};
161228

162229
test('generateMutationQuery skip issue archive when the card is already archived', t => {
163-
t.deepEqual(generateMutationQuery(archiveData, project, column, nodeId, 'archive'), []);
230+
t.deepEqual(generateMutationQuery(archiveData, project, column, nodeId, columnAllowList, columnDenyList, 'archive'), []);
164231
});
165232

166233
const dataNoColumn = {
@@ -193,7 +260,7 @@ const dataNoColumn = {
193260
};
194261

195262
test('generateMutationQuery should fail if it cannot find a matching column', t => {
196-
const error = t.throws(() => generateMutationQuery(dataNoColumn, project, column, nodeId));
263+
const error = t.throws(() => generateMutationQuery(dataNoColumn, project, column, columnAllowList, columnDenyList, nodeId));
197264

198265
t.is(error.message, `Could not find the column "${column}" or project "${project}"`);
199266
});
@@ -228,7 +295,7 @@ const dataNoProject = {
228295
};
229296

230297
test('generateMutationQuery should fail if it cannot find a matching project', t => {
231-
const error = t.throws(() => generateMutationQuery(dataNoProject, project, column, nodeId));
298+
const error = t.throws(() => generateMutationQuery(dataNoProject, project, column, nodeId, columnAllowList, columnDenyList));
232299

233300
t.is(error.message, `Could not find the column "${column}" or project "${project}"`);
234301
});

0 commit comments

Comments
 (0)