- clear categories in tests as we run in the same process multiple times

This commit is contained in:
Mike Penz
2024-03-01 19:23:22 +00:00
committed by GitHub
parent eaf255d3da
commit 39d8ac4b4f
12 changed files with 146 additions and 69 deletions
+2
View File
@@ -1,6 +1,8 @@
import { clear } from '../src/transform'
import {mergeConfiguration, parseConfiguration, resolveConfiguration} from '../src/utils' import {mergeConfiguration, parseConfiguration, resolveConfiguration} from '../src/utils'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
it('Configurations are merged correctly', async () => { it('Configurations are merged correctly', async () => {
const configurationJson = parseConfiguration(`{ const configurationJson = parseConfiguration(`{
@@ -1,8 +1,10 @@
import {mergeConfiguration, resolveConfiguration} from '../../src/utils' import {mergeConfiguration, resolveConfiguration} from '../../src/utils'
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder' import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder'
import {GiteaRepository} from '../../src/repositories/GiteaRepository' import {GiteaRepository} from '../../src/repositories/GiteaRepository'
import { clear } from '../../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
/** /**
* Before starting testing, you should manually clone the repository * Before starting testing, you should manually clone the repository
@@ -2,8 +2,10 @@ import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../..
import {buildChangelog} from '../../src/transform' import {buildChangelog} from '../../src/transform'
import {pullData} from '../../src/pr-collector/prCollector' import {pullData} from '../../src/pr-collector/prCollector'
import {GiteaRepository} from '../../src/repositories/GiteaRepository' import {GiteaRepository} from '../../src/repositories/GiteaRepository'
import { clear } from '../../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
// load octokit instance // load octokit instance
const enablePullData = false const enablePullData = false
+2
View File
@@ -2,8 +2,10 @@ import * as path from 'path'
import * as process from 'process' import * as process from 'process'
import * as cp from 'child_process' import * as cp from 'child_process'
import * as fs from 'fs' import * as fs from 'fs'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
test('missing values should result in failure', () => { test('missing values should result in failure', () => {
expect.assertions(1) expect.assertions(1)
+2
View File
@@ -1,7 +1,9 @@
import { transformStringToValue, validateRegex } from '../src/pr-collector/regexUtils' import { transformStringToValue, validateRegex } from '../src/pr-collector/regexUtils'
import { Regex } from '../src/pr-collector/types' import { Regex } from '../src/pr-collector/types'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
it('Replace into target', async () => { it('Replace into target', async () => {
const regex: Regex = { const regex: Regex = {
+2
View File
@@ -1,8 +1,10 @@
import {mergeConfiguration, resolveConfiguration} from '../src/utils' import {mergeConfiguration, resolveConfiguration} from '../src/utils'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder' import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder'
import {GithubRepository} from '../src/repositories/GithubRepository' import {GithubRepository} from '../src/repositories/GithubRepository'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
const token = process.env.GITHUB_TOKEN || '' const token = process.env.GITHUB_TOKEN || ''
const githubRepository = new GithubRepository(token, undefined, '.') const githubRepository = new GithubRepository(token, undefined, '.')
@@ -2,8 +2,10 @@ import {checkExportedData, mergeConfiguration, resolveConfiguration} from '../sr
import {buildChangelog} from '../src/transform' import {buildChangelog} from '../src/transform'
import {pullData} from '../src/pr-collector/prCollector' import {pullData} from '../src/pr-collector/prCollector'
import {GithubRepository} from '../src/repositories/GithubRepository' import {GithubRepository} from '../src/repositories/GithubRepository'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
// load octokit instance // load octokit instance
const enablePullData = false // if false -> use cache for data const enablePullData = false // if false -> use cache for data
+2
View File
@@ -1,8 +1,10 @@
import { TagResolver } from '../src/configuration' import { TagResolver } from '../src/configuration'
import { validateRegex } from '../src/pr-collector/regexUtils' import { validateRegex } from '../src/pr-collector/regexUtils'
import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags' import {filterTags, prepareAndSortTags, TagInfo, transformTags} from '../src/pr-collector/tags'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
it('Should order tags correctly using semver', async () => { it('Should order tags correctly using semver', async () => {
const tags: TagInfo[] = [ const tags: TagInfo[] = [
+2
View File
@@ -4,8 +4,10 @@ import {Configuration, DefaultConfiguration} from '../src/configuration'
import {PullRequestInfo} from '../src/pr-collector/pullRequests' import {PullRequestInfo} from '../src/pr-collector/pullRequests'
import {DefaultDiffInfo} from '../src/pr-collector/commits' import {DefaultDiffInfo} from '../src/pr-collector/commits'
import {GithubRepository} from '../src/repositories/GithubRepository' import {GithubRepository} from '../src/repositories/GithubRepository'
import { clear } from '../src/transform'
jest.setTimeout(180000) jest.setTimeout(180000)
clear()
const configuration = Object.assign({}, DefaultConfiguration) const configuration = Object.assign({}, DefaultConfiguration)
configuration.categories = [ configuration.categories = [
Generated Vendored
+121 -67
View File
@@ -2500,13 +2500,18 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.replaceEmptyTemplate = exports.buildChangelog = void 0; exports.replaceEmptyTemplate = exports.buildChangelog = exports.clear = void 0;
const core = __importStar(__nccwpck_require__(2186)); const core = __importStar(__nccwpck_require__(2186));
const utils_1 = __nccwpck_require__(918); const utils_1 = __nccwpck_require__(918);
const pullRequests_1 = __nccwpck_require__(4012); const pullRequests_1 = __nccwpck_require__(4012);
const regexUtils_1 = __nccwpck_require__(5351); const regexUtils_1 = __nccwpck_require__(5351);
const regexUtils_2 = __nccwpck_require__(2364); const regexUtils_2 = __nccwpck_require__(2364);
const EMPTY_MAP = new Map(); const EMPTY_MAP = new Map();
let CLEAR = false;
function clear() {
CLEAR = true;
}
exports.clear = clear;
function buildChangelog(diffInfo, origPrs, options) { function buildChangelog(diffInfo, origPrs, options) {
core.startGroup('📦 Build changelog'); core.startGroup('📦 Build changelog');
let prs = origPrs; let prs = origPrs;
@@ -2616,18 +2621,21 @@ function buildChangelog(diffInfo, origPrs, options) {
core.info(`️ Used ${validatedTransformers.length} transformers to adjust message`); core.info(`️ Used ${validatedTransformers.length} transformers to adjust message`);
core.info(`✒️ Wrote messages for ${prs.length} pull requests`); core.info(`✒️ Wrote messages for ${prs.length} pull requests`);
// bring PRs into the order of categories // bring PRs into the order of categories
const categorized = new Map();
const categories = config.categories; const categories = config.categories;
const ignoredLabels = config.ignore_labels; const ignoredLabels = config.ignore_labels;
for (const category of categories) { const flatCategories = flatten(config.categories);
categorized.set(category, []);
}
const categorizedPrs = []; const categorizedPrs = [];
const ignoredPrs = []; const ignoredPrs = [];
const openPrs = []; const openPrs = [];
const uncategorizedPrs = []; const uncategorizedPrs = [];
// set-up the category object
for (const category of flatCategories) {
if (CLEAR || !category.entries) {
category.entries = [];
}
}
// bring elements in order // bring elements in order
for (const [pr, body] of transformedMap) { prLoop: for (const [pr, body] of transformedMap) {
if ((0, utils_1.haveCommonElementsArr)(ignoredLabels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) { if ((0, utils_1.haveCommonElementsArr)(ignoredLabels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) {
ignoredPrs.push(body); ignoredPrs.push(body);
continue; continue;
@@ -2636,55 +2644,17 @@ function buildChangelog(diffInfo, origPrs, options) {
openPrs.push(body); openPrs.push(body);
} }
let matchedOnce = false; // in case we matched once at least, the PR can't be uncategorized let matchedOnce = false; // in case we matched once at least, the PR can't be uncategorized
for (const [category, pullRequests] of categorized) { for (const category of categories) {
let matched = false; // check if we matched within the given category const [matched, consumed] = recursiveCategorizePr(category, pr, body);
// check if any exclude label matches if (consumed) {
if (category.exclude_labels !== undefined) { continue prLoop;
if ((0, utils_1.haveCommonElementsArr)(category.exclude_labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) {
if (core.isDebug()) {
const excludeLabels = JSON.stringify(category.exclude_labels);
core.debug(` PR ${pr.number} with labels: ${pr.labels} excluded from category via exclude label: ${excludeLabels}`);
}
continue; // one of the exclude labels matched, skip the PR for this category
}
}
// in case we have exhaustive matching enabled, and have labels and/or rules
// validate for an exhaustive match (e.g. every provided rule applies)
if (category.exhaustive === true && (category.labels !== undefined || category.rules !== undefined)) {
if (category.labels !== undefined) {
matched = (0, utils_1.haveEveryElementsArr)(category.labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels);
}
let exhaustive_rules = true;
if (category.exhaustive_rules !== undefined) {
exhaustive_rules = category.exhaustive_rules;
}
if ((matched || category.labels === undefined) && category.rules !== undefined) {
matched = (0, regexUtils_2.matchesRules)(category.rules, pr, exhaustive_rules);
}
}
else {
// if not exhaustive, do individual matches
if (category.labels !== undefined) {
// check if either any of the labels applies
matched = (0, utils_1.haveCommonElementsArr)(category.labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels);
}
let exhaustive_rules = false;
if (category.exhaustive_rules !== undefined) {
exhaustive_rules = category.exhaustive_rules;
}
if (!matched && category.rules !== undefined) {
// if no label did apply, check if any rule applies
matched = (0, regexUtils_2.matchesRules)(category.rules, pr, exhaustive_rules);
}
}
if (matched) {
pullRequests.push(body); // if matched add the PR to the list
} }
matchedOnce = matchedOnce || matched; matchedOnce = matchedOnce || matched;
} }
if (!matchedOnce) { if (!matchedOnce) {
// we allow to have pull requests included in an "uncategorized" category // we allow to have pull requests included in an "uncategorized" category
for (const [category, pullRequests] of categorized) { for (const category of flatCategories) {
const pullRequests = category.entries || [];
if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) { if ((category.labels === undefined || category.labels.length === 0) && category.rules === undefined) {
// check if any exclude label matches for the "uncategorized" category // check if any exclude label matches for the "uncategorized" category
if (category.exclude_labels !== undefined) { if (category.exclude_labels !== undefined) {
@@ -2711,26 +2681,16 @@ function buildChangelog(diffInfo, origPrs, options) {
} }
core.info(`️ Ordered all pull requests into ${categories.length} categories`); core.info(`️ Ordered all pull requests into ${categories.length} categories`);
// serialize and provide the categorized content as json // serialize and provide the categorized content as json
const transformedCategorized = Array.from(categorized).reduce((obj, [key, value]) => Object.assign(obj, { [key.key || key.title]: value }), {}); const transformedCategorized = {};
for (const category of flatCategories) {
Object.assign(transformedCategorized, { [category.key || category.title]: category.entries });
}
core.setOutput('categorized', JSON.stringify(transformedCategorized)); core.setOutput('categorized', JSON.stringify(transformedCategorized));
// construct final changelog // construct final changelog
let changelog = ''; let changelog = '';
for (const [category, pullRequests] of categorized) { for (const category of flatCategories) {
if (pullRequests.length > 0) { const pullRequests = category.entries || [];
if (category.title) { changelog = attachCategoryChangelog(changelog, category, pullRequests);
changelog = `${changelog + category.title}\n\n`;
}
for (const pr of pullRequests) {
changelog = `${changelog + pr}\n`;
}
changelog = `${changelog}\n`; // add space between sections
}
else if (category.empty_content !== undefined) {
if (category.title) {
changelog = `${changelog + category.title}\n\n`;
}
changelog = `${changelog + category.empty_content}\n\n`;
}
} }
core.info(`✒️ Wrote ${categorizedPrs.length} categorized pull requests down`); core.info(`✒️ Wrote ${categorizedPrs.length} categorized pull requests down`);
if (core.isDebug()) { if (core.isDebug()) {
@@ -2801,6 +2761,92 @@ function buildChangelog(diffInfo, origPrs, options) {
return transformedChangelog; return transformedChangelog;
} }
exports.buildChangelog = buildChangelog; exports.buildChangelog = buildChangelog;
function recursiveCategorizePr(category, pr, body) {
let matched = false;
let consumed = false;
if (category.categories) {
for (const childCategory of category.categories) {
const pullRequests = childCategory.entries || [];
matched = categorizePr(childCategory, pr);
if (matched) {
pullRequests.push(body); // if matched add the PR to the list
}
if (childCategory.consume) {
consumed = true;
continue;
}
}
}
if (!consumed) {
const pullRequests = category.entries || [];
matched = categorizePr(category, pr);
if (matched) {
pullRequests.push(body); // if matched add the PR to the list
}
}
return [matched, consumed];
}
function categorizePr(category, pr) {
let matched = false; // check if we matched within the given category
// check if any exclude label matches
if (category.exclude_labels !== undefined) {
if ((0, utils_1.haveCommonElementsArr)(category.exclude_labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels)) {
if (core.isDebug()) {
const excludeLabels = JSON.stringify(category.exclude_labels);
core.debug(` PR ${pr.number} with labels: ${pr.labels} excluded from category via exclude label: ${excludeLabels}`);
}
return false; // one of the exclude labels matched, skip the PR for this category
}
}
// in case we have exhaustive matching enabled, and have labels and/or rules
// validate for an exhaustive match (e.g. every provided rule applies)
if (category.exhaustive === true && (category.labels !== undefined || category.rules !== undefined)) {
if (category.labels !== undefined) {
matched = (0, utils_1.haveEveryElementsArr)(category.labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels);
}
let exhaustive_rules = true;
if (category.exhaustive_rules !== undefined) {
exhaustive_rules = category.exhaustive_rules;
}
if ((matched || category.labels === undefined) && category.rules !== undefined) {
matched = (0, regexUtils_2.matchesRules)(category.rules, pr, exhaustive_rules);
}
}
else {
// if not exhaustive, do individual matches
if (category.labels !== undefined) {
// check if either any of the labels applies
matched = (0, utils_1.haveCommonElementsArr)(category.labels.map(lbl => lbl.toLocaleLowerCase('en')), pr.labels);
}
let exhaustive_rules = false;
if (category.exhaustive_rules !== undefined) {
exhaustive_rules = category.exhaustive_rules;
}
if (!matched && category.rules !== undefined) {
// if no label did apply, check if any rule applies
matched = (0, regexUtils_2.matchesRules)(category.rules, pr, exhaustive_rules);
}
}
return matched;
}
function attachCategoryChangelog(changelog, category, pullRequests) {
if (pullRequests.length > 0) {
if (category.title) {
changelog = `${changelog + category.title}\n\n`;
}
for (const pr of pullRequests) {
changelog = `${changelog + pr}\n`;
}
changelog = `${changelog}\n`; // add space between sections
}
else if (category.empty_content !== undefined) {
if (category.title) {
changelog = `${changelog + category.title}\n\n`;
}
changelog = `${changelog + category.empty_content}\n\n`;
}
return changelog;
}
function replaceEmptyTemplate(template, options) { function replaceEmptyTemplate(template, options) {
const placeholders = new Map(); const placeholders = new Map();
for (const ph of options.configuration.custom_placeholders || []) { for (const ph of options.configuration.custom_placeholders || []) {
@@ -3011,6 +3057,14 @@ function extractValuesFromString(value, extractor) {
return null; return null;
} }
} }
function flatten(categories) {
if (!categories) {
return [];
}
return categories.reduce(function (r, i) {
return r.concat([i]).concat(flatten(i.categories));
}, []);
}
/***/ }), /***/ }),
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+6 -1
View File
@@ -16,6 +16,11 @@ import {ReleaseNotesOptions} from './releaseNotesBuilder'
import {matchesRules} from './regexUtils' import {matchesRules} from './regexUtils'
const EMPTY_MAP = new Map<string, string>() const EMPTY_MAP = new Map<string, string>()
let CLEAR = false
export function clear(): void {
CLEAR = true
}
export interface PullRequestData extends PullRequestInfo { export interface PullRequestData extends PullRequestInfo {
childPrs?: PullRequestInfo[] childPrs?: PullRequestInfo[]
@@ -146,7 +151,7 @@ export function buildChangelog(diffInfo: DiffInfo, origPrs: PullRequestInfo[], o
// set-up the category object // set-up the category object
for (const category of flatCategories) { for (const category of flatCategories) {
if (!category.entries) { if (CLEAR || !category.entries) {
category.entries = [] category.entries = []
} }
} }