mirror of
https://github.com/encounter/zed.git
synced 2026-07-11 06:19:04 -07:00
ci: Fix issue response script (#24891)
This PR fixes the issue response script. There were a number of things preventing it from working: - The directory name used in the GitHub Action did not match the one on disk. - The script has been moved accordingly - `ts-node` does not support ESM. - `ts-node` seems unmaintained, so I changed the script to be plain JS that is type-checked with TypeScript. - The data being sent to the Slack API was invalid: - Each section block can only have a maximum of 3000 characters in the `text` field, so we need to break up the issue list across multiple sections. - We needed to escape `&`, `<`, and `>` characters in the issue titles. Release Notes: - N/A
This commit is contained in:
@@ -27,7 +27,7 @@ jobs:
|
||||
- run: pnpm install --dir script/issue_response
|
||||
|
||||
- name: Run Issue Response
|
||||
run: pnpm exec ts-node script/issue_response/main.ts
|
||||
run: pnpm run --dir script/issue_response start
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SLACK_ISSUE_RESPONSE_WEBHOOK_URL: ${{ secrets.SLACK_ISSUE_RESPONSE_WEBHOOK_URL }}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { IncomingWebhook } from "@slack/webhook";
|
||||
|
||||
/**
|
||||
* The maximum length of the `text` in a section block.
|
||||
*
|
||||
* [Slack Docs](https://api.slack.com/reference/block-kit/blocks#section)
|
||||
*/
|
||||
const SECTION_BLOCK_TEXT_LIMIT = 3000;
|
||||
|
||||
async function main() {
|
||||
const octokit = new Octokit({ auth: process.env["GITHUB_TOKEN"] });
|
||||
|
||||
if (!process.env["SLACK_ISSUE_RESPONSE_WEBHOOK_URL"]) {
|
||||
throw new Error("SLACK_ISSUE_RESPONSE_WEBHOOK_URL is not set");
|
||||
}
|
||||
|
||||
const webhook = new IncomingWebhook(
|
||||
process.env["SLACK_ISSUE_RESPONSE_WEBHOOK_URL"],
|
||||
);
|
||||
|
||||
const owner = "zed-industries";
|
||||
const repo = "zed";
|
||||
const staff = await octokit.paginate(octokit.rest.orgs.listMembers, {
|
||||
org: owner,
|
||||
per_page: 100,
|
||||
});
|
||||
let staffHandles = staff.map((member) => member.login);
|
||||
let commenterFilters = staffHandles.map((name) => `-commenter:${name}`);
|
||||
let authorFilters = staffHandles.map((name) => `-author:${name}`);
|
||||
|
||||
const q = [
|
||||
`repo:${owner}/${repo}`,
|
||||
"is:issue",
|
||||
"state:open",
|
||||
"created:>=2025-02-01",
|
||||
"sort:created-asc",
|
||||
...commenterFilters,
|
||||
...authorFilters,
|
||||
];
|
||||
|
||||
const response = await octokit.rest.search.issuesAndPullRequests({
|
||||
q: q.join("+"),
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
let issues = response.data.items;
|
||||
let issueLines = issues.map((issue, index) => {
|
||||
const formattedDate = new Date(issue.created_at).toLocaleDateString(
|
||||
"en-US",
|
||||
{
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
},
|
||||
);
|
||||
const sanitizedTitle = issue.title
|
||||
.replaceAll("&", "&")
|
||||
.replaceAll("<", "<")
|
||||
.replaceAll(">", ">");
|
||||
|
||||
return `${index + 1}. ${formattedDate}: <${issue.html_url}|${sanitizedTitle}>\n`;
|
||||
});
|
||||
|
||||
const sections = [];
|
||||
/** @type {string[]} */
|
||||
let currentSection = [];
|
||||
let currentSectionLength = 0;
|
||||
|
||||
for (const issueLine of issueLines) {
|
||||
if (currentSectionLength + issueLine.length <= SECTION_BLOCK_TEXT_LIMIT) {
|
||||
currentSection.push(issueLine);
|
||||
currentSectionLength += issueLine.length;
|
||||
} else {
|
||||
sections.push(currentSection);
|
||||
currentSection = [];
|
||||
currentSectionLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSection.length > 0) {
|
||||
sections.push(currentSection);
|
||||
}
|
||||
|
||||
const blocks = sections.map((section) => ({
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: section.join("").trimEnd(),
|
||||
},
|
||||
}));
|
||||
|
||||
await webhook.send({ blocks });
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error("An error occurred:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "issue_response",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "main.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc -p .",
|
||||
"start": "node main.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^21.1.0",
|
||||
"@slack/webhook": "^7.0.4",
|
||||
"date-fns": "^4.1.0",
|
||||
"octokit": "^4.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/types": "^13.8.0",
|
||||
"@slack/types": "^2.14.0",
|
||||
"@tsconfig/node20": "20.1.4",
|
||||
"@tsconfig/strictest": "2.0.5",
|
||||
"typescript": "5.7.3"
|
||||
}
|
||||
}
|
||||
+108
-218
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": ["@tsconfig/node20/tsconfig.json", "@tsconfig/strictest/tsconfig.json"],
|
||||
"compilerOptions": {
|
||||
"checkJs": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": ["main.js"]
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { IncomingWebhook } from "@slack/webhook";
|
||||
|
||||
async function main() {
|
||||
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
|
||||
const webhook = new IncomingWebhook(
|
||||
process.env.SLACK_ISSUE_RESPONSE_WEBHOOK_URL!,
|
||||
);
|
||||
|
||||
const owner = "zed-industries";
|
||||
const repo = "zed";
|
||||
const staff = await octokit.paginate(octokit.rest.orgs.listMembers, {
|
||||
org: owner,
|
||||
per_page: 100,
|
||||
});
|
||||
let staffHandles = staff.map((member) => member.login);
|
||||
let commenterFilters = staffHandles.map((name) => `-commenter:${name}`);
|
||||
let authorFilters = staffHandles.map((name) => `-author:${name}`);
|
||||
|
||||
const q = [
|
||||
`repo:${owner}/${repo}`,
|
||||
"is:issue",
|
||||
"state:open",
|
||||
"created:>=2025-02-01",
|
||||
"sort:created-asc",
|
||||
...commenterFilters,
|
||||
...authorFilters,
|
||||
];
|
||||
|
||||
const response = await octokit.rest.search.issuesAndPullRequests({
|
||||
q: q.join("+"),
|
||||
per_page: 100,
|
||||
});
|
||||
|
||||
let issues = response.data.items;
|
||||
let issueLines = issues.map((issue, index) => {
|
||||
const formattedDate = new Date(issue.created_at).toLocaleDateString(
|
||||
"en-US",
|
||||
{
|
||||
year: "numeric",
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
},
|
||||
);
|
||||
return `${index + 1}. ${formattedDate}: <${issue.html_url}|${issue.title}>`;
|
||||
});
|
||||
|
||||
const blocks = [
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: issueLines.join("\n"),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
await webhook.send({ blocks: blocks });
|
||||
}
|
||||
|
||||
main().catch((error) => console.error("An error occurred:", error));
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^21.1.0",
|
||||
"@slack/webhook": "^7.0.4",
|
||||
"date-fns": "^4.1.0",
|
||||
"octokit": "^4.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@octokit/types": "^13.8.0",
|
||||
"@slack/types": "^2.14.0",
|
||||
"ts-node": "^10.9.2"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user