diff --git a/index.js b/index.js index 1a1ffc77..2198f1a9 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,11 @@ const core = require('@actions/core'); const github = require('@actions/github'); const asana = require('asana'); +async function commentAlreadySent(client, taskId, taskComment) { + const stories = await client.tasks.stories(taskId); + return stories.data.some(s => s.type === 'comment' && s.text === taskComment); +} + async function asanaOperations( asanaPAT, targets, @@ -15,7 +20,7 @@ async function asanaOperations( }).useAccessToken(asanaPAT); const task = await client.tasks.findById(taskId); - + targets.forEach(async target => { let targetProject = task.projects.find(project => project.name === target.project); if (targetProject) { @@ -33,10 +38,15 @@ async function asanaOperations( }); if (taskComment) { - await client.tasks.addComment(taskId, { - text: taskComment - }); - core.info('Added the pull request link to the Asana task.'); + const shouldSkip = await commentAlreadySent(client, taskId, taskComment); + if (shouldSkip) { + core.info('Pull request link was already added.') + } else { + await client.tasks.addComment(taskId, { + text: taskComment + }); + core.info('Added the pull request link to the Asana task.'); + } } } catch (ex) { console.error(ex.value);