main.ts

 1import { Octokit } from "@octokit/rest";
 2import { IncomingWebhook } from "@slack/webhook";
 3
 4async function main() {
 5  const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
 6  const webhook = new IncomingWebhook(
 7    process.env.SLACK_ISSUE_RESPONSE_WEBHOOK_URL!,
 8  );
 9
10  const owner = "zed-industries";
11  const repo = "zed";
12  const staff = await octokit.paginate(octokit.rest.orgs.listMembers, {
13    org: owner,
14    per_page: 100,
15  });
16  let staffHandles = staff.map((member) => member.login);
17  let commenterFilters = staffHandles.map((name) => `-commenter:${name}`);
18  let authorFilters = staffHandles.map((name) => `-author:${name}`);
19
20  const q = [
21    `repo:${owner}/${repo}`,
22    "is:issue",
23    "state:open",
24    "created:>=2025-02-01",
25    "sort:created-asc",
26    ...commenterFilters,
27    ...authorFilters,
28  ];
29
30  const response = await octokit.rest.search.issuesAndPullRequests({
31    q: q.join("+"),
32    per_page: 100,
33  });
34
35  let issues = response.data.items;
36  let issueLines = issues.map((issue, index) => {
37    const formattedDate = new Date(issue.created_at).toLocaleDateString(
38      "en-US",
39      {
40        year: "numeric",
41        month: "short",
42        day: "numeric",
43      },
44    );
45    return `${index + 1}. ${formattedDate}: <${issue.html_url}|${issue.title}>`;
46  });
47
48  const blocks = [
49    {
50      type: "section",
51      text: {
52        type: "mrkdwn",
53        text: issueLines.join("\n"),
54      },
55    },
56  ];
57
58  await webhook.send({ blocks: blocks });
59}
60
61main().catch((error) => console.error("An error occurred:", error));