From 300f201d1c9a9f31f7cfa265d5a70ec929338b4f Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sun, 28 Jul 2024 22:20:50 +0800 Subject: [PATCH] fix: handle errors. --- dist/index.js | 2 +- src/index.ts | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/dist/index.js b/dist/index.js index f0b0b1f..8257d25 100644 --- a/dist/index.js +++ b/dist/index.js @@ -37891,7 +37891,7 @@ function _Le() { } ;// CONCATENATED MODULE: ./src/index.ts -function convertToNumber(str){var num=+str;return isNaN(num)?5:num;};(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var folderPath,exclude,depth,_context$repo,owner,repo,dtreeOptions,dreeResult;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:folderPath=(0,core.getInput)('path')||".";exclude=(0,core.getInput)('exclude');depth=convertToNumber((0,core.getInput)('depth')||"5");_context$repo=github.context.repo,owner=_context$repo.owner,repo=_context$repo.repo;dtreeOptions={depth:depth};if(exclude){dtreeOptions.exclude=new RegExp(exclude);}dreeResult=Ie(folderPath,dtreeOptions);(0,core.startGroup)("\x1B[32;1m ".concat(owner,"/").concat(repo," \x1B[0m tree: "));(0,core.info)("".concat(dreeResult));(0,core.endGroup)();(0,core.setOutput)('content',dreeResult);case 11:case"end":return _context.stop();}},_callee);}))(); +function convertToNumber(str){var num=+str;return isNaN(num)?5:num;};(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var folderPath,exclude,depth,_context$repo,owner,repo,dtreeOptions,dreeResult;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:folderPath=(0,core.getInput)('path')||".";exclude=(0,core.getInput)('exclude');depth=convertToNumber((0,core.getInput)('depth')||"5");_context$repo=github.context.repo,owner=_context$repo.owner,repo=_context$repo.repo;dtreeOptions={depth:depth};try{if(exclude){dtreeOptions.exclude=new RegExp(exclude);}dreeResult=Ie(folderPath,dtreeOptions);(0,core.startGroup)("\x1B[32;1m ".concat(owner,"/").concat(repo," \x1B[0m tree: "));(0,core.info)("".concat(dreeResult));(0,core.endGroup)();(0,core.setOutput)('content',dreeResult);}catch(error){(0,core.setFailed)(error);}case 6:case"end":return _context.stop();}},_callee);}))(); })(); module.exports = __webpack_exports__; diff --git a/src/index.ts b/src/index.ts index 791693e..33b3732 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { context } from '@actions/github'; -import { getInput, setOutput, startGroup, info, endGroup } from '@actions/core'; +import { getInput, setOutput, setFailed, startGroup, info, endGroup } from '@actions/core'; import { parse, ParseOptions } from 'dree'; function convertToNumber(str: string): number { @@ -15,14 +15,16 @@ function convertToNumber(str: string): number { const dtreeOptions: ParseOptions = { depth }; - if (exclude) { - dtreeOptions.exclude = new RegExp(exclude); + try { + if (exclude) { + dtreeOptions.exclude = new RegExp(exclude); + } + const dreeResult = parse(folderPath, dtreeOptions); + startGroup(`\x1b[32;1m ${owner}/${repo} \x1b[0m tree: `); + info(`${dreeResult}`); + endGroup(); + setOutput('content', dreeResult); + } catch (error) { + setFailed(error as Error); } - - const dreeResult = parse(folderPath, dtreeOptions); - - startGroup(`\x1b[32;1m ${owner}/${repo} \x1b[0m tree: `); - info(`${dreeResult}`); - endGroup(); - setOutput('content', dreeResult); })(); \ No newline at end of file