From c67ca9c687967721b9b351970ff8c65fc5658dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=A3=20Bida=20Vacaro?= Date: Fri, 22 Dec 2023 14:51:20 -0300 Subject: [PATCH] Fix silent error bug (#30) * Fix silent error bug * replace throw by setFailed --- dist/index.js | 106 ++++++++++++++++++++++++++++++---------------- dist/linter.js | 10 ++--- dist/main.js | 30 ++++++++++++- package-lock.json | 1 - src/linter.ts | 78 +++++++++++++++++----------------- src/main.ts | 22 +++++----- 6 files changed, 153 insertions(+), 94 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3ce8f24..68fd584 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9555,14 +9555,13 @@ function linter(title) { let splitTitle = extractContext(title, preset); let tag = splitTitle[0]; if (!allowedTags.includes(tag)) { - throw (`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`); + core.setFailed(`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`); } ; console.log("✅ PR title is correct!"); } catch (err) { - console.log("❌ Incorrect PR title."); - throw (err); + core.setFailed("❌ Incorrect PR title."); } ; } @@ -9574,17 +9573,75 @@ function extractContext(title, preset) { try { let results = Array.from(matches)[0].filter(Boolean).splice(1); if (results.length === 4 && preset !== `conventionalcommits`) { - throw ("- To use '!' in the title, set preset as `convenvionalcommits`"); + core.setFailed("- To use '!' in the title, set preset as `conventionalcommits`"); } ; return results; } catch (err) { - throw (`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`); + core.setFailed(`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`); + throw (err); + } + ; +} +; + + +/***/ }), + +/***/ 5881: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.run = void 0; +const core = __importStar(__nccwpck_require__(8864)); +const github_1 = __nccwpck_require__(6366); +const linter_1 = __nccwpck_require__(8116); +function run() { + var _a; + try { + let pullRequestTitle = (_a = github_1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.title; + if (!pullRequestTitle) { + core.setFailed("- Title not found"); + return; + } + ; + (0, linter_1.linter)(pullRequestTitle); + } + catch (err) { + console.log(err); + core.setFailed(`❌ PR Title linter failed\n${err}`); } ; } +exports.run = run; ; +run(); /***/ }), @@ -9763,37 +9820,12 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ -var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be in strict mode. -(() => { -"use strict"; -var exports = __webpack_exports__; - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.run = void 0; -const github_1 = __nccwpck_require__(6366); -const linter_1 = __nccwpck_require__(8116); -function run() { - var _a; - try { - let pullRequestTitle = (_a = github_1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.title; - if (!pullRequestTitle) { - throw ("- Title not found"); - } - ; - (0, linter_1.linter)(pullRequestTitle); - } - catch (err) { - console.log(`❌ PR Title linter failed\n${err}`); - } - ; -} -exports.run = run; -; -run(); - -})(); - -module.exports = __webpack_exports__; +/******/ +/******/ // startup +/******/ // Load entry module and return exports +/******/ // This entry module is referenced by other modules so it can't be inlined +/******/ var __webpack_exports__ = __nccwpck_require__(5881); +/******/ module.exports = __webpack_exports__; +/******/ /******/ })() ; \ No newline at end of file diff --git a/dist/linter.js b/dist/linter.js index 1320915..e002f99 100644 --- a/dist/linter.js +++ b/dist/linter.js @@ -42,14 +42,13 @@ function linter(title) { let splitTitle = extractContext(title, preset); let tag = splitTitle[0]; if (!allowedTags.includes(tag)) { - throw (`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`); + core.setFailed(`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`); } ; console.log("✅ PR title is correct!"); } catch (err) { - console.log("❌ Incorrect PR title."); - throw (err); + core.setFailed("❌ Incorrect PR title."); } ; } @@ -61,13 +60,14 @@ function extractContext(title, preset) { try { let results = Array.from(matches)[0].filter(Boolean).splice(1); if (results.length === 4 && preset !== `conventionalcommits`) { - throw ("- To use '!' in the title, set preset as `convenvionalcommits`"); + core.setFailed("- To use '!' in the title, set preset as `conventionalcommits`"); } ; return results; } catch (err) { - throw (`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`); + core.setFailed(`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`); + throw (err); } ; } diff --git a/dist/main.js b/dist/main.js index c8196be..46a9d85 100644 --- a/dist/main.js +++ b/dist/main.js @@ -1,6 +1,30 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.run = void 0; +const core = __importStar(require("@actions/core")); const github_1 = require("@actions/github"); const linter_1 = require("./linter"); function run() { @@ -8,13 +32,15 @@ function run() { try { let pullRequestTitle = (_a = github_1.context.payload.pull_request) === null || _a === void 0 ? void 0 : _a.title; if (!pullRequestTitle) { - throw ("- Title not found"); + core.setFailed("- Title not found"); + return; } ; (0, linter_1.linter)(pullRequestTitle); } catch (err) { - console.log(`❌ PR Title linter failed\n${err}`); + console.log(err); + core.setFailed(`❌ PR Title linter failed\n${err}`); } ; } diff --git a/package-lock.json b/package-lock.json index 733597f..00dd69b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1489,4 +1489,3 @@ } } } - diff --git a/src/linter.ts b/src/linter.ts index f6261f5..b4bd81d 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -3,53 +3,53 @@ import * as core from "@actions/core"; export function linter(title: string) { - let allowedTags = [ - "build", - "ci", - "chore", - "docs", - "feat", - "fix", - "perf", - "refactor", - "test", - ]; - - let preset: string = core.getInput(`convention-name`, { required: false }).toLowerCase(); - - try { - let splitTitle = extractContext(title, preset); - let tag = splitTitle[0]; - - if (!allowedTags.includes(tag)) { - throw(`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`) - }; - - console.log("✅ PR title is correct!"); - - } catch (err) { - console.log("❌ Incorrect PR title.") - throw(err) + let allowedTags = [ + "build", + "ci", + "chore", + "docs", + "feat", + "fix", + "perf", + "refactor", + "test", + ]; + + let preset: string = core.getInput(`convention-name`, { required: false }).toLowerCase(); + + try { + let splitTitle = extractContext(title, preset); + let tag = splitTitle[0]; + + if (!allowedTags.includes(tag)) { + core.setFailed(`- Incorrect PR tag: "${tag}" is not accepted by Semantic-Release`) }; + + console.log("✅ PR title is correct!"); + + } catch (err) { + core.setFailed("❌ Incorrect PR title.") + }; }; function extractContext(title: string, preset: string): string[] { - let regEx: RegExp = /(^[\w\s?]+)(\(.+\)(!?):\s)([^A-Z\W].*[^.]$)/g; - - let matches = title.matchAll(regEx); - - try { - let results = Array.from(matches)[0].filter(Boolean).splice(1); + let regEx: RegExp = /(^[\w\s?]+)(\(.+\)(!?):\s)([^A-Z\W].*[^.]$)/g; - if (results.length === 4 && preset !== `conventionalcommits`) { - throw("- To use '!' in the title, set preset as `convenvionalcommits`"); - }; + let matches = title.matchAll(regEx); - return results; + try { + let results = Array.from(matches)[0].filter(Boolean).splice(1); - } catch (err) { - throw(`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`) + if (results.length === 4 && preset !== `conventionalcommits`) { + core.setFailed("- To use '!' in the title, set preset as `conventionalcommits`"); }; + + return results; + + } catch (err) { + core.setFailed(`${err}\n- "${title}" format is incorrect. Please use Angular Commit Message Conventions`) + throw (err) + }; }; diff --git a/src/main.ts b/src/main.ts index c8914d3..7cc578e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,21 +1,23 @@ +import * as core from "@actions/core"; import { context } from '@actions/github' import { linter } from './linter' export function run() { - try { - let pullRequestTitle: string = context.payload.pull_request?.title; + try { + let pullRequestTitle: string = context.payload.pull_request?.title; - if (!pullRequestTitle) { - throw("- Title not found"); - }; + if (!pullRequestTitle) { + core.setFailed("- Title not found"); + return; + }; - linter(pullRequestTitle); + linter(pullRequestTitle); - } catch (err) { - console.log(`❌ PR Title linter failed\n${ err }`); - throw(err); - }; + } catch (err) { + console.log(err); + core.setFailed(`❌ PR Title linter failed\n${err}`); + }; }; run();