Skip to content

Commit

Permalink
Fix silent error bug (#30)
Browse files Browse the repository at this point in the history
* Fix silent error bug

* replace throw by setFailed
  • Loading branch information
luabida authored Dec 22, 2023
1 parent 85c2ded commit c67ca9c
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 94 deletions.
106 changes: 69 additions & 37 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
;
}
Expand All @@ -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();


/***/ }),
Expand Down Expand Up @@ -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__;
/******/
/******/ })()
;
10 changes: 5 additions & 5 deletions dist/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
;
}
Expand All @@ -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);
}
;
}
Expand Down
30 changes: 28 additions & 2 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,46 @@
"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() {
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");
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}`);
}
;
}
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 39 additions & 39 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
};
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit c67ca9c

Please sign in to comment.