Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

GitHub Projects: Assign to the person who just moved the card

Receives Project v2 items webhook events from GitHub. When a card is moved on a Kanban board (Status field), if it is on a specific column, assign it to the person who moved it. Useful when I move a card from To do (no assignee) to Doing (assigns to me), for example.

How to use it?

  1. Fork this val and edit it
    1. Change wipColumnName to whatever is the name of the column you are using as Doing
    2. Provide a token on ghToken with permissions:
      • Repository access to the repository(ies) holding the issues being manipulated
      • Organization permissions: Read access to members, Read and Write access to organization projects
      • Read and write access to Issues and Pull Requests
  2. Create an organization webhook pointing to your new val
    • Individual events: Project v2 items
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" },
);
};
augustohp-ghautoassignonwip.web.val.run
November 25, 2023