Skip to content

Commit

Permalink
Make the check for project/section a little more rigorous (#27)
Browse files Browse the repository at this point in the history
- Fail cleanly if we can't find the target
  • Loading branch information
Ryan Doyle authored Aug 28, 2023
1 parent 8d89cc6 commit 967374b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@ async function moveSection(client, taskId, targets) {
const task = await client.tasks.findById(taskId);

for (const target of targets) {
// Find the right project
const projectNameRegex = new RegExp(target.projectNameRegex || target.project)
const targetProject = task.projects.find(project => projectNameRegex.test(project.name));
core.info(`Discovered Project: ${targetProject.name} with ID: ${targetProject.gid}`);
if (!targetProject) {
core.info(`This task does not exist in "${target.project}" project`);
continue;
}
core.info(`Discovered Project: ${targetProject.name} with ID: ${targetProject.gid}`);

// Find the right section
const sectionNameRegex = new RegExp(target.section)
const sections = await client.sections.findByProject(targetProject.gid)
const targetSection = sections.find(section => sectionNameRegex.test(section.name));
if (!targetSection) {
core.info(`Could not find a section matching "${target.section}"`);
continue;
}
core.info(`Discovered Section: ${targetSection.name} with ID: ${targetSection.gid}`);

if (targetSection && targetProject) {
await client.sections.addTask(targetSection.gid, { task: taskId });
core.info(`Moved to: ${targetProject.name}/${targetSection.name}`);
} else {
core.error(`Asana section ${target.section} not matched against any existing section.`);
}
// Move the task
await client.sections.addTask(targetSection.gid, { task: taskId });
core.info(`Moved to: ${targetProject.name}/${targetSection.name}`);
}
}

Expand Down

0 comments on commit 967374b

Please sign in to comment.