Skip to content

Commit 278947e

Browse files
committed
added task-update
1 parent b5fce8e commit 278947e

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

action.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ async function moveSection(client, taskId, targets) {
2727
});
2828
}
2929

30+
async function updateTask(client, taskId, targets) {
31+
const task = await client.tasks.findById(taskId);
32+
if (!task) {
33+
core.info(`This task does not exist`);
34+
return;
35+
}
36+
targets.forEach(async (target) => {
37+
await client.tasks.update(taskId, {
38+
custom_fields: {
39+
[target.fieldId]: target.fieldValue,
40+
},
41+
});
42+
core.info(`Task status updated to "${target.fieldValue}"`);
43+
});
44+
}
45+
3046
async function migrateSection(client, targets) {
3147
targets.forEach(async (target) => {
3248
const targetProject = await client.projects.findById(target.projectId);
@@ -234,13 +250,18 @@ async function action() {
234250
const targets = JSON.parse(targetJSON);
235251
const migratedTasks = [];
236252
await migrateSection(client, targets);
237-
// const movedTasks = [];
238-
// for (const taskId of foundAsanaTasks) {
239-
// await moveSection(client, taskId, targets);
240-
// movedTasks.push(taskId);
241-
// }
242253
return migratedTasks;
243254
}
255+
case "update-task": {
256+
const targetJSON = core.getInput("targets", { required: true });
257+
const targets = JSON.parse(targetJSON);
258+
const updatedTask = [];
259+
for (const taskId of foundAsanaTasks) {
260+
await updateTask(client, taskId, targets);
261+
updatedTask.push(taskId);
262+
return updatedTask;
263+
}
264+
}
244265
default:
245266
core.setFailed("unexpected action ${ACTION}");
246267
}

action.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,19 @@ describe("asana github actions", () => {
191191

192192
await expect(action.action()).resolves.toHaveLength(1);
193193
});
194+
195+
test("update task", async () => {
196+
inputs = {
197+
"asana-pat": asanaPAT,
198+
action: "update-task",
199+
targets: `[{"fieldId": "", "fieldValue":""}]`,
200+
};
201+
github.context.payload = {
202+
pull_request: {
203+
body: defaultBody,
204+
},
205+
};
206+
207+
await expect(action.action()).resolves.toHaveLength(1);
208+
});
194209
});

0 commit comments

Comments
 (0)