Skip to content

Commit

Permalink
Merge pull request #24 from insurify/arslan_use_new_asana_api_2_0_1
Browse files Browse the repository at this point in the history
✨ Use Asana Package v3.0.1 for v2.0
  • Loading branch information
arslanather authored Feb 1, 2024
2 parents a45a2eb + 4df29d4 commit aa3c9fe
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const core = require('@actions/core');
const github = require('@actions/github');
const asana = require('asana');
const Asana = require('asana');

async function asanaOperations(
asanaPAT,
Expand All @@ -9,20 +9,22 @@ async function asanaOperations(
taskComment
) {
try {
const client = asana.Client.create({
defaultHeaders: { 'asana-enable': 'new-sections,string_ids' },
logAsanaChangeWarnings: false
}).useAccessToken(asanaPAT);
let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = asanaPAT;
let tasksApiInstance = new Asana.TasksApi();
let sectionsApiInstance = new Asana.SectionsApi();
let storiesApiInstance = new Asana.StoriesApi();

const task = await tasksApiInstance.getTask(taskId);

const task = await client.tasks.findById(taskId);

targets.forEach(async target => {
let targetProject = task.projects.find(project => project.name === target.project);
let targetProject = task.data.projects.find(project => project.name === target.project);
if (targetProject) {
let targetSection = await client.sections.findByProject(targetProject.gid)
.then(sections => sections.find(section => section.name === target.section));
let targetSection = await sectionsApiInstance.getSectionsForProject(targetProject.gid)
.then(sections => sections.data.find(section => section.name === target.section));
if (targetSection) {
await client.sections.addTask(targetSection.gid, { task: taskId });
await sectionsApiInstance.addTaskForSection(targetSection.gid, { body: { data: { task: taskId } } });
core.info(`Moved to: ${target.project}/${target.section}`);
} else {
core.error(`Asana section ${target.section} not found.`);
Expand All @@ -33,9 +35,7 @@ async function asanaOperations(
});

if (taskComment) {
await client.tasks.addComment(taskId, {
text: taskComment
});
await storiesApiInstance.createStoryForTask({ data: { text: taskComment } }, taskId)
core.info('Added the pull request link to the Asana task.');
}
} catch (ex) {
Expand Down

0 comments on commit aa3c9fe

Please sign in to comment.