-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (38 loc) · 1.7 KB
/
index.js
File metadata and controls
50 lines (38 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const core = require('@actions/core');
const github = require('@actions/github');
const getActionData = require('./get-action-data');
const generateProjectQuery = require('./generate-project-query');
const generateMutationQuery = require('./generate-mutation-query');
(async () => {
try {
const token = core.getInput('repo-token');
const project = core.getInput('project');
const column = core.getInput('column');
const action = core.getInput('action') || 'update';
// Get data from the current action
const {nodeId, url} = getActionData(github.context);
// Create a method to query GitHub
const octokit = new github.GitHub(token);
// Get the column ID from searching for the project and card Id if it exists
const projectQuery = generateProjectQuery(url, github.context.payload, project);
core.debug(projectQuery);
const {resource} = await octokit.graphql(projectQuery);
core.debug(JSON.stringify(resource));
// A list of columns that line up with the user entered project and column
const mutationQueries = generateMutationQuery(resource, project, column, nodeId, action);
if ((action === 'delete' || action === 'archive' || action === 'add') && mutationQueries.length === 0) {
console.log('✅ There is nothing to do with card');
return;
}
core.debug(mutationQueries.join('\n'));
// Run the graphql queries
await Promise.all(mutationQueries.map(query => octokit.graphql(query)));
if (mutationQueries.length > 1) {
console.log(`✅ Card materialised into to ${column} in ${mutationQueries.length} projects called ${project}`);
} else {
console.log(`✅ Card materialised into ${column} in ${project}`);
}
} catch (error) {
core.setFailed(error.message);
}
})();