Skip to content

Commit 625733c

Browse files
authored
Merge pull request #152 from peter-evans/fix-any
fix: replace use of any type
2 parents eb502e5 + 8740008 commit 625733c

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

dist/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ exports.GitHubHelper = void 0;
272272
const core = __importStar(__nccwpck_require__(2186));
273273
const octokit_client_1 = __nccwpck_require__(5040);
274274
const util_1 = __nccwpck_require__(3837);
275+
const utils = __importStar(__nccwpck_require__(918));
275276
class GitHubHelper {
276277
constructor(token) {
277278
this.octokit = new octokit_client_1.Octokit({
@@ -313,7 +314,7 @@ class GitHubHelper {
313314
yield this.octokit.rest.reactions.createForIssueComment(Object.assign(Object.assign({}, repo), { comment_id: commentId, content: reaction }));
314315
}
315316
catch (error) {
316-
core.debug(error);
317+
core.debug(utils.getErrorMessage(error));
317318
core.warning(`Failed to set reaction on comment ID ${commentId}.`);
318319
}
319320
});
@@ -415,6 +416,7 @@ const github = __importStar(__nccwpck_require__(5438));
415416
const util_1 = __nccwpck_require__(3837);
416417
const command_helper_1 = __nccwpck_require__(9622);
417418
const github_helper_1 = __nccwpck_require__(446);
419+
const utils = __importStar(__nccwpck_require__(918));
418420
function run() {
419421
return __awaiter(this, void 0, void 0, function* () {
420422
try {
@@ -543,7 +545,7 @@ function run() {
543545
}
544546
catch (error) {
545547
core.debug((0, util_1.inspect)(error));
546-
const message = error.message;
548+
const message = utils.getErrorMessage(error);
547549
// Handle validation errors from workflow dispatch
548550
if (message.startsWith('Unexpected inputs provided') ||
549551
(message.startsWith('Required input') &&
@@ -554,7 +556,7 @@ function run() {
554556
core.warning(message);
555557
}
556558
else {
557-
core.setFailed(error.message);
559+
core.setFailed(message);
558560
}
559561
}
560562
});
@@ -619,7 +621,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
619621
return result;
620622
};
621623
Object.defineProperty(exports, "__esModule", ({ value: true }));
622-
exports.getStringAsArray = exports.getInputAsArray = void 0;
624+
exports.getErrorMessage = exports.getStringAsArray = exports.getInputAsArray = void 0;
623625
const core = __importStar(__nccwpck_require__(2186));
624626
function getInputAsArray(name, options) {
625627
return getStringAsArray(core.getInput(name, options));
@@ -632,6 +634,12 @@ function getStringAsArray(str) {
632634
.filter(x => x !== '');
633635
}
634636
exports.getStringAsArray = getStringAsArray;
637+
function getErrorMessage(error) {
638+
if (error instanceof Error)
639+
return error.message;
640+
return String(error);
641+
}
642+
exports.getErrorMessage = getErrorMessage;
635643

636644

637645
/***/ }),

src/github-helper.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core'
22
import {Octokit, PullsGetResponseData} from './octokit-client'
33
import {Command, SlashCommandPayload} from './command-helper'
44
import {inspect} from 'util'
5+
import * as utils from './utils'
56

67
type ReposCreateDispatchEventParamsClientPayload = {
78
[key: string]: ReposCreateDispatchEventParamsClientPayloadKeyString
@@ -101,8 +102,8 @@ export class GitHubHelper {
101102
comment_id: commentId,
102103
content: reaction
103104
})
104-
} catch (error: any) {
105-
core.debug(error)
105+
} catch (error) {
106+
core.debug(utils.getErrorMessage(error))
106107
core.warning(`Failed to set reaction on comment ID ${commentId}.`)
107108
}
108109
}

src/main.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
getSlashCommandPayload
1111
} from './command-helper'
1212
import {GitHubHelper, ClientPayload} from './github-helper'
13+
import * as utils from './utils'
1314

1415
async function run(): Promise<void> {
1516
try {
@@ -189,9 +190,9 @@ async function run(): Promise<void> {
189190
commentId,
190191
'rocket'
191192
)
192-
} catch (error: any) {
193+
} catch (error) {
193194
core.debug(inspect(error))
194-
const message: string = error.message
195+
const message: string = utils.getErrorMessage(error)
195196
// Handle validation errors from workflow dispatch
196197
if (
197198
message.startsWith('Unexpected inputs provided') ||
@@ -203,7 +204,7 @@ async function run(): Promise<void> {
203204
core.setOutput('error-message', message)
204205
core.warning(message)
205206
} else {
206-
core.setFailed(error.message)
207+
core.setFailed(message)
207208
}
208209
}
209210
}

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ export function getStringAsArray(str: string): string[] {
1313
.map(s => s.trim())
1414
.filter(x => x !== '')
1515
}
16+
17+
export function getErrorMessage(error: unknown) {
18+
if (error instanceof Error) return error.message
19+
return String(error)
20+
}

0 commit comments

Comments
 (0)