Skip to content

Commit e93f34b

Browse files
committed
Add targets JSON input
1 parent 4badafc commit e93f34b

File tree

3 files changed

+24
-28
lines changed

3 files changed

+24
-28
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,22 @@ This action integrates asana with github.
2222

2323
**Optional** If any comment is provided, the action will add a comment to the specified asana task with the text & pull request link.
2424

25-
### `target-project`
25+
### `targets`
2626

27-
**Optional** Move task only if it exists in provided project i.e `Current Sprint`.
28-
29-
### `target-section`
30-
31-
**Optional** Add/Move the task to the provided section if provided section exists in `target-project` i.e `merged`, `review`.
27+
**Optional** JSON array of objects having project and section where to move current task. Move task only if it exists in target project. e.g
28+
```yaml
29+
targets: '[{"project": "Backlog", "section": "Development Done"}, {"project": "Current Sprint", "section": "In Review"}]'
30+
```
31+
if you don't want to move task omit `targets`.
3232

3333

3434
## Example usage
3535

3636
```yaml
37-
uses: https://github.com/insurify/github-actions@master
37+
uses: https://github.com/insurify/github-actions@v2.0.0
3838
with:
3939
asana-pat: 'Your PAT'
40-
target-project: 'Current Sprint'
41-
target-section: 'In Review'
4240
task-comment: 'View Pull Request Here: '
4341
trigger-phrase: 'Asana Task:'
42+
targets: '[{"project": "Backlog", "section": "Development Done"}, {"project": "Current Sprint", "section": "In Review"}]'
4443
```

action.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ inputs:
77
task-comment:
88
description: 'Provide text, which will add a comment with the pull request link to the asana task.'
99
required: false
10-
target-project:
11-
description: 'Name of a project in which you want to move task from one section(column) to another(target-section).'
12-
required: false
13-
target-section:
14-
description: 'Name of a section(column) of target-project where you want to move the task.'
10+
targets:
11+
description: 'JSON array of objects having project and section where to move current task. Move task only if it exists in target project.'
1512
required: false
1613
trigger-phrase:
1714
description: 'Prefix before the task i.e ASANA TASK: https://app.asana.com/1/2/3'

index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ const asana = require('asana');
44

55
async function asanaOperations(
66
asanaPAT,
7-
projectName,
7+
targets,
88
taskId,
9-
sectionName,
109
taskComment
1110
) {
1211
try {
@@ -15,22 +14,23 @@ async function asanaOperations(
1514
logAsanaChangeWarnings: false
1615
}).useAccessToken(asanaPAT);
1716

18-
if (sectionName && projectName) {
19-
let targetProject = await client.tasks.findById(taskId)
20-
.then(task => task.projects.find(project => project.name === projectName));
17+
const task = await client.tasks.findById(taskId);
18+
19+
targets.forEach(async target => {
20+
let targetProject = task.projects.find(project => project.name === target.project);
2121
if (targetProject) {
2222
let targetSection = await client.sections.findByProject(targetProject.gid)
23-
.then(sections => sections.find(section => section.name === sectionName));
23+
.then(sections => sections.find(section => section.name === target.section));
2424
if (targetSection) {
2525
await client.sections.addTask(targetSection.gid, { task: taskId });
26-
core.info('Moved to: ' + targetSection.name);
26+
core.info(`Moved to: ${target.project}/${target.section}`);
2727
} else {
28-
core.error('Asana section ' + sectionName + ' not found.');
28+
core.error(`Asana section ${target.section} not found.`);
2929
}
3030
} else {
31-
core.error(`This task does not exist in "${projectName}" project`);
31+
core.info(`This task does not exist in "${target.project}" project`);
3232
}
33-
}
33+
});
3434

3535
if (taskComment) {
3636
await client.tasks.addComment(taskId, {
@@ -45,8 +45,7 @@ async function asanaOperations(
4545

4646
try {
4747
const ASANA_PAT = core.getInput('asana-pat'),
48-
PROJECT_NAME = core.getInput('target-project'),
49-
SECTION_NAME = core.getInput('target-section'),
48+
TARGETS = core.getInput('targets'),
5049
TRIGGER_PHRASE = core.getInput('trigger-phrase'),
5150
TASK_COMMENT = core.getInput('task-comment'),
5251
PULL_REQUEST = github.context.payload.pull_request,
@@ -55,6 +54,7 @@ try {
5554
'g'
5655
);
5756
let taskComment = null,
57+
targets = TARGETS? JSON.parse(TARGETS) : [],
5858
parseAsanaURL = null;
5959

6060
if (!ASANA_PAT){
@@ -66,9 +66,9 @@ try {
6666
while ((parseAsanaURL = REGEX.exec(PULL_REQUEST.body)) !== null) {
6767
let taskId = parseAsanaURL.groups.task;
6868
if (taskId) {
69-
asanaOperations(ASANA_PAT, PROJECT_NAME, taskId, SECTION_NAME, taskComment);
69+
asanaOperations(ASANA_PAT, targets, taskId, taskComment);
7070
} else {
71-
core.info('Invalid Asana task URL after the trigger phrase' + TRIGGER_PHRASE);
71+
core.info(`Invalid Asana task URL after the trigger phrase ${TRIGGER_PHRASE}`);
7272
}
7373
}
7474
} catch (error) {

0 commit comments

Comments
 (0)