- recompile

This commit is contained in:
Mike Penz
2024-03-01 16:31:57 +00:00
committed by GitHub
parent 89d1f43dfa
commit 40d2beb495
3 changed files with 130 additions and 51 deletions
+4 -1
View File
@@ -489,10 +489,13 @@ Table of descriptions for the `configuration.json` options to configure the resu
| exclude_merge_branches | An array of branches to be ignored from processing as merge commits | | exclude_merge_branches | An array of branches to be ignored from processing as merge commits |
| tag_resolver | Section to provide configuration for the tag resolving logic. Used if no `fromTag` is provided | | tag_resolver | Section to provide configuration for the tag resolving logic. Used if no `fromTag` is provided |
| tag_resolver.method | Defines the method to use. Current options are: `semver`, `sort`. Default: `semver` | | tag_resolver.method | Defines the method to use. Current options are: `semver`, `sort`. Default: `semver` |
| tag_resolver.filter | Defines a regex which is used to filter out tags not matching. | | tag_resolver.filter | Defines a regex object which is used to filter out tags not matching. |
| tag_resolver.transformer | Defines a regex transformer used to optionally transform the tag after the filter was applied. Allows to adjust the format to e.g. semver. | | tag_resolver.transformer | Defines a regex transformer used to optionally transform the tag after the filter was applied. Allows to adjust the format to e.g. semver. |
| base_branches | The target branches for the merged PR, ingnores PRs with different target branch. Values can be a `regex`. Default: allow all base branches | | base_branches | The target branches for the merged PR, ingnores PRs with different target branch. Values can be a `regex`. Default: allow all base branches |
| trim_values | Defines if all values inserted in templates are `trimmed`. Default: false | | trim_values | Defines if all values inserted in templates are `trimmed`. Default: false |
### Custom placeholders 🧪 ### Custom placeholders 🧪
Starting with v3.2.0 the action provides a feature of defining `CUSTOM_PLACEHOLDERS`. Starting with v3.2.0 the action provides a feature of defining `CUSTOM_PLACEHOLDERS`.
Generated Vendored
+125 -49
View File
@@ -922,27 +922,19 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.buildRegex = exports.validateTransformer = void 0; exports.transformStringToValue = exports.transformStringToOptionalValue = exports.transformStringToValues = exports.applyCaptureGroup = exports.buildRegex = exports.validateRegex = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
function validateTransformer(transformer) { function validateRegex(regex) {
if (transformer === undefined) { if (regex === undefined) {
return null; return null;
} }
try { try {
let target = undefined; const target = regex.target;
if (transformer.hasOwnProperty('target')) { const method = regex.method;
target = transformer.target; const onEmpty = regex.on_empty;
}
let onProperty = undefined; let onProperty = undefined;
let method = undefined; if (regex.hasOwnProperty('on_property')) {
let onEmpty = undefined; onProperty = regex.on_property;
if (transformer.hasOwnProperty('method')) {
method = transformer.method;
onEmpty = transformer.on_empty;
onProperty = transformer.on_property;
}
else if (transformer.hasOwnProperty('on_property')) {
onProperty = transformer.on_property;
} }
// legacy handling, transform single value input to array // legacy handling, transform single value input to array
if (!Array.isArray(onProperty)) { if (!Array.isArray(onProperty)) {
@@ -950,14 +942,14 @@ function validateTransformer(transformer) {
onProperty = [onProperty]; onProperty = [onProperty];
} }
} }
return buildRegex(transformer, target, onProperty, method, onEmpty); return buildRegex(regex, target, onProperty, method, onEmpty);
} }
catch (e) { catch (e) {
core.warning(`⚠️ Failed to validate transformer: ${transformer.pattern}`); core.warning(`⚠️ Failed to validate transformer: ${regex.pattern}`);
return null; return null;
} }
} }
exports.validateTransformer = validateTransformer; exports.validateRegex = validateRegex;
/** /**
* Constructs the RegExp, providing the configured Regex and additional values * Constructs the RegExp, providing the configured Regex and additional values
*/ */
@@ -978,6 +970,100 @@ function buildRegex(regex, target, onProperty, method, onEmpty) {
} }
} }
exports.buildRegex = buildRegex; exports.buildRegex = buildRegex;
// eslint-disable-next-line no-undef
function applyCaptureGroup(value, target) {
const groups = value['groups'];
if (groups) {
const matched = groups[target];
if (matched) {
// if we had a perfect group match return that.
return matched;
}
}
if (target.startsWith('$') && !target.startsWith('$$')) {
// if we start with $ offer support for matching index based capture groups
const index = Number(target.substring(1));
if (!isNaN(index) && index < value.length) {
return value[index];
}
}
return null;
}
exports.applyCaptureGroup = applyCaptureGroup;
function transformStringToValues(value, extractor) {
if (extractor.pattern == null) {
return null;
}
if (extractor.method === 'exec' || extractor.method === 'execAll') {
// eslint-disable-next-line no-undef
let matches;
const result = new Set();
// match regex to all occurrences in the string if we run `execAll`
// otherwise just do the first match with exec
do {
matches = extractor.pattern.exec(value);
if (matches) {
if (extractor.target) {
const matchedGroup = applyCaptureGroup(matches, extractor.target);
if (matchedGroup) {
result.add(matchedGroup);
}
}
else {
for (const match of matches) {
result.add(match);
}
}
}
} while (matches && extractor.method === 'execAll');
if (result.size > 0) {
return [...result];
}
}
else if (extractor.method === 'match') {
const matches = value.match(extractor.pattern);
if (matches !== null && matches.length > 0) {
if (extractor.target) {
const matchedGroup = applyCaptureGroup(matches, extractor.target);
if (matchedGroup) {
return [matchedGroup];
}
}
return matches.map(match => match || '');
}
}
else if (extractor.method === 'replaceAll') {
const match = value.replaceAll(extractor.pattern, extractor.target);
if (match !== '') {
return [match];
}
}
else {
const match = value.replace(extractor.pattern, extractor.target);
if (match !== '') {
return [match];
}
}
if (extractor.onEmpty !== undefined) {
return [extractor.onEmpty];
}
return null;
}
exports.transformStringToValues = transformStringToValues;
function transformStringToOptionalValue(value, extractor) {
const result = transformStringToValues(value, extractor);
if (result != null && result.length > 0) {
return result[0];
}
else {
return null;
}
}
exports.transformStringToOptionalValue = transformStringToOptionalValue;
function transformStringToValue(value, extractor) {
return transformStringToOptionalValue(value, extractor) || '';
}
exports.transformStringToValue = transformStringToValue;
/***/ }), /***/ }),
@@ -1084,10 +1170,11 @@ class Tags {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
let tags = []; let tags = [];
if (!toTag || !fromTag) { if (!toTag || !fromTag) {
const filterRegex = (0, regexUtils_1.validateRegex)(tagResolver.filter);
// filter out tags not matching the specified filter // filter out tags not matching the specified filter
const filteredTags = filterTags( const filteredTags = filterTags(
// retrieve the tags from the API // retrieve the tags from the API
yield this.getTags(owner, repo, maxTagsToFetch), tagResolver); yield this.getTags(owner, repo, maxTagsToFetch), filterRegex);
// check if a transformer, legacy handling, transform single value input to array // check if a transformer, legacy handling, transform single value input to array
let tagTransfomers = undefined; let tagTransfomers = undefined;
if (tagResolver.transformer !== undefined) { if (tagResolver.transformer !== undefined) {
@@ -1102,7 +1189,7 @@ class Tags {
let transformedTags = filteredTags; let transformedTags = filteredTags;
if (tagTransfomers !== undefined && tagTransfomers.length > 0) { if (tagTransfomers !== undefined && tagTransfomers.length > 0) {
for (const transformer of tagTransfomers) { for (const transformer of tagTransfomers) {
const tagTransformer = (0, regexUtils_1.validateTransformer)(transformer); const tagTransformer = (0, regexUtils_1.validateRegex)(transformer);
if (tagTransformer != null) { if (tagTransformer != null) {
core.debug(`️ Using configured tagTransformer (${transformer.pattern})`); core.debug(`️ Using configured tagTransformer (${transformer.pattern})`);
transformedTags = transformTags(transformedTags, tagTransformer); transformedTags = transformTags(transformedTags, tagTransformer);
@@ -1186,12 +1273,9 @@ exports.Tags = Tags;
* Uses the provided filter (if available) to filter out any tags not currently relevant. * Uses the provided filter (if available) to filter out any tags not currently relevant.
* https://github.com/mikepenz/release-changelog-builder-action/issues/566 * https://github.com/mikepenz/release-changelog-builder-action/issues/566
*/ */
function filterTags(tags, tagResolver) { function filterTags(tags, filterRegex) {
var _a; if (filterRegex !== null) {
const filter = tagResolver.filter; const filteredTags = tags.filter(tag => (0, regexUtils_1.transformStringToOptionalValue)(tag.name, filterRegex) !== null);
if (filter !== undefined) {
const regex = new RegExp(filter.pattern.replace('\\\\', '\\'), (_a = filter.flags) !== null && _a !== void 0 ? _a : 'gu');
const filteredTags = tags.filter(tag => tag.name.match(regex) !== null);
core.debug(`️ Filtered tags count: ${filteredTags.length}, original count: ${tags.length}`); core.debug(`️ Filtered tags count: ${filteredTags.length}, original count: ${tags.length}`);
return filteredTags; return filteredTags;
} }
@@ -1206,7 +1290,7 @@ exports.filterTags = filterTags;
function transformTags(tags, transformer) { function transformTags(tags, transformer) {
return tags.map(function (tag) { return tags.map(function (tag) {
if (transformer.pattern) { if (transformer.pattern) {
const transformedName = tag.name.replace(transformer.pattern, transformer.target); const transformedName = (0, regexUtils_1.transformStringToValue)(tag.name, transformer);
core.debug(`️ Transformed ${tag.name} to ${transformedName}`); core.debug(`️ Transformed ${tag.name} to ${transformedName}`);
return { return {
tmp: tag.name, // remember the original name tmp: tag.name, // remember the original name
@@ -1414,7 +1498,7 @@ const regexUtils_1 = __nccwpck_require__(5351);
* Checks if any of the rules match the given PR * Checks if any of the rules match the given PR
*/ */
function matchesRules(rules, pr, exhaustive) { function matchesRules(rules, pr, exhaustive) {
const transformers = rules.map(rule => (0, regexUtils_1.validateTransformer)(rule)).filter(t => t !== null); const transformers = rules.map(rule => (0, regexUtils_1.validateRegex)(rule)).filter(t => t !== null);
if (exhaustive) { if (exhaustive) {
return transformers.every(transformer => { return transformers.every(transformer => {
return matches(pr, transformer, 'rule'); return matches(pr, transformer, 'rule');
@@ -2453,7 +2537,7 @@ function buildChangelog(diffInfo, origPrs, options) {
core.info(`️ Sorted all pull requests ascending: ${JSON.stringify(sort)}`); core.info(`️ Sorted all pull requests ascending: ${JSON.stringify(sort)}`);
// establish parent child PR relations // establish parent child PR relations
if (config.reference !== undefined) { if (config.reference !== undefined) {
const reference = (0, regexUtils_1.validateTransformer)(config.reference); const reference = (0, regexUtils_1.validateRegex)(config.reference);
if (reference !== null) { if (reference !== null) {
core.info(`️ Identifying PR references using \`reference\``); core.info(`️ Identifying PR references using \`reference\``);
const mapped = new Map(); const mapped = new Map();
@@ -2491,7 +2575,7 @@ function buildChangelog(diffInfo, origPrs, options) {
} }
// drop duplicate pull requests // drop duplicate pull requests
if (config.duplicate_filter !== undefined) { if (config.duplicate_filter !== undefined) {
const extractor = (0, regexUtils_1.validateTransformer)(config.duplicate_filter); const extractor = (0, regexUtils_1.validateRegex)(config.duplicate_filter);
if (extractor !== null) { if (extractor !== null) {
core.info(`️ Remove duplicated pull requests using \`duplicate_filter\``); core.info(`️ Remove duplicated pull requests using \`duplicate_filter\``);
const deduplicatedMap = new Map(); const deduplicatedMap = new Map();
@@ -2804,17 +2888,18 @@ function handlePlaceholder(template, key, value, placeholders /* placeholders to
const phs = placeholders.get(key); const phs = placeholders.get(key);
if (phs) { if (phs) {
for (const placeholder of phs) { for (const placeholder of phs) {
const transformer = (0, regexUtils_1.validateTransformer)(placeholder.transformer); const transformer = (0, regexUtils_1.validateRegex)(placeholder.transformer);
if (transformer === null || transformer === void 0 ? void 0 : transformer.pattern) { if (transformer === null || transformer === void 0 ? void 0 : transformer.pattern) {
const extractedValue = value.replace(transformer.pattern, transformer.target); const extractedValue = (0, regexUtils_1.transformStringToOptionalValue)(value, transformer);
// note: `.replace` will return the full string again if there was no match // note: `.replace` will return the full string again if there was no match
if (extractedValue && (extractedValue !== value || (extractedValue === value && value.match(transformer.pattern)))) { // note: This is mostly backwards compatiblity
if (extractedValue && ((transformer.method && transformer.method !== 'replace') || extractedValue !== value)) {
if (placeholderPrMap) { if (placeholderPrMap) {
(0, utils_1.createOrSet)(placeholderPrMap, placeholder.name, extractedValue); (0, utils_1.createOrSet)(placeholderPrMap, placeholder.name, extractedValue);
} }
transformed = transformed.replaceAll(`#{{${placeholder.name}}}`, configuration.trim_values ? extractedValue.trim() : extractedValue); transformed = transformed.replaceAll(`#{{${placeholder.name}}}`, configuration.trim_values ? extractedValue.trim() : extractedValue);
if (core.isDebug()) { if (core.isDebug()) {
core.debug(` Custom Placeholder successfully matched data - ${extractValues} (${placeholder.name})`); core.debug(` Custom Placeholder successfully matched data - ${extractedValue} (${placeholder.name})`);
} }
} }
else if (core.isDebug() && extractedValue === value) { else if (core.isDebug() && extractedValue === value) {
@@ -2899,7 +2984,7 @@ function validateTransformers(specifiedTransformers) {
const transformers = specifiedTransformers; const transformers = specifiedTransformers;
return transformers return transformers
.map(transformer => { .map(transformer => {
return (0, regexUtils_1.validateTransformer)(transformer); return (0, regexUtils_1.validateRegex)(transformer);
}) })
.filter(transformer => (transformer === null || transformer === void 0 ? void 0 : transformer.pattern) != null) .filter(transformer => (transformer === null || transformer === void 0 ? void 0 : transformer.pattern) != null)
.map(transformer => { .map(transformer => {
@@ -2932,23 +3017,14 @@ function extractValuesFromString(value, extractor) {
if (extractor.pattern == null) { if (extractor.pattern == null) {
return null; return null;
} }
if (extractor.method === 'match') { const transformed = (0, regexUtils_1.transformStringToValues)(value, extractor);
const lables = value.match(extractor.pattern); if (transformed) {
if (lables !== null && lables.length > 0) { return transformed.map(val => (val === null || val === void 0 ? void 0 : val.toLocaleLowerCase('en')) || '');
return lables.map(label => (label === null || label === void 0 ? void 0 : label.toLocaleLowerCase('en')) || '');
}
} }
else { else {
const label = value.replace(extractor.pattern, extractor.target);
if (label !== '') {
return [label.toLocaleLowerCase('en')];
}
}
if (extractor.onEmpty !== undefined) {
return [extractor.onEmpty.toLocaleLowerCase('en')];
}
return null; return null;
} }
}
/***/ }), /***/ }),
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long