- introduce the ability to reference parent / child PR relationships
- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/1074 - optimize placeholder removal - only keep placeholders in array if we have values
This commit is contained in:
@@ -266,7 +266,7 @@ pullRequestsWithLabels.push(
|
|||||||
repoName: 'test-repo',
|
repoName: 'test-repo',
|
||||||
labels: ['issue', 'fix'],
|
labels: ['issue', 'fix'],
|
||||||
milestone: '',
|
milestone: '',
|
||||||
body: 'no magic body for this matter',
|
body: 'no magic body for this matter - #1',
|
||||||
assignees: [],
|
assignees: [],
|
||||||
requestedReviewers: [],
|
requestedReviewers: [],
|
||||||
approvedReviewers: [],
|
approvedReviewers: [],
|
||||||
@@ -399,6 +399,26 @@ it('Deduplicate duplicated PRs DESC', async () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Reference PRs', async () => {
|
||||||
|
const customConfig = Object.assign({}, DefaultConfiguration)
|
||||||
|
customConfig.categories = [
|
||||||
|
{
|
||||||
|
title: '',
|
||||||
|
labels: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
customConfig.pr_template = "${{NUMBER}} -- ${{REFERENCED[*].number}}"
|
||||||
|
customConfig.reference = {
|
||||||
|
pattern: '.*\ \#(.).*',
|
||||||
|
on_property: 'body',
|
||||||
|
method: 'replace',
|
||||||
|
target: '$1'
|
||||||
|
}
|
||||||
|
expect(buildChangelogTest(customConfig, pullRequestsWithLabels)).toStrictEqual(
|
||||||
|
`1 -- 2\n4 -- \n3 -- \n\n`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it('Use empty_content for empty category', async () => {
|
it('Use empty_content for empty category', async () => {
|
||||||
const customConfig = Object.assign({}, DefaultConfiguration)
|
const customConfig = Object.assign({}, DefaultConfiguration)
|
||||||
customConfig.categories = [
|
customConfig.categories = [
|
||||||
|
|||||||
+85
-3
@@ -436,8 +436,9 @@ const pullRequests_1 = __nccwpck_require__(1948);
|
|||||||
const regexUtils_1 = __nccwpck_require__(3078);
|
const regexUtils_1 = __nccwpck_require__(3078);
|
||||||
const regexUtils_2 = __nccwpck_require__(2364);
|
const regexUtils_2 = __nccwpck_require__(2364);
|
||||||
const EMPTY_MAP = new Map();
|
const EMPTY_MAP = new Map();
|
||||||
function buildChangelog(diffInfo, prs, options) {
|
function buildChangelog(diffInfo, origPrs, options) {
|
||||||
core.startGroup('📦 Build changelog');
|
core.startGroup('📦 Build changelog');
|
||||||
|
let prs = origPrs;
|
||||||
if (prs.length === 0) {
|
if (prs.length === 0) {
|
||||||
core.warning(`⚠️ No pull requests found`);
|
core.warning(`⚠️ No pull requests found`);
|
||||||
const result = replaceEmptyTemplate(options.configuration.empty_template, options);
|
const result = replaceEmptyTemplate(options.configuration.empty_template, options);
|
||||||
@@ -449,10 +450,48 @@ function buildChangelog(diffInfo, prs, options) {
|
|||||||
const sort = config.sort;
|
const sort = config.sort;
|
||||||
prs = (0, pullRequests_1.sortPullRequests)(prs, sort);
|
prs = (0, pullRequests_1.sortPullRequests)(prs, sort);
|
||||||
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
|
||||||
|
if (config.reference !== undefined) {
|
||||||
|
const reference = (0, regexUtils_1.validateTransformer)(config.reference);
|
||||||
|
if (reference !== null) {
|
||||||
|
core.info(`ℹ️ Identifying PR references using \`reference\``);
|
||||||
|
const mapped = new Map();
|
||||||
|
for (const pr of prs) {
|
||||||
|
mapped.set(pr.number, pr);
|
||||||
|
}
|
||||||
|
const remappedPrs = [];
|
||||||
|
for (const pr of prs) {
|
||||||
|
const extracted = extractValues(pr, reference, 'reference');
|
||||||
|
if (extracted !== null && extracted.length > 0) {
|
||||||
|
const foundNumber = parseInt(extracted[0]);
|
||||||
|
const valid = !isNaN(foundNumber);
|
||||||
|
const parent = mapped.get(foundNumber);
|
||||||
|
if (valid && parent !== undefined) {
|
||||||
|
if (parent.childPrs === undefined) {
|
||||||
|
parent.childPrs = [];
|
||||||
|
}
|
||||||
|
parent.childPrs.push(pr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!valid)
|
||||||
|
core.warning(`⚠️ Extracted reference 'isNaN': ${extracted}`);
|
||||||
|
remappedPrs.push(pr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
remappedPrs.push(pr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prs = remappedPrs;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.warning(`⚠️ Configured \`reference\` invalid.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
// 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.validateTransformer)(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();
|
||||||
const unmatched = [];
|
const unmatched = [];
|
||||||
@@ -672,6 +711,7 @@ function buildChangelog(diffInfo, prs, options) {
|
|||||||
transformedChangelog = replacePlaceholders(transformedChangelog, EMPTY_MAP, placeholderMap, placeholders, placeholderPrMap, config);
|
transformedChangelog = replacePlaceholders(transformedChangelog, EMPTY_MAP, placeholderMap, placeholders, placeholderPrMap, config);
|
||||||
transformedChangelog = replacePrPlaceholders(transformedChangelog, placeholderPrMap, config);
|
transformedChangelog = replacePrPlaceholders(transformedChangelog, placeholderPrMap, config);
|
||||||
transformedChangelog = cleanupPrPlaceholders(transformedChangelog, placeholders);
|
transformedChangelog = cleanupPrPlaceholders(transformedChangelog, placeholders);
|
||||||
|
transformedChangelog = cleanupPlaceholders(transformedChangelog);
|
||||||
core.info(`ℹ️ Filled template`);
|
core.info(`ℹ️ Filled template`);
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
return transformedChangelog;
|
return transformedChangelog;
|
||||||
@@ -709,6 +749,7 @@ function fillPrTemplate(pr, template, placeholders /* placeholders to apply */,
|
|||||||
var _a, _b, _c, _d, _e, _f;
|
var _a, _b, _c, _d, _e, _f;
|
||||||
const arrayPlaceholderMap = new Map();
|
const arrayPlaceholderMap = new Map();
|
||||||
fillReviewPlaceholders(arrayPlaceholderMap, 'REVIEWS', pr.reviews || []);
|
fillReviewPlaceholders(arrayPlaceholderMap, 'REVIEWS', pr.reviews || []);
|
||||||
|
fillChildPrPlaceholders(arrayPlaceholderMap, 'REFERENCED', pr.childPrs || []);
|
||||||
const placeholderMap = new Map();
|
const placeholderMap = new Map();
|
||||||
placeholderMap.set('NUMBER', pr.number.toString());
|
placeholderMap.set('NUMBER', pr.number.toString());
|
||||||
placeholderMap.set('TITLE', pr.title);
|
placeholderMap.set('TITLE', pr.title);
|
||||||
@@ -771,6 +812,8 @@ function handlePlaceholder(template, key, value, placeholders /* placeholders to
|
|||||||
return transformed;
|
return transformed;
|
||||||
}
|
}
|
||||||
function fillArrayPlaceholders(placeholderMap /* placeholderKey and original value */, key, values) {
|
function fillArrayPlaceholders(placeholderMap /* placeholderKey and original value */, key, values) {
|
||||||
|
if (values.length === 0)
|
||||||
|
return;
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
placeholderMap.set(`${key}[${i}]`, values[i]);
|
placeholderMap.set(`${key}[${i}]`, values[i]);
|
||||||
}
|
}
|
||||||
@@ -778,6 +821,8 @@ function fillArrayPlaceholders(placeholderMap /* placeholderKey and original val
|
|||||||
}
|
}
|
||||||
function fillReviewPlaceholders(placeholderMap /* placeholderKey and original value */, parentKey, values) {
|
function fillReviewPlaceholders(placeholderMap /* placeholderKey and original value */, parentKey, values) {
|
||||||
var _a;
|
var _a;
|
||||||
|
if (values.length === 0)
|
||||||
|
return;
|
||||||
// retrieve the keys from the CommentInfo object
|
// retrieve the keys from the CommentInfo object
|
||||||
for (const childKey of Object.keys(pullRequests_1.EMPTY_COMMENT_INFO)) {
|
for (const childKey of Object.keys(pullRequests_1.EMPTY_COMMENT_INFO)) {
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
@@ -786,6 +831,18 @@ function fillReviewPlaceholders(placeholderMap /* placeholderKey and original va
|
|||||||
placeholderMap.set(`${parentKey}[*].${childKey}`, values.map(value => { var _a; return ((_a = value[childKey]) === null || _a === void 0 ? void 0 : _a.toLocaleString('en')) || ''; }).join(', '));
|
placeholderMap.set(`${parentKey}[*].${childKey}`, values.map(value => { var _a; return ((_a = value[childKey]) === null || _a === void 0 ? void 0 : _a.toLocaleString('en')) || ''; }).join(', '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function fillChildPrPlaceholders(placeholderMap /* placeholderKey and original value */, parentKey, values) {
|
||||||
|
var _a;
|
||||||
|
if (values.length === 0)
|
||||||
|
return;
|
||||||
|
// retrieve the keys from the PullRequestInfo object
|
||||||
|
for (const childKey of Object.keys(pullRequests_1.EMPTY_PULL_REQUEST_INFO)) {
|
||||||
|
for (let i = 0; i < values.length; i++) {
|
||||||
|
placeholderMap.set(`${parentKey}[${i}].${childKey}`, ((_a = values[i][childKey]) === null || _a === void 0 ? void 0 : _a.toLocaleString('en')) || '');
|
||||||
|
}
|
||||||
|
placeholderMap.set(`${parentKey}[*].${childKey}`, values.map(value => { var _a; return ((_a = value[childKey]) === null || _a === void 0 ? void 0 : _a.toLocaleString('en')) || ''; }).join(', '));
|
||||||
|
}
|
||||||
|
}
|
||||||
function replacePrPlaceholders(template, placeholderPrMap /* map with all pr related custom placeholder values */, configuration) {
|
function replacePrPlaceholders(template, placeholderPrMap /* map with all pr related custom placeholder values */, configuration) {
|
||||||
let transformed = template;
|
let transformed = template;
|
||||||
for (const [key, values] of placeholderPrMap) {
|
for (const [key, values] of placeholderPrMap) {
|
||||||
@@ -805,6 +862,13 @@ function cleanupPrPlaceholders(template, placeholders) {
|
|||||||
}
|
}
|
||||||
return transformed;
|
return transformed;
|
||||||
}
|
}
|
||||||
|
function cleanupPlaceholders(template) {
|
||||||
|
let transformed = template;
|
||||||
|
for (const phs of ['REVIEWS', 'REFERENCED', 'ASSIGNEES', 'REVIEWERS', 'APPROVERS']) {
|
||||||
|
transformed = transformed.replaceAll(new RegExp(`\\$\\{\\{${phs}\\[.+?\\]\\..*?\\}\\}`, 'gu'), '');
|
||||||
|
}
|
||||||
|
return transformed;
|
||||||
|
}
|
||||||
function transform(filled, transformers) {
|
function transform(filled, transformers) {
|
||||||
if (transformers.length === 0) {
|
if (transformers.length === 0) {
|
||||||
return filled;
|
return filled;
|
||||||
@@ -17115,10 +17179,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.retrieveProperty = exports.compare = exports.sortPullRequests = exports.PullRequests = exports.EMPTY_COMMENT_INFO = void 0;
|
exports.retrieveProperty = exports.compare = exports.sortPullRequests = exports.PullRequests = exports.EMPTY_COMMENT_INFO = exports.EMPTY_PULL_REQUEST_INFO = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(2242));
|
const core = __importStar(__nccwpck_require__(2242));
|
||||||
const moment_1 = __importDefault(__nccwpck_require__(8985));
|
const moment_1 = __importDefault(__nccwpck_require__(8985));
|
||||||
const commits_1 = __nccwpck_require__(5789);
|
const commits_1 = __nccwpck_require__(5789);
|
||||||
|
exports.EMPTY_PULL_REQUEST_INFO = {
|
||||||
|
number: 0,
|
||||||
|
title: "",
|
||||||
|
htmlURL: "",
|
||||||
|
baseBranch: "",
|
||||||
|
mergedAt: undefined,
|
||||||
|
createdAt: (0, moment_1.default)(),
|
||||||
|
mergeCommitSha: "",
|
||||||
|
author: "",
|
||||||
|
repoName: "",
|
||||||
|
labels: [],
|
||||||
|
milestone: "",
|
||||||
|
body: "",
|
||||||
|
assignees: [],
|
||||||
|
requestedReviewers: [],
|
||||||
|
approvedReviewers: [],
|
||||||
|
status: 'open'
|
||||||
|
};
|
||||||
exports.EMPTY_COMMENT_INFO = {
|
exports.EMPTY_COMMENT_INFO = {
|
||||||
id: 0,
|
id: 0,
|
||||||
htmlURL: '',
|
htmlURL: '',
|
||||||
|
|||||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -36,6 +36,25 @@ export interface CommentInfo {
|
|||||||
state: string | undefined
|
state: string | undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const EMPTY_PULL_REQUEST_INFO: PullRequestInfo = {
|
||||||
|
number: 0,
|
||||||
|
title: "",
|
||||||
|
htmlURL: "",
|
||||||
|
baseBranch: "",
|
||||||
|
mergedAt: undefined,
|
||||||
|
createdAt: moment(),
|
||||||
|
mergeCommitSha: "",
|
||||||
|
author: "",
|
||||||
|
repoName: "",
|
||||||
|
labels: [],
|
||||||
|
milestone: "",
|
||||||
|
body: "",
|
||||||
|
assignees: [],
|
||||||
|
requestedReviewers: [],
|
||||||
|
approvedReviewers: [],
|
||||||
|
status: 'open'
|
||||||
|
}
|
||||||
|
|
||||||
export const EMPTY_COMMENT_INFO: CommentInfo = {
|
export const EMPTY_COMMENT_INFO: CommentInfo = {
|
||||||
id: 0,
|
id: 0,
|
||||||
htmlURL: '',
|
htmlURL: '',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export interface Configuration extends PullConfiguration {
|
|||||||
ignore_labels: string[]
|
ignore_labels: string[]
|
||||||
label_extractor: Extractor[]
|
label_extractor: Extractor[]
|
||||||
duplicate_filter?: Extractor // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`)
|
duplicate_filter?: Extractor // extract an identifier from a PR used to detect duplicates, will keep the last match (depends on `sort`)
|
||||||
|
reference?: Extractor // extracts a reference from a PR, used to establish parent child relations. This will remove the child from the main PR list.
|
||||||
transformers: Transformer[]
|
transformers: Transformer[]
|
||||||
tag_resolver: TagResolver
|
tag_resolver: TagResolver
|
||||||
base_branches: string[]
|
base_branches: string[]
|
||||||
|
|||||||
+84
-4
@@ -1,7 +1,14 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {Category, Configuration, Placeholder, Property} from './configuration'
|
import {Category, Configuration, Placeholder, Property} from './configuration'
|
||||||
import {createOrSet, haveCommonElementsArr, haveEveryElementsArr} from './utils'
|
import {createOrSet, haveCommonElementsArr, haveEveryElementsArr} from './utils'
|
||||||
import {CommentInfo, EMPTY_COMMENT_INFO, PullRequestInfo, retrieveProperty, sortPullRequests} from 'github-pr-collector/lib/pullRequests'
|
import {
|
||||||
|
CommentInfo,
|
||||||
|
EMPTY_COMMENT_INFO,
|
||||||
|
EMPTY_PULL_REQUEST_INFO,
|
||||||
|
PullRequestInfo,
|
||||||
|
retrieveProperty,
|
||||||
|
sortPullRequests
|
||||||
|
} from 'github-pr-collector/lib/pullRequests'
|
||||||
import {DiffInfo} from 'github-pr-collector/lib/commits'
|
import {DiffInfo} from 'github-pr-collector/lib/commits'
|
||||||
import {validateTransformer} from 'github-pr-collector/lib/regexUtils'
|
import {validateTransformer} from 'github-pr-collector/lib/regexUtils'
|
||||||
import {Transformer, RegexTransformer} from 'github-pr-collector/lib/types'
|
import {Transformer, RegexTransformer} from 'github-pr-collector/lib/types'
|
||||||
@@ -10,8 +17,14 @@ import {matchesRules} from './regexUtils'
|
|||||||
|
|
||||||
const EMPTY_MAP = new Map<string, string>()
|
const EMPTY_MAP = new Map<string, string>()
|
||||||
|
|
||||||
export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], options: ReleaseNotesOptions): string {
|
export interface PullRequestData extends PullRequestInfo {
|
||||||
|
childPrs?: PullRequestInfo[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], options: ReleaseNotesOptions): string {
|
||||||
core.startGroup('📦 Build changelog')
|
core.startGroup('📦 Build changelog')
|
||||||
|
|
||||||
|
let prs: PullRequestData[] = origPrs
|
||||||
if (prs.length === 0) {
|
if (prs.length === 0) {
|
||||||
core.warning(`⚠️ No pull requests found`)
|
core.warning(`⚠️ No pull requests found`)
|
||||||
const result = replaceEmptyTemplate(options.configuration.empty_template, options)
|
const result = replaceEmptyTemplate(options.configuration.empty_template, options)
|
||||||
@@ -25,10 +38,47 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
|
|||||||
prs = sortPullRequests(prs, sort)
|
prs = sortPullRequests(prs, sort)
|
||||||
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
|
||||||
|
if (config.reference !== undefined) {
|
||||||
|
const reference = validateTransformer(config.reference)
|
||||||
|
if (reference !== null) {
|
||||||
|
core.info(`ℹ️ Identifying PR references using \`reference\``)
|
||||||
|
|
||||||
|
const mapped = new Map<number, PullRequestData>()
|
||||||
|
for (const pr of prs) {
|
||||||
|
mapped.set(pr.number, pr)
|
||||||
|
}
|
||||||
|
|
||||||
|
const remappedPrs: PullRequestData[] = []
|
||||||
|
for (const pr of prs) {
|
||||||
|
const extracted = extractValues(pr, reference, 'reference')
|
||||||
|
if (extracted !== null && extracted.length > 0) {
|
||||||
|
const foundNumber = parseInt(extracted[0])
|
||||||
|
const valid = !isNaN(foundNumber)
|
||||||
|
const parent = mapped.get(foundNumber)
|
||||||
|
if (valid && parent !== undefined) {
|
||||||
|
if (parent.childPrs === undefined) {
|
||||||
|
parent.childPrs = []
|
||||||
|
}
|
||||||
|
parent.childPrs.push(pr)
|
||||||
|
} else {
|
||||||
|
if (!valid) core.warning(`⚠️ Extracted reference 'isNaN': ${extracted}`)
|
||||||
|
remappedPrs.push(pr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
remappedPrs.push(pr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prs = remappedPrs
|
||||||
|
} else {
|
||||||
|
core.warning(`⚠️ Configured \`reference\` invalid.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// drop duplicate pull requests
|
// drop duplicate pull requests
|
||||||
if (config.duplicate_filter !== undefined) {
|
if (config.duplicate_filter !== undefined) {
|
||||||
const extractor = validateTransformer(config.duplicate_filter)
|
const extractor = validateTransformer(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<string, PullRequestInfo>()
|
const deduplicatedMap = new Map<string, PullRequestInfo>()
|
||||||
@@ -283,6 +333,7 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
|
|||||||
transformedChangelog = replacePlaceholders(transformedChangelog, EMPTY_MAP, placeholderMap, placeholders, placeholderPrMap, config)
|
transformedChangelog = replacePlaceholders(transformedChangelog, EMPTY_MAP, placeholderMap, placeholders, placeholderPrMap, config)
|
||||||
transformedChangelog = replacePrPlaceholders(transformedChangelog, placeholderPrMap, config)
|
transformedChangelog = replacePrPlaceholders(transformedChangelog, placeholderPrMap, config)
|
||||||
transformedChangelog = cleanupPrPlaceholders(transformedChangelog, placeholders)
|
transformedChangelog = cleanupPrPlaceholders(transformedChangelog, placeholders)
|
||||||
|
transformedChangelog = cleanupPlaceholders(transformedChangelog)
|
||||||
core.info(`ℹ️ Filled template`)
|
core.info(`ℹ️ Filled template`)
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
return transformedChangelog
|
return transformedChangelog
|
||||||
@@ -322,7 +373,7 @@ function fillAdditionalPlaceholders(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fillPrTemplate(
|
function fillPrTemplate(
|
||||||
pr: PullRequestInfo,
|
pr: PullRequestData,
|
||||||
template: string,
|
template: string,
|
||||||
placeholders: Map<string, Placeholder[]> /* placeholders to apply */,
|
placeholders: Map<string, Placeholder[]> /* placeholders to apply */,
|
||||||
placeholderPrMap: Map<string, string[]> /* map to keep replaced placeholder values with their key */,
|
placeholderPrMap: Map<string, string[]> /* map to keep replaced placeholder values with their key */,
|
||||||
@@ -330,6 +381,7 @@ function fillPrTemplate(
|
|||||||
): string {
|
): string {
|
||||||
const arrayPlaceholderMap = new Map<string, string>()
|
const arrayPlaceholderMap = new Map<string, string>()
|
||||||
fillReviewPlaceholders(arrayPlaceholderMap, 'REVIEWS', pr.reviews || [])
|
fillReviewPlaceholders(arrayPlaceholderMap, 'REVIEWS', pr.reviews || [])
|
||||||
|
fillChildPrPlaceholders(arrayPlaceholderMap, 'REFERENCED', pr.childPrs || [])
|
||||||
const placeholderMap = new Map<string, string>()
|
const placeholderMap = new Map<string, string>()
|
||||||
placeholderMap.set('NUMBER', pr.number.toString())
|
placeholderMap.set('NUMBER', pr.number.toString())
|
||||||
placeholderMap.set('TITLE', pr.title)
|
placeholderMap.set('TITLE', pr.title)
|
||||||
@@ -419,6 +471,7 @@ function fillArrayPlaceholders(
|
|||||||
key: string,
|
key: string,
|
||||||
values: string[]
|
values: string[]
|
||||||
): void {
|
): void {
|
||||||
|
if (values.length === 0) return
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
placeholderMap.set(`${key}[${i}]`, values[i])
|
placeholderMap.set(`${key}[${i}]`, values[i])
|
||||||
}
|
}
|
||||||
@@ -430,6 +483,7 @@ function fillReviewPlaceholders(
|
|||||||
parentKey: string,
|
parentKey: string,
|
||||||
values: CommentInfo[]
|
values: CommentInfo[]
|
||||||
): void {
|
): void {
|
||||||
|
if (values.length === 0) return
|
||||||
// retrieve the keys from the CommentInfo object
|
// retrieve the keys from the CommentInfo object
|
||||||
for (const childKey of Object.keys(EMPTY_COMMENT_INFO)) {
|
for (const childKey of Object.keys(EMPTY_COMMENT_INFO)) {
|
||||||
for (let i = 0; i < values.length; i++) {
|
for (let i = 0; i < values.length; i++) {
|
||||||
@@ -442,6 +496,24 @@ function fillReviewPlaceholders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function fillChildPrPlaceholders(
|
||||||
|
placeholderMap: Map<string, string> /* placeholderKey and original value */,
|
||||||
|
parentKey: string,
|
||||||
|
values: PullRequestInfo[]
|
||||||
|
): void {
|
||||||
|
if (values.length === 0) return
|
||||||
|
// retrieve the keys from the PullRequestInfo object
|
||||||
|
for (const childKey of Object.keys(EMPTY_PULL_REQUEST_INFO)) {
|
||||||
|
for (let i = 0; i < values.length; i++) {
|
||||||
|
placeholderMap.set(`${parentKey}[${i}].${childKey}`, values[i][childKey as keyof PullRequestInfo]?.toLocaleString('en') || '')
|
||||||
|
}
|
||||||
|
placeholderMap.set(
|
||||||
|
`${parentKey}[*].${childKey}`,
|
||||||
|
values.map(value => value[childKey as keyof PullRequestInfo]?.toLocaleString('en') || '').join(', ')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function replacePrPlaceholders(
|
function replacePrPlaceholders(
|
||||||
template: string,
|
template: string,
|
||||||
placeholderPrMap: Map<string, string[]> /* map with all pr related custom placeholder values */,
|
placeholderPrMap: Map<string, string[]> /* map with all pr related custom placeholder values */,
|
||||||
@@ -467,6 +539,14 @@ function cleanupPrPlaceholders(template: string, placeholders: Map<string, Place
|
|||||||
return transformed
|
return transformed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanupPlaceholders(template: string): string {
|
||||||
|
let transformed = template
|
||||||
|
for (const phs of ['REVIEWS', 'REFERENCED', 'ASSIGNEES', 'REVIEWERS', 'APPROVERS']) {
|
||||||
|
transformed = transformed.replaceAll(new RegExp(`\\$\\{\\{${phs}\\[.+?\\]\\..*?\\}\\}`, 'gu'), '')
|
||||||
|
}
|
||||||
|
return transformed
|
||||||
|
}
|
||||||
|
|
||||||
function transform(filled: string, transformers: RegexTransformer[]): string {
|
function transform(filled: string, transformers: RegexTransformer[]): string {
|
||||||
if (transformers.length === 0) {
|
if (transformers.length === 0) {
|
||||||
return filled
|
return filled
|
||||||
|
|||||||
Reference in New Issue
Block a user