File size: 1,079 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { config } from "dotenv"
import { readFile } from "fs/promises"
import fetch from "node-fetch"

config()

async function getLatestVersion() {
  const packageJson = await readFile("packages/react/package.json", "utf-8")
  const { version } = JSON.parse(packageJson)
  return version
}

export async function main() {
  const url = process.env.SLACK_WEBHOOK_URL

  if (!url) {
    throw new Error("Missing Slack Webhook URL")
  }

  const version = await getLatestVersion()

  const response = await fetch(url, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      project: "chakra-ui",
      version,
      url: `https://github.com/chakra-ui/chakra-ui/blob/main/.changelog/v3#${version}`,
      discord:
        "https://discordapp.com/channels/660863154703695893/660865232004055050",
      twitter: "https://twitter.com/chakra_ui",
    }),
  })

  if (response.ok) {
    console.log("✅ Successfully sent message to Slack")
  } else {
    console.error("❌ Failed to send message to Slack")
  }
}

main()