-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.mts
56 lines (49 loc) · 1.57 KB
/
index.mts
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
49
50
51
52
53
54
55
56
import { GraphQlQueryResponseData } from "@octokit/graphql";
import { Octokit } from "@octokit/rest";
import process from "node:process";
import core from "@actions/core";
import fs from "fs";
// The project ID for the Docs project.
// You can find this by running the `project-id.graphql` query.
const PROJECT_ID = "PVT_kwDOAG3Mbc027w";
const ISSUES_QUERY = fs.readFileSync("issues.graphql", "utf8");
const ADD_TO_PROJECT_MUTATION = fs.readFileSync(
"add-to-project.graphql",
"utf8",
);
async function addIssuesToProject(): Promise<Array<string>> {
const added: Array<string> = [];
try {
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const issues = (
(await octokit.graphql(ISSUES_QUERY)) as GraphQlQueryResponseData
).search.nodes;
for (const issue of issues) {
console.log(
`Adding issue ${issue.title} (${issue.url}) to the Docs project.`,
);
added.push(
// https://api.slack.com/reference/surfaces/formatting#escaping
`${issue.url}|${issue.title}`
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">"),
);
await octokit.graphql(ADD_TO_PROJECT_MUTATION, {
projectId: PROJECT_ID,
contentId: issue.id,
});
}
} catch (error: any) {
console.error("Error adding issues to the project:", error.message);
core.setFailed(error.message);
}
return added;
}
const added = await addIssuesToProject();
core.setOutput(
"added",
added.map((issue) => `- <${issue}>`.replaceAll('"', '\\"')).join("\\n"),
);