Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace use of any type #152

Merged
merged 1 commit into from
Oct 21, 2022
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
16 changes: 12 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ exports.GitHubHelper = void 0;
const core = __importStar(__nccwpck_require__(2186));
const octokit_client_1 = __nccwpck_require__(5040);
const util_1 = __nccwpck_require__(3837);
const utils = __importStar(__nccwpck_require__(918));
class GitHubHelper {
constructor(token) {
this.octokit = new octokit_client_1.Octokit({
Expand Down Expand Up @@ -313,7 +314,7 @@ class GitHubHelper {
yield this.octokit.rest.reactions.createForIssueComment(Object.assign(Object.assign({}, repo), { comment_id: commentId, content: reaction }));
}
catch (error) {
core.debug(error);
core.debug(utils.getErrorMessage(error));
core.warning(`Failed to set reaction on comment ID ${commentId}.`);
}
});
Expand Down Expand Up @@ -415,6 +416,7 @@ const github = __importStar(__nccwpck_require__(5438));
const util_1 = __nccwpck_require__(3837);
const command_helper_1 = __nccwpck_require__(9622);
const github_helper_1 = __nccwpck_require__(446);
const utils = __importStar(__nccwpck_require__(918));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -543,7 +545,7 @@ function run() {
}
catch (error) {
core.debug((0, util_1.inspect)(error));
const message = error.message;
const message = utils.getErrorMessage(error);
// Handle validation errors from workflow dispatch
if (message.startsWith('Unexpected inputs provided') ||
(message.startsWith('Required input') &&
Expand All @@ -554,7 +556,7 @@ function run() {
core.warning(message);
}
else {
core.setFailed(error.message);
core.setFailed(message);
}
}
});
Expand Down Expand Up @@ -619,7 +621,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getStringAsArray = exports.getInputAsArray = void 0;
exports.getErrorMessage = exports.getStringAsArray = exports.getInputAsArray = void 0;
const core = __importStar(__nccwpck_require__(2186));
function getInputAsArray(name, options) {
return getStringAsArray(core.getInput(name, options));
Expand All @@ -632,6 +634,12 @@ function getStringAsArray(str) {
.filter(x => x !== '');
}
exports.getStringAsArray = getStringAsArray;
function getErrorMessage(error) {
if (error instanceof Error)
return error.message;
return String(error);
}
exports.getErrorMessage = getErrorMessage;


/***/ }),
Expand Down
5 changes: 3 additions & 2 deletions src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as core from '@actions/core'
import {Octokit, PullsGetResponseData} from './octokit-client'
import {Command, SlashCommandPayload} from './command-helper'
import {inspect} from 'util'
import * as utils from './utils'

type ReposCreateDispatchEventParamsClientPayload = {
[key: string]: ReposCreateDispatchEventParamsClientPayloadKeyString
Expand Down Expand Up @@ -101,8 +102,8 @@ export class GitHubHelper {
comment_id: commentId,
content: reaction
})
} catch (error: any) {
core.debug(error)
} catch (error) {
core.debug(utils.getErrorMessage(error))
core.warning(`Failed to set reaction on comment ID ${commentId}.`)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getSlashCommandPayload
} from './command-helper'
import {GitHubHelper, ClientPayload} from './github-helper'
import * as utils from './utils'

async function run(): Promise<void> {
try {
Expand Down Expand Up @@ -189,9 +190,9 @@ async function run(): Promise<void> {
commentId,
'rocket'
)
} catch (error: any) {
} catch (error) {
core.debug(inspect(error))
const message: string = error.message
const message: string = utils.getErrorMessage(error)
// Handle validation errors from workflow dispatch
if (
message.startsWith('Unexpected inputs provided') ||
Expand All @@ -203,7 +204,7 @@ async function run(): Promise<void> {
core.setOutput('error-message', message)
core.warning(message)
} else {
core.setFailed(error.message)
core.setFailed(message)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ export function getStringAsArray(str: string): string[] {
.map(s => s.trim())
.filter(x => x !== '')
}

export function getErrorMessage(error: unknown) {
if (error instanceof Error) return error.message
return String(error)
}