Skip to content

Commit

Permalink
change: add retry option, and reduce default retry count to 3 from 10
Browse files Browse the repository at this point in the history
  • Loading branch information
MeilCli committed Feb 9, 2022
1 parent e10b01f commit fa66b1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ inputs:
description: 'Provide another message`s ts value to upload this file as a reply. Never use a reply`s ts value; use its parent instead.'
title:
description: 'Title of file.'
retries:
description: 'max API retry count. default retries is 3'
outputs:
response:
description: 'the api response'
Expand Down
17 changes: 16 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as core from "@actions/core";
import * as slack from "@slack/web-api";
import * as fs from "fs";

const defaultMaxRetryCount = 3;

interface Option {
slackToken: string;
slackApiUrl: string | undefined;
Expand All @@ -13,6 +15,7 @@ interface Option {
initialComment: string | undefined;
threadTs: string | undefined;
title: string | undefined;
retries: number | undefined;
}

function getInput(key: string): string {
Expand All @@ -27,6 +30,14 @@ function getInputOrUndefined(key: string): string | undefined {
return result;
}

function getInputNumberOrUndefined(key: string): number | undefined {
const value = getInputOrUndefined(key);
if (value == undefined) {
return undefined;
}
return parseInt(value);
}

function readOption(): Option {
return {
slackToken: getInput("slack_token"),
Expand All @@ -39,13 +50,17 @@ function readOption(): Option {
initialComment: getInputOrUndefined("initial_comment"),
threadTs: getInputOrUndefined("thread_ts"),
title: getInputOrUndefined("title"),
retries: getInputNumberOrUndefined("retries"),
};
}

async function run() {
try {
const option = readOption();
const client = new slack.WebClient(option.slackToken, { slackApiUrl: option.slackApiUrl });
const client = new slack.WebClient(option.slackToken, {
slackApiUrl: option.slackApiUrl,
retryConfig: { retries: option.retries ?? defaultMaxRetryCount },
});
let file: Buffer | undefined;
if (option.filePath) {
file = fs.readFileSync(option.filePath);
Expand Down

0 comments on commit fa66b1d

Please sign in to comment.