-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.js
48 lines (40 loc) · 1.14 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { context } = require("@actions/github");
const {
ACTION_STATUS_MAP,
COMPLETE,
CUSTOM_FIELD_NAMES,
} = require("./constants");
const shouldMoveStatus = (prBody) => {
if (!!prBody) {
const moveStatusMatch = prBody.match(
/(?<=(<!--\s+AsanaBot:MoveStatus:))\w+(?=\s+-->)/gm
);
return !!moveStatusMatch ? moveStatusMatch.pop() === "true" : false;
}
return false;
};
const findAsanaTaskIds = (prBody) =>
!!prBody
? prBody.match(/(?<=app.asana.com\/.*\/.*\/)\d+(?=(\/f$|$))/gm)
: null;
const filterCustomFields = (taskData) =>
taskData.custom_fields.find(({ name }) => CUSTOM_FIELD_NAMES.includes(name));
const calcNextStatus = (enumOptions) => {
const action = context.payload.action;
const statusOptions = enumOptions.reduce(
(accum, opt) => ({ ...accum, [opt.name]: opt.gid }),
{}
);
const nextStatus = ACTION_STATUS_MAP[action];
return {
nextStatusName: nextStatus,
nextStatusOptionId: statusOptions[nextStatus] || null,
isComplete: nextStatus === COMPLETE ? true : false,
};
};
module.exports = {
shouldMoveStatus,
findAsanaTaskIds,
filterCustomFields,
calcNextStatus,
};