Skip to content

Commit fa03fe4

Browse files
authored
refactor: send webhooks with the @slack/webhook package (#630)
1 parent 0539f0d commit fa03fe4

10 files changed

Lines changed: 298 additions & 311 deletions

File tree

.changeset/webhook-trigger-sdk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@slack/slack-github-action": patch
3+
---
4+
5+
refactor: send webhooks with the [`@slack/webhook`](https://docs.slack.dev/tools/node-slack-sdk/webhook) package

package-lock.json

Lines changed: 83 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
"@actions/github": "^9.1.1",
4747
"@slack/logger": "^4.0.1",
4848
"@slack/web-api": "^7.16.0",
49-
"axios": "^1.18.1",
50-
"axios-retry": "^4.5.0",
49+
"@slack/webhook": "^7.2.0",
5150
"flat": "^6.0.1",
5251
"https-proxy-agent": "^9.0.0",
5352
"js-yaml": "^5.2.0",

src/config.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import os from "node:os";
21
import webapi from "@slack/web-api";
3-
import axios from "axios";
2+
import webhook from "@slack/webhook";
43
import packageJson from "../package.json" with { type: "json" };
54
import Content from "./content.js";
65
import SlackError from "./errors.js";
@@ -60,11 +59,6 @@ export default class Config {
6059
*/
6160
inputs;
6261

63-
/**
64-
* @type {import("axios").AxiosStatic} - The axios client.
65-
*/
66-
axios;
67-
6862
/**
6963
* @type {Content} - The parsed payload data to send.
7064
*/
@@ -87,6 +81,11 @@ export default class Config {
8781
*/
8882
webapi;
8983

84+
/**
85+
* @type {import("@slack/webhook")} - Slack webhook client.
86+
*/
87+
webhook;
88+
9089
/**
9190
* Gather values from the job inputs and use defaults or error for the missing
9291
* ones.
@@ -98,10 +97,10 @@ export default class Config {
9897
* @param {import("@actions/core")} core - GitHub Actions core utilities.
9998
*/
10099
constructor(core) {
101-
this.axios = axios;
102100
this.core = core;
103101
this.logger = new Logger(core).logger;
104102
this.webapi = webapi;
103+
this.webhook = webhook;
105104
this.inputs = {
106105
api: core.getInput("api"),
107106
errors: core.getBooleanInput("errors"),
@@ -137,11 +136,10 @@ export default class Config {
137136
name: packageJson.name,
138137
version: packageJson.version,
139138
});
140-
this.axios.defaults.headers.common["User-Agent"] =
141-
`${packageJson.name.replace("/", ":")}/${packageJson.version} ` +
142-
`axios/${this.axios.VERSION} ` +
143-
`node/${process.version.replace("v", "")} ` +
144-
`${os.platform()}/${os.release()}`;
139+
this.webhook.addAppMetadata({
140+
name: packageJson.name,
141+
version: packageJson.version,
142+
});
145143
}
146144

147145
/**

0 commit comments

Comments
 (0)