Skip to content

Commit 4badafc

Browse files
committed
Add target-project
1 parent e7eb105 commit 4badafc

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ 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`
26+
27+
**Optional** Move task only if it exists in provided project i.e `Current Sprint`.
28+
2529
### `target-section`
2630

27-
**Optional** Add/Move the task to the provided section i.e `merged`, `review`.
31+
**Optional** Add/Move the task to the provided section if provided section exists in `target-project` i.e `merged`, `review`.
2832

2933

3034
## Example usage
@@ -33,6 +37,7 @@ This action integrates asana with github.
3337
uses: https://github.com/insurify/github-actions@master
3438
with:
3539
asana-pat: 'Your PAT'
40+
target-project: 'Current Sprint'
3641
target-section: 'In Review'
3742
task-comment: 'View Pull Request Here: '
3843
trigger-phrase: 'Asana Task:'

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ 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
1013
target-section:
11-
description: 'Provide the name of an Asana projects section or column where you want to move the task.'
14+
description: 'Name of a section(column) of target-project where you want to move the task.'
1215
required: false
1316
trigger-phrase:
1417
description: 'Prefix before the task i.e ASANA TASK: https://app.asana.com/1/2/3'

index.js

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

55
async function asanaOperations(
66
asanaPAT,
7-
projectId,
7+
projectName,
88
taskId,
99
sectionName,
1010
taskComment
@@ -14,20 +14,24 @@ async function asanaOperations(
1414
defaultHeaders: { 'asana-enable': 'new-sections,string_ids' },
1515
logAsanaChangeWarnings: false
1616
}).useAccessToken(asanaPAT);
17-
if (sectionName) {
18-
let project = await client.sections.findByProject(projectId);
19-
if (project) {
20-
let requiredSection = project.find(data => data.name === sectionName);
21-
if (requiredSection) {
22-
await client.sections.addTask(requiredSection.gid, { task: taskId });
23-
core.info('Moved to: ' + requiredSection.name);
17+
18+
if (sectionName && projectName) {
19+
let targetProject = await client.tasks.findById(taskId)
20+
.then(task => task.projects.find(project => project.name === projectName));
21+
if (targetProject) {
22+
let targetSection = await client.sections.findByProject(targetProject.gid)
23+
.then(sections => sections.find(section => section.name === sectionName));
24+
if (targetSection) {
25+
await client.sections.addTask(targetSection.gid, { task: taskId });
26+
core.info('Moved to: ' + targetSection.name);
2427
} else {
2528
core.error('Asana section ' + sectionName + ' not found.');
2629
}
2730
} else {
28-
core.error('Asana project with id ' + projectId + ' not found.');
31+
core.error(`This task does not exist in "${projectName}" project`);
2932
}
3033
}
34+
3135
if (taskComment) {
3236
await client.tasks.addComment(taskId, {
3337
text: taskComment
@@ -41,6 +45,7 @@ async function asanaOperations(
4145

4246
try {
4347
const ASANA_PAT = core.getInput('asana-pat'),
48+
PROJECT_NAME = core.getInput('target-project'),
4449
SECTION_NAME = core.getInput('target-section'),
4550
TRIGGER_PHRASE = core.getInput('trigger-phrase'),
4651
TASK_COMMENT = core.getInput('task-comment'),
@@ -53,16 +58,15 @@ try {
5358
parseAsanaURL = null;
5459

5560
if (!ASANA_PAT){
56-
throw({message: "ASANA PAT Not Found!"});
61+
throw({message: 'ASANA PAT Not Found!'});
5762
}
5863
if (TASK_COMMENT) {
5964
taskComment = `${TASK_COMMENT} ${PULL_REQUEST.html_url}`;
6065
}
6166
while ((parseAsanaURL = REGEX.exec(PULL_REQUEST.body)) !== null) {
62-
let projectId = parseAsanaURL.groups.project,
63-
taskId = parseAsanaURL.groups.task;
64-
if (projectId && taskId) {
65-
asanaOperations(ASANA_PAT, projectId, taskId, SECTION_NAME, taskComment);
67+
let taskId = parseAsanaURL.groups.task;
68+
if (taskId) {
69+
asanaOperations(ASANA_PAT, PROJECT_NAME, taskId, SECTION_NAME, taskComment);
6670
} else {
6771
core.info('Invalid Asana task URL after the trigger phrase' + TRIGGER_PHRASE);
6872
}

0 commit comments

Comments
 (0)