diff --git a/README.md b/README.md index 05d3d32..e47cfdd 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,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 @@ -275,5 +277,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' ``` diff --git a/action.js b/action.js index 9c17636..fda031c 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,4 @@ async function action() { module.exports = { action, default: action, -}; \ 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