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
import { ghAssignCardWhenOnColumn } from "https://esm.town/v/augustohp/ghAssignCardWhenOnColumn";
import process from "node:process";
/**
* TODO: Add signture check to webhook
*/
export const autoAssignOnWIP = async (req: Request) => {
// Configuration
const wipColumnNames = ["Em progresso", "Detalhando"];
const ghToken = process.env.GITHUB_TOKEN_PROJECTS;
// Webhook logic
const { action, sender, projects_v2_item, changes } = await req.json();
if (action != "edited") {
console.log(`Action: ${action}`);
return new Response("Not an edition, ignoring.");
}
if (!projects_v2_item) {
return new Response("Not a ProjectsV2 webhook event, ignoring");
}
const acceptableItemTypes = ["Issue", "PullRequest"];
if (!acceptableItemTypes.includes(projects_v2_item.content_type)) {
return new Response(`Not an Issue or PR (${projects_v2_item.content_type}), ignoring.`);
}
if (changes == undefined) {
return new Response("Not a change, ignoring.");
}
if (changes.field_value == undefined) {
return new Response("Not a change in a ProjectsV2Field, ignoring.");
}
if (changes.field_value.field_type != "single_select") {
return new Response("Not a column change, ignoring.");
}
await ghAssignCardWhenOnColumn(
projects_v2_item.content_node_id,
sender.node_id,
wipColumnNames,
ghToken,
);
return new Response(
`Assigned to ${sender.login}.`,
{ status: 201, statusText: "Assigned" },
);
};