Skip to content

Commit 4a71f13

Browse files
committed
bump: release
1 parent c6ec261 commit 4a71f13

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

dist/index.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ const core = __importStar(__nccwpck_require__(2186));
5959
*/
6060
async function checkCommitMessages(args) {
6161
// Check arguments
62-
if (args.pattern.length === 0) {
62+
if ((args.pattern === null &&
63+
args.progressivePattern === null) || (args.pattern === null &&
64+
args.progressivePattern !== null &&
65+
args.progressivePattern.length !== 0) || (args.progressivePattern === null &&
66+
args.pattern !== null &&
67+
args.pattern.length !== 0)) {
6368
throw new Error(`PATTERN not defined.`);
6469
}
6570
const regex = new RegExp('[^gimsuy]', 'g');
@@ -80,22 +85,34 @@ async function checkCommitMessages(args) {
8085
// Check messages
8186
let result = true;
8287
core.info(`Checking commit messages against "${args.pattern}"...`);
83-
let debugRegexMsg = '';
8488
for (const message of args.messages) {
85-
if (checkMessage(message.replaceAll('\r', ''), args.pattern, args.flags)) {
86-
core.info(`- OK: "${message}"`);
89+
if (args.pattern === null || args.pattern.length === 0) {
90+
const errorMessage = debugRegexMatching(args.progressivePattern, message);
91+
if (errorMessage !== null) {
92+
core.info(`- failed: "${message}"`);
93+
args.error += '\n' + errorMessage;
94+
result = false;
95+
}
96+
else {
97+
core.info(`- OK: "${message}"`);
98+
}
8799
}
88100
else {
89-
core.info(`- failed: "${message}"`);
90-
if (args.debugRegex !== null) {
91-
debugRegexMsg = '\n' + debugRegexMatching(args.debugRegex, message);
101+
if (checkMessage(message.replaceAll('\r', ''), args.pattern, args.flags)) {
102+
core.info(`- OK: "${message}"`);
103+
}
104+
else {
105+
core.info(`- failed: "${message}"`);
106+
if (args.progressivePattern !== null) {
107+
args.error += '\n' + (debugRegexMatching(args.progressivePattern, message) ?? 'Unexpected missmatch.');
108+
}
109+
result = false;
92110
}
93-
result = false;
94111
}
95112
}
96113
// Throw error in case of failed test
97114
if (!result) {
98-
throw new Error(args.error + debugRegexMsg);
115+
throw new Error(args.error);
99116
}
100117
}
101118
exports.checkCommitMessages = checkCommitMessages;
@@ -142,7 +159,7 @@ const debugRegexMatching = (regexes, str) => {
142159
regexes = regexes.splice(1);
143160
} while (regexes.length > 0);
144161
if (str.length === 0 && regexes.length === 0) {
145-
return "The regex should work.";
162+
return null;
146163
}
147164
else {
148165
const paddingLeft = Math.max(matchesUntil - 10, 0);
@@ -247,7 +264,7 @@ async function getInputs() {
247264
const result = {};
248265
core.debug('Get inputs...');
249266
// Get pattern
250-
result.pattern = core.getInput('pattern', { required: true });
267+
result.pattern = core.getInput('pattern');
251268
core.debug(`pattern: ${result.pattern}`);
252269
// Get flags
253270
result.flags = core.getInput('flags');
@@ -262,10 +279,10 @@ async function getInputs() {
262279
const excludeDescriptionStr = core.getInput('excludeDescription');
263280
core.debug(`excludeDescription: ${excludeDescriptionStr}`);
264281
// Debug regex
265-
const debugRegex = core.getInput('debugRegex');
266-
core.debug(`debugRegex: ${debugRegex}`);
267-
if (debugRegex.length > 0)
268-
result.debugRegex = JSON.parse(debugRegex);
282+
const progressivePattern = core.getInput('progressivePattern');
283+
core.debug(`progressivePattern: ${progressivePattern}`);
284+
if (progressivePattern.length > 0)
285+
result.progressivePattern = JSON.parse(progressivePattern);
269286
// Get checkAllCommitMessages
270287
const checkAllCommitMessagesStr = core.getInput('checkAllCommitMessages');
271288
core.debug(`checkAllCommitMessages: ${checkAllCommitMessagesStr}`);

0 commit comments

Comments
 (0)