@@ -59,7 +59,12 @@ const core = __importStar(__nccwpck_require__(2186));
59
59
*/
60
60
async function checkCommitMessages(args) {
61
61
// 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)) {
63
68
throw new Error(`PATTERN not defined.`);
64
69
}
65
70
const regex = new RegExp('[^gimsuy]', 'g');
@@ -80,22 +85,34 @@ async function checkCommitMessages(args) {
80
85
// Check messages
81
86
let result = true;
82
87
core.info(`Checking commit messages against "${args.pattern}"...`);
83
- let debugRegexMsg = '';
84
88
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
+ }
87
99
}
88
100
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;
92
110
}
93
- result = false;
94
111
}
95
112
}
96
113
// Throw error in case of failed test
97
114
if (!result) {
98
- throw new Error(args.error + debugRegexMsg );
115
+ throw new Error(args.error);
99
116
}
100
117
}
101
118
exports.checkCommitMessages = checkCommitMessages;
@@ -142,7 +159,7 @@ const debugRegexMatching = (regexes, str) => {
142
159
regexes = regexes.splice(1);
143
160
} while (regexes.length > 0);
144
161
if (str.length === 0 && regexes.length === 0) {
145
- return "The regex should work." ;
162
+ return null ;
146
163
}
147
164
else {
148
165
const paddingLeft = Math.max(matchesUntil - 10, 0);
@@ -247,7 +264,7 @@ async function getInputs() {
247
264
const result = {};
248
265
core.debug('Get inputs...');
249
266
// Get pattern
250
- result.pattern = core.getInput('pattern', { required: true } );
267
+ result.pattern = core.getInput('pattern');
251
268
core.debug(`pattern: ${result.pattern}`);
252
269
// Get flags
253
270
result.flags = core.getInput('flags');
@@ -262,10 +279,10 @@ async function getInputs() {
262
279
const excludeDescriptionStr = core.getInput('excludeDescription');
263
280
core.debug(`excludeDescription: ${excludeDescriptionStr}`);
264
281
// 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 );
269
286
// Get checkAllCommitMessages
270
287
const checkAllCommitMessagesStr = core.getInput('checkAllCommitMessages');
271
288
core.debug(`checkAllCommitMessages: ${checkAllCommitMessagesStr}`);
0 commit comments