From ba296a57a6131b4ed9779a8084d09b83666a7089 Mon Sep 17 00:00:00 2001 From: Anastasia Shuba Date: Wed, 23 Oct 2024 15:42:11 -0700 Subject: [PATCH 1/3] add option for tags --- action.js | 79 +++++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/action.js b/action.js index 9c17636..e4b34e5 100644 --- a/action.js +++ b/action.js @@ -250,38 +250,39 @@ async function findTaskInSection(client, sectionId, name) { return existingTaskId } -async function createTask(client, name, description, projectId) { - console.log('creating new task', name); - let createdTaskId = "0" - try { - await client.tasks.createTask({name: name, - notes: description, - projects: [projectId], - pretty: true}) - .then((result) => { - createdTaskId = result.gid - console.log('task created', createdTaskId); - }) - } catch (error) { - console.error('rejecting promise', error); +async function createTask(client, name, description, projectId, sectionId = '', tag = '') { + const taskOpts = { + name: name, + notes: description, + projects: [projectId], + pretty: true + }; + + if (sectionId != '') { + console.log('checking for duplicate task before creating a new one', name); + let existingTaskId = await findTaskInSection(client, sectionId, name) + if (existingTaskId != "0") { + console.log("task already exists, skipping") + core.setOutput('taskId', existingTaskId) + core.setOutput('duplicate', true) + return existingTaskId; + } + + taskOpts.memberships = [{project: projectId, section: sectionId}]; } - return createdTaskId -} -async function createTaskInSection(client, name, description, projectId, sectionId) { - console.log('creating new task in section', sectionId); + if (tag != '') + taskOpts.tags = [tag]; + + console.log(`creating new task with section='${sectionId}' and tag='${tag}'`); let createdTaskId = "0" try { - await client.tasks.createTask({name: name, - notes: description, - projects: [projectId], - memberships: [{project: projectId, section: sectionId}], - pretty: true}) + await client.tasks.createTask(taskOpts) .then((result) => { createdTaskId = result.gid - console.log('task created in section', createdTaskId); - core.setOutput('taskId', createdTaskId) - core.setOutput('duplicate', false) + console.log('task created', createdTaskId); + core.setOutput('taskId', createdTaskId); + core.setOutput('duplicate', false); }) } catch (error) { console.error('rejecting promise', error); @@ -289,19 +290,6 @@ async function createTaskInSection(client, name, description, projectId, section return createdTaskId } -async function createTaskIfNotDuplicate(client, name, description, projectId, sectionId) { - console.log('checking for duplicate task before creating a new one', name); - let existingTaskId = await findTaskInSection(client, sectionId, name) - if (existingTaskId == "0") { - return createTaskInSection(client, name, description, projectId, sectionId) - } else { - console.log("task already exists, skipping") - core.setOutput('taskId', existingTaskId) - core.setOutput('duplicate', true) - } - return existingTaskId -} - async function createAsanaTask(){ const client = await buildAsanaClient(); @@ -309,13 +297,10 @@ async function createAsanaTask(){ projectId = core.getInput('asana-project', {required: true}), sectionId = core.getInput('asana-section'), taskName = core.getInput('asana-task-name', {required: true}), - taskDescription = core.getInput('asana-task-description', {required: true}); + taskDescription = core.getInput('asana-task-description', {required: true}), + tag = core.getInput('asana-tag'); - if (sectionId === "") { - return createTask(client, taskName, taskDescription, projectId) - } else { - return createTaskIfNotDuplicate(client, taskName, taskDescription, projectId, sectionId) - } + return createTask(client, taskName, taskDescription, projectId, sectionId, tag); } async function addTaskPRDescription(){ @@ -409,4 +394,6 @@ async function action() { module.exports = { action, default: action, -}; \ No newline at end of file +}; + +// TODO: generic Asana create task with optional inputs for tags and etc \ No newline at end of file From ed9f4063d36ecda3e536952e7cd6b2310d512357 Mon Sep 17 00:00:00 2001 From: Anastasia Shuba Date: Wed, 23 Oct 2024 16:01:44 -0700 Subject: [PATCH 2/3] add input --- action.js | 2 -- action.yml | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/action.js b/action.js index e4b34e5..fda031c 100644 --- a/action.js +++ b/action.js @@ -395,5 +395,3 @@ module.exports = { action, default: action, }; - -// TODO: generic Asana create task with optional inputs for tags and etc \ No newline at end of file diff --git a/action.yml b/action.yml index 6c0c19c..6f14737 100644 --- a/action.yml +++ b/action.yml @@ -22,6 +22,9 @@ inputs: asana-task-description: description: 'Description of the Asana task you want to create.' required: false + asana-tag: + description: 'Tag to be added to the Asana task.' + required: false trigger-phrase: description: 'Prefix used to identify Asana tasks (URL).' required: false From b637fbe6c60a27c83ff4c1adbe4d753c0ec8fdcc Mon Sep 17 00:00:00 2001 From: Anastasia Shuba Date: Wed, 23 Oct 2024 16:15:30 -0700 Subject: [PATCH 3/3] update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d99e43a..f2895f3 100644 --- a/README.md +++ b/README.md @@ -255,6 +255,8 @@ The Asana section ID in the Asana Project **Required** Name of the Asana task ### `asana-task-description` **Required** Description of the Asana task +### `asana-tag` +ID of Asana tag to be added to the task i.e. https://app.asana.com/0/1208613272217946/ #### Example Usage @@ -274,5 +276,6 @@ jobs: asana-section: 'Asana Section Id' asana-task-name: 'Asana Task Name' asana-task-description: 'Asana Task Description' + asana-tag: 'Tag Id' action: 'create-asana-task' ``` \ No newline at end of file