Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
305 changes: 131 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
},
"homepage": "https://docs.slack.dev/tools/slack-github-action/",
"dependencies": {
"@actions/core": "^2.0.1",
"@actions/github": "^7.0.0",
"@actions/core": "^3.0.0",
"@actions/github": "^9.0.0",
"@slack/logger": "^4.0.0",
"@slack/web-api": "^7.13.0",
"axios": "^1.13.4",
Expand Down
13 changes: 6 additions & 7 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import core from "@actions/core";
import webapi from "@slack/web-api";
import axios from "axios";
import Content from "./content.js";
Expand Down Expand Up @@ -94,7 +93,7 @@ export default class Config {
* kept for later use.
*
* @constructor
* @param {core} core - GitHub Actions core utilities.
* @param {import("@actions/core")} core - GitHub Actions core utilities.
*/
constructor(core) {
this.axios = axios;
Expand Down Expand Up @@ -132,18 +131,18 @@ export default class Config {
*/
mask() {
if (this.inputs.token) {
core.debug("Setting the provided token as a secret variable.");
core.setSecret(this.inputs.token);
this.core.debug("Setting the provided token as a secret variable.");
this.core.setSecret(this.inputs.token);
}
if (this.inputs.webhook) {
core.debug("Setting the provided webhook as a secret variable.");
core.setSecret(this.inputs.webhook);
this.core.debug("Setting the provided webhook as a secret variable.");
this.core.setSecret(this.inputs.webhook);
}
}

/**
* Confirm the configurations are correct enough to continue.
* @param {core} core - GitHub Actions core utilities.
* @param {import("@actions/core")} core - GitHub Actions core utilities.
*/
validate(core) {
switch (this.inputs.retries.trim().toUpperCase()) {
Expand Down
2 changes: 1 addition & 1 deletion src/content.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import github from "@actions/github";
import * as github from "@actions/github";
import { flatten } from "flat";
import yaml from "js-yaml";
import markup from "markup-js";
Expand Down
4 changes: 1 addition & 3 deletions src/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import core from "@actions/core";

/**
* @typedef Cause
* @property {Error[]} [values] - Caught exceptions.
Expand All @@ -15,7 +13,7 @@ export default class SlackError extends Error {
*/

/**
* @param {core} _core - GitHub Actions core utilities.
* @param {import("@actions/core")} _core - GitHub Actions core utilities.
* @param {any} error - The error message to throw.
* @param {Options} options - configurations of erroring.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import core from "@actions/core";
import * as core from "@actions/core";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️‍🗨️ note: This is now recognized as the single import of @actions/core since other references can be shown in "jsdoc" for typechecking!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks for the note!

import send from "./send.js";

/**
Expand Down
3 changes: 1 addition & 2 deletions src/send.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import core from "@actions/core";
import Client from "./client.js";
import Config from "./config.js";
import SlackError from "./errors.js";
import Webhook from "./webhook.js";

/**
* Orchestrate the action job happenings from inputs to logic to outputs.
* @param {core} core - GitHub Actions core utilities.
* @param {import("@actions/core")} core - GitHub Actions core utilities.
* @throws if an error happens but might not cause the job to fail.
*/
export default async function send(core) {
Expand Down
13 changes: 6 additions & 7 deletions test/client.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from "node:assert";
import { beforeEach, describe, it } from "node:test";
import core from "@actions/core";
import webapi from "@slack/web-api";
import errors from "@slack/web-api/dist/errors.js";
import sinon from "sinon";
Expand All @@ -22,7 +21,7 @@ describe("client", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {
token: "xoxb-example",
},
Expand All @@ -44,7 +43,7 @@ describe("client", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {
method: "chat.postMessage",
},
Expand Down Expand Up @@ -79,8 +78,8 @@ describe("client", () => {
timestamp: "1234567890.000000",
},
},
core: core,
logger: new Logger(core).logger,
core: mocks.core,
logger: new Logger(mocks.core).logger,
inputs: {
method: "pins.add",
token: "xoxb-example-002",
Expand Down Expand Up @@ -124,8 +123,8 @@ describe("client", () => {
stream: false,
},
},
core: core,
logger: new Logger(core).logger,
core: mocks.core,
logger: new Logger(mocks.core).logger,
inputs: {
api: "http://localhost:11434/api/",
method: "generate",
Expand Down
5 changes: 2 additions & 3 deletions test/content.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import assert from "node:assert";
import path from "node:path";
import { beforeEach, describe, it } from "node:test";
import core from "@actions/core";
import { YAMLException } from "js-yaml";
import Config from "../src/config.js";
import Content from "../src/content.js";
Expand Down Expand Up @@ -270,7 +269,7 @@ describe("content", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {
payloadFilePath: "unknown.json",
},
Expand Down Expand Up @@ -534,7 +533,7 @@ describe("content", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {
payload: "LGTM",
},
Expand Down
23 changes: 21 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from "node:fs";
import core from "@actions/core";
import webapi from "@slack/web-api";
import axios, { AxiosError } from "axios";
import sinon from "sinon";
Expand Down Expand Up @@ -45,7 +44,18 @@ export class Mock {
this.sandbox = sinon.createSandbox();
this.axios = this.sandbox.stub(axios);
this.calls = this.sandbox.stub(webapi.WebClient.prototype, "apiCall");
this.core = this.sandbox.stub(core);
this.core = {
debug: this.sandbox.stub(),
error: this.sandbox.stub(),
getInput: this.sandbox.stub(),
getBooleanInput: this.sandbox.stub(),
info: this.sandbox.stub(),
isDebug: this.sandbox.stub(),
setFailed: this.sandbox.stub(),
setOutput: this.sandbox.stub(),
setSecret: this.sandbox.stub(),
warning: this.sandbox.stub(),
};
this.fs = this.sandbox.stub(fs);
this.webapi = {
WebClient: function () {
Expand All @@ -65,7 +75,16 @@ export class Mock {
this.sandbox.reset();
this.axios.post.resetHistory();
this.calls.resetHistory();
this.core.debug.reset();
this.core.error.reset();
this.core.getInput.reset();
this.core.getBooleanInput.reset();
this.core.info.reset();
this.core.isDebug.reset();
this.core.setFailed.reset();
this.core.setOutput.reset();
this.core.setSecret.reset();
this.core.warning.reset();
this.webapi = {
WebClient: function () {
this.apiCall = () => ({
Expand Down
9 changes: 4 additions & 5 deletions test/logger.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from "node:assert";
import { beforeEach, describe, it } from "node:test";
import core from "@actions/core";
import { LogLevel } from "@slack/logger";
import Logger from "../src/logger.js";
import { mocks } from "./index.spec.js";
Expand All @@ -12,16 +11,16 @@ describe("logger", () => {

describe("level", () => {
it("debug", () => {
mocks.core.isDebug = () => true;
const { logger } = new Logger(core);
mocks.core.isDebug.returns(true);
const { logger } = new Logger(mocks.core);
const actual = logger.getLevel();
const expected = LogLevel.DEBUG;
assert.strictEqual(actual, expected);
});

it("info", () => {
mocks.core.isDebug = () => false;
const { logger } = new Logger(core);
mocks.core.isDebug.returns(false);
const { logger } = new Logger(mocks.core);
const actual = logger.getLevel();
const expected = LogLevel.INFO;
assert.strictEqual(actual, expected);
Expand Down
5 changes: 2 additions & 3 deletions test/webhook.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import assert from "node:assert";
import { beforeEach, describe, it } from "node:test";
import core from "@actions/core";
import { AxiosError } from "axios";
import Config from "../src/config.js";
import SlackError from "../src/errors.js";
Expand Down Expand Up @@ -77,7 +76,7 @@ describe("webhook", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {},
};
try {
Expand Down Expand Up @@ -169,7 +168,7 @@ describe("webhook", () => {
* @type {Config}
*/
const config = {
core: core,
core: mocks.core,
inputs: {},
};
try {
Expand Down