import { ghAssignCardWhenOnColumn } from "https://esm.town/v/augustohp/ghAssignCardWhenOnColumn";
import process from "node:process";
export const autoAssignOnWIP = async (req: Request) => {
const wipColumnNames = ["Em progresso", "Detalhando"];
const ghToken = process.env.GITHUB_TOKEN_PROJECTS;
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" },
);
};