Merge pull request #42 from mikepenz/develop

dev -> main
This commit is contained in:
Mike Penz
2020-10-18 12:29:56 +02:00
committed by GitHub
5 changed files with 149 additions and 96 deletions
Generated Vendored
+132 -79
View File
@@ -299,80 +299,65 @@ const utils_1 = __webpack_require__(918);
const releaseNotes_1 = __webpack_require__(5882); const releaseNotes_1 = __webpack_require__(5882);
const gitHelper_1 = __webpack_require__(353); const gitHelper_1 = __webpack_require__(353);
const github = __importStar(__webpack_require__(5438)); const github = __importStar(__webpack_require__(5438));
const path = __importStar(__webpack_require__(5622));
const configuration_1 = __webpack_require__(5527); const configuration_1 = __webpack_require__(5527);
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.setOutput('failed', false); // mark the action not failed by default
core.startGroup(`📘 Reading input values`); core.startGroup(`📘 Reading input values`);
try { try {
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']; // read in path specification, resolve github workspace, and repo path
if (!githubWorkspacePath) { const inputPath = core.getInput('path');
throw new Error('GITHUB_WORKSPACE not defined'); const repositoryPath = utils_1.retrieveRepositoryPath(inputPath);
} // read in configuration file if possible
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`);
let repositoryPath = core.getInput('path') || '.';
repositoryPath = path.resolve(githubWorkspacePath, repositoryPath);
core.debug(`repositoryPath = '${repositoryPath}'`);
const configurationFile = core.getInput('configuration'); const configurationFile = core.getInput('configuration');
let configuration = configuration_1.DefaultConfiguration; const configuration = utils_1.resolveConfiguration(repositoryPath, configurationFile);
if (configurationFile) { // read in repository inputs
const configurationPath = path.resolve(githubWorkspacePath, configurationFile);
core.debug(`configurationPath = '${configurationPath}'`);
const providedConfiguration = utils_1.readConfiguration(configurationPath);
if (!providedConfiguration) {
core.info(`⚠️ Configuration provided, but it couldn't be found, or failed to parse. Fallback to Defaults`);
}
else {
configuration = providedConfiguration;
}
}
const token = core.getInput('token'); const token = core.getInput('token');
let owner = core.getInput('owner'); const owner = core.getInput('owner') || github.context.repo.owner;
let repo = core.getInput('repo'); const repo = core.getInput('repo') || github.context.repo.repo;
// read in from, to tag inputs
const fromTag = core.getInput('fromTag'); const fromTag = core.getInput('fromTag');
let toTag = core.getInput('toTag'); let toTag = core.getInput('toTag');
const ignorePreReleases = core.getInput('ignorePreReleases'); // read in flags
const ignorePreReleases = core.getInput('ignorePreReleases') === 'true';
const failOnError = core.getInput('failOnError') === 'true';
// ensure to resolve the toTag if it was not provided
if (!toTag) { if (!toTag) {
// if not specified try to retrieve tag from git // if not specified try to retrieve tag from github.context.ref
const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath); if (github.context.ref.startsWith('refs/tags/')) {
const latestTag = yield gitHelper.latestTag(); toTag = github.context.ref.replace('refs/tags/', '');
toTag = latestTag; core.info(`🔖 Resolved current tag (${toTag}) from the 'github.context.ref'`);
core.debug(`toTag = '${latestTag}'`); }
} else {
if (!owner || !repo) { // if not specified try to retrieve tag from git
// Qualified repository const gitHelper = yield gitHelper_1.createCommandManager(repositoryPath);
const qualifiedRepository = core.getInput('repository') || const latestTag = yield gitHelper.latestTag();
`${github.context.repo.owner}/${github.context.repo.repo}`; toTag = latestTag;
core.debug(`qualified repository = '${qualifiedRepository}'`); core.info(`🔖 Resolved current tag (${toTag}) from 'git rev-list --tags --skip=0 --max-count=1'`);
const splitRepository = qualifiedRepository.split('/');
if (splitRepository.length !== 2 ||
!splitRepository[0] ||
!splitRepository[1]) {
throw new Error(`Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.`);
} }
owner = splitRepository[0];
repo = splitRepository[1];
} }
if (!owner) { if (!owner) {
core.error(`💥 Missing or couldn't resolve 'owner'`); utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError);
return; return;
} }
else { else {
core.setOutput('owner', owner);
core.debug(`Resolved 'owner' as ${owner}`); core.debug(`Resolved 'owner' as ${owner}`);
} }
if (!repo) { if (!repo) {
core.error(`💥 Missing or couldn't resolve 'owner'`); utils_1.failOrError(`💥 Missing or couldn't resolve 'owner'`, failOnError);
return; return;
} }
else { else {
core.setOutput('repo', repo);
core.debug(`Resolved 'repo' as ${repo}`); core.debug(`Resolved 'repo' as ${repo}`);
} }
if (!toTag) { if (!toTag) {
core.error(`💥 Missing or couldn't resolve 'toTag'`); utils_1.failOrError(`💥 Missing or couldn't resolve 'toTag'`, failOnError);
return; return;
} }
else { else {
core.setOutput('toTag', toTag);
core.debug(`Resolved 'toTag' as ${toTag}`); core.debug(`Resolved 'toTag' as ${toTag}`);
} }
core.endGroup(); core.endGroup();
@@ -381,10 +366,13 @@ function run() {
repo, repo,
fromTag, fromTag,
toTag, toTag,
ignorePreReleases: ignorePreReleases === 'true', ignorePreReleases,
failOnError,
configuration configuration
}); });
core.setOutput('changelog', yield releaseNotes.pull(token)); core.setOutput('changelog', (yield releaseNotes.pull(token)) ||
configuration.empty_template ||
configuration_1.DefaultConfiguration.empty_template);
} }
catch (error) { catch (error) {
core.setFailed(error.message); core.setFailed(error.message);
@@ -639,36 +627,44 @@ const transform_1 = __webpack_require__(1644);
const core = __importStar(__webpack_require__(2186)); const core = __importStar(__webpack_require__(2186));
const tags_1 = __webpack_require__(7532); const tags_1 = __webpack_require__(7532);
const configuration_1 = __webpack_require__(5527); const configuration_1 = __webpack_require__(5527);
const utils_1 = __webpack_require__(918);
class ReleaseNotes { class ReleaseNotes {
constructor(options) { constructor(options) {
this.options = options; this.options = options;
} }
pull(token) { pull(token) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const octokit = new rest_1.Octokit({ const octokit = new rest_1.Octokit({
auth: `token ${token || process.env.GITHUB_TOKEN}` auth: `token ${token || process.env.GITHUB_TOKEN}`
}); });
const { owner, repo, toTag, ignorePreReleases, configuration } = this.options; const { owner, repo, toTag, ignorePreReleases, failOnError, configuration } = this.options;
if (!this.options.fromTag) { if (!this.options.fromTag) {
core.startGroup(`🔖 Resolve previous tag`); core.startGroup(`🔖 Resolve previous tag`);
core.debug(`fromTag undefined, trying to resolve via API`); core.debug(`fromTag undefined, trying to resolve via API`);
const tagsApi = new tags_1.Tags(octokit); const tagsApi = new tags_1.Tags(octokit);
const previousTag = yield tagsApi.findPredecessorTag(owner, repo, toTag, ignorePreReleases, (_a = configuration.max_tags_to_fetch) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.max_tags_to_fetch); const previousTag = yield tagsApi.findPredecessorTag(owner, repo, toTag, ignorePreReleases, configuration.max_tags_to_fetch ||
configuration_1.DefaultConfiguration.max_tags_to_fetch);
if (previousTag == null) { if (previousTag == null) {
core.error(`💥 Unable to retrieve previous tag given ${toTag}`); utils_1.failOrError(`💥 Unable to retrieve previous tag given ${toTag}`, failOnError);
return ((_b = configuration.empty_template) !== null && _b !== void 0 ? _b : configuration_1.DefaultConfiguration.empty_template); return null;
} }
this.options.fromTag = previousTag.name; this.options.fromTag = previousTag.name;
core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`); core.debug(`fromTag resolved via previousTag as: ${previousTag.name}`);
core.endGroup(); core.endGroup();
} }
if (!this.options.fromTag) {
utils_1.failOrError(`💥 Missing or couldn't resolve 'fromTag'`, failOnError);
return null;
}
else {
core.setOutput('fromTag', this.options.fromTag);
}
core.startGroup(`🚀 Load pull requests`); core.startGroup(`🚀 Load pull requests`);
const mergedPullRequests = yield this.getMergedPullRequests(octokit); const mergedPullRequests = yield this.getMergedPullRequests(octokit);
core.endGroup(); core.endGroup();
if (mergedPullRequests.length === 0) { if (mergedPullRequests.length === 0) {
core.warning(`⚠️ No pull requests found`); core.warning(`⚠️ No pull requests found`);
return (_c = configuration.empty_template) !== null && _c !== void 0 ? _c : configuration_1.DefaultConfiguration.empty_template; return null;
} }
core.startGroup('📦 Build changelog'); core.startGroup('📦 Build changelog');
const resultChangelog = transform_1.buildChangelog(mergedPullRequests, configuration); const resultChangelog = transform_1.buildChangelog(mergedPullRequests, configuration);
@@ -677,9 +673,8 @@ class ReleaseNotes {
}); });
} }
getMergedPullRequests(octokit) { getMergedPullRequests(octokit) {
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const { owner, repo, fromTag, toTag, configuration } = this.options; const { owner, repo, fromTag, toTag, failOnError, configuration } = this.options;
core.info(`️ Comparing ${owner}/${repo} - '${fromTag}...${toTag}'`); core.info(`️ Comparing ${owner}/${repo} - '${fromTag}...${toTag}'`);
const commitsApi = new commits_1.Commits(octokit); const commitsApi = new commits_1.Commits(octokit);
let commits; let commits;
@@ -687,18 +682,19 @@ class ReleaseNotes {
commits = yield commitsApi.getDiff(owner, repo, fromTag, toTag); commits = yield commitsApi.getDiff(owner, repo, fromTag, toTag);
} }
catch (error) { catch (error) {
core.error(`💥 Failed to retrieve - Invalid tag? - Because of: ${error}`); utils_1.failOrError(`💥 Failed to retrieve - Invalid tag? - Because of: ${error}`, failOnError);
return []; return [];
} }
if (commits.length === 0) { if (commits.length === 0) {
core.warning(`💥 No commits found between - ${fromTag}...${toTag}`); core.warning(`⚠️ No commits found between - ${fromTag}...${toTag}`);
return []; return [];
} }
const firstCommit = commits[0]; const firstCommit = commits[0];
const lastCommit = commits[commits.length - 1]; const lastCommit = commits[commits.length - 1];
let fromDate = firstCommit.date; let fromDate = firstCommit.date;
const toDate = lastCommit.date; const toDate = lastCommit.date;
const maxDays = (_a = configuration.max_back_track_time_days) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.max_back_track_time_days; const maxDays = configuration.max_back_track_time_days ||
configuration_1.DefaultConfiguration.max_back_track_time_days;
const maxFromDate = toDate.clone().subtract(maxDays, 'days'); const maxFromDate = toDate.clone().subtract(maxDays, 'days');
if (maxFromDate.isAfter(fromDate)) { if (maxFromDate.isAfter(fromDate)) {
core.info(`⚠️ Adjusted 'fromDate' to go max ${maxDays} back`); core.info(`⚠️ Adjusted 'fromDate' to go max ${maxDays} back`);
@@ -706,9 +702,10 @@ class ReleaseNotes {
} }
core.info(`️ Fetching PRs between dates ${fromDate.toISOString()} to ${toDate.toISOString()} for ${owner}/${repo}`); core.info(`️ Fetching PRs between dates ${fromDate.toISOString()} to ${toDate.toISOString()} for ${owner}/${repo}`);
const pullRequestsApi = new pullRequests_1.PullRequests(octokit); const pullRequestsApi = new pullRequests_1.PullRequests(octokit);
const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, (_b = configuration.max_pull_requests) !== null && _b !== void 0 ? _b : configuration_1.DefaultConfiguration.max_pull_requests); const pullRequests = yield pullRequestsApi.getBetweenDates(owner, repo, fromDate, toDate, configuration.max_pull_requests || configuration_1.DefaultConfiguration.max_pull_requests);
core.info(`️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`); core.info(`️ Retrieved ${pullRequests.length} merged PRs for ${owner}/${repo}`);
const prCommits = pullRequestsApi.filterCommits(commits, (_c = configuration.exclude_merge_branches) !== null && _c !== void 0 ? _c : configuration_1.DefaultConfiguration.exclude_merge_branches); const prCommits = pullRequestsApi.filterCommits(commits, configuration.exclude_merge_branches ||
configuration_1.DefaultConfiguration.exclude_merge_branches);
core.info(`️ Retrieved ${prCommits.length} PR merge commits for ${owner}/${repo}`); core.info(`️ Retrieved ${prCommits.length} PR merge commits for ${owner}/${repo}`);
const filteredPullRequests = []; const filteredPullRequests = [];
const pullRequestsByNumber = {}; const pullRequestsByNumber = {};
@@ -926,9 +923,8 @@ const pullRequests_1 = __webpack_require__(4217);
const core = __importStar(__webpack_require__(2186)); const core = __importStar(__webpack_require__(2186));
const configuration_1 = __webpack_require__(5527); const configuration_1 = __webpack_require__(5527);
function buildChangelog(prs, config) { function buildChangelog(prs, config) {
var _a, _b, _c;
// sort to target order // sort to target order
const sort = (_a = config.sort) !== null && _a !== void 0 ? _a : configuration_1.DefaultConfiguration.sort; const sort = config.sort || configuration_1.DefaultConfiguration.sort;
const sortAsc = sort.toUpperCase() === 'ASC'; const sortAsc = sort.toUpperCase() === 'ASC';
prs = pullRequests_1.sortPullRequests(prs, sortAsc); prs = pullRequests_1.sortPullRequests(prs, sortAsc);
core.info(`️ Sorted all pull requests ascending: ${sort}`); core.info(`️ Sorted all pull requests ascending: ${sort}`);
@@ -944,7 +940,7 @@ function buildChangelog(prs, config) {
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 categorized = new Map();
const categories = (_b = config.categories) !== null && _b !== void 0 ? _b : configuration_1.DefaultConfiguration.categories; const categories = config.categories || configuration_1.DefaultConfiguration.categories;
for (const category of categories) { for (const category of categories) {
categorized.set(category, []); categorized.set(category, []);
} }
@@ -982,7 +978,7 @@ function buildChangelog(prs, config) {
} }
core.info(`✒️ Wrote ${changelogUncategorized.length} non categorized pull requests down`); core.info(`✒️ Wrote ${changelogUncategorized.length} non categorized pull requests down`);
// fill template // fill template
let transformedChangelog = (_c = config.template) !== null && _c !== void 0 ? _c : configuration_1.DefaultConfiguration.template; let transformedChangelog = config.template || configuration_1.DefaultConfiguration.template;
transformedChangelog = transformedChangelog.replace('${{CHANGELOG}}', changelog); transformedChangelog = transformedChangelog.replace('${{CHANGELOG}}', changelog);
transformedChangelog = transformedChangelog.replace('${{UNCATEGORIZED}}', changelogUncategorized); transformedChangelog = transformedChangelog.replace('${{UNCATEGORIZED}}', changelogUncategorized);
core.info(`️ Filled template`); core.info(`️ Filled template`);
@@ -993,18 +989,18 @@ function haveCommonElements(arr1, arr2) {
return arr1.some(item => arr2.includes(item)); return arr1.some(item => arr2.includes(item));
} }
function fillTemplate(pr, template) { function fillTemplate(pr, template) {
var _a, _b, _c, _d, _e, _f, _g; var _a, _b, _c;
let transformed = template; let transformed = template;
transformed = transformed.replace('${{NUMBER}}', pr.number.toString()); transformed = transformed.replace('${{NUMBER}}', pr.number.toString());
transformed = transformed.replace('${{TITLE}}', pr.title); transformed = transformed.replace('${{TITLE}}', pr.title);
transformed = transformed.replace('${{URL}}', pr.htmlURL); transformed = transformed.replace('${{URL}}', pr.htmlURL);
transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString()); transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString());
transformed = transformed.replace('${{AUTHOR}}', pr.author); transformed = transformed.replace('${{AUTHOR}}', pr.author);
transformed = transformed.replace('${{LABELS}}', (_b = (_a = pr.labels) === null || _a === void 0 ? void 0 : _a.join(', ')) !== null && _b !== void 0 ? _b : ''); transformed = transformed.replace('${{LABELS}}', ((_a = pr.labels) === null || _a === void 0 ? void 0 : _a.join(', ')) || '');
transformed = transformed.replace('${{MILESTONE}}', (_c = pr.milestone) !== null && _c !== void 0 ? _c : ''); transformed = transformed.replace('${{MILESTONE}}', pr.milestone || '');
transformed = transformed.replace('${{BODY}}', pr.body); transformed = transformed.replace('${{BODY}}', pr.body);
transformed = transformed.replace('${{ASSIGNEES}}', (_e = (_d = pr.assignees) === null || _d === void 0 ? void 0 : _d.join(', ')) !== null && _e !== void 0 ? _e : ''); transformed = transformed.replace('${{ASSIGNEES}}', ((_b = pr.assignees) === null || _b === void 0 ? void 0 : _b.join(', ')) || '');
transformed = transformed.replace('${{REVIEWERS}}', (_g = (_f = pr.requestedReviewers) === null || _f === void 0 ? void 0 : _f.join(', ')) !== null && _g !== void 0 ? _g : ''); transformed = transformed.replace('${{REVIEWERS}}', ((_c = pr.requestedReviewers) === null || _c === void 0 ? void 0 : _c.join(', ')) || '');
return transformed; return transformed;
} }
function transform(filled, transformers) { function transform(filled, transformers) {
@@ -1018,7 +1014,7 @@ function transform(filled, transformers) {
return transformed; return transformed;
} }
function validateTransfomers(specifiedTransformers) { function validateTransfomers(specifiedTransformers) {
const transformers = specifiedTransformers !== null && specifiedTransformers !== void 0 ? specifiedTransformers : configuration_1.DefaultConfiguration.transformers; const transformers = specifiedTransformers || configuration_1.DefaultConfiguration.transformers;
return transformers return transformers
.map(transformer => { .map(transformer => {
try { try {
@@ -1066,8 +1062,63 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.directoryExistsSync = exports.readConfiguration = void 0; exports.directoryExistsSync = exports.resolveConfiguration = exports.failOrError = exports.retrieveRepositoryPath = void 0;
const fs = __importStar(__webpack_require__(5747)); const fs = __importStar(__webpack_require__(5747));
const configuration_1 = __webpack_require__(5527);
const core = __importStar(__webpack_require__(2186));
const path = __importStar(__webpack_require__(5622));
/**
* Resolves the repository path, relatively to the GITHUB_WORKSPACE
*/
function retrieveRepositoryPath(providedPath) {
let githubWorkspacePath = process.env['GITHUB_WORKSPACE'];
if (!githubWorkspacePath) {
throw new Error('GITHUB_WORKSPACE not defined');
}
githubWorkspacePath = path.resolve(githubWorkspacePath);
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`);
let repositoryPath = providedPath || '.';
repositoryPath = path.resolve(githubWorkspacePath, repositoryPath);
core.debug(`repositoryPath = '${repositoryPath}'`);
return repositoryPath;
}
exports.retrieveRepositoryPath = retrieveRepositoryPath;
/**
* Will automatically either report the message to the log, or mark the action as failed. Additionally defining the output failed, allowing it to be read in by other actions
*/
function failOrError(message, failOnError) {
// if we report any failure, consider the action to have failed, may not make the build fail
core.setOutput('failed', true);
if (failOnError) {
core.setFailed(message);
}
else {
core.error(message);
}
}
exports.failOrError = failOrError;
/**
* Retrieves the configuration given the file path, if not found it will fallback to the `DefaultConfiguration`
*/
function resolveConfiguration(githubWorkspacePath, configurationFile) {
let configuration = configuration_1.DefaultConfiguration;
if (configurationFile) {
const configurationPath = path.resolve(githubWorkspacePath, configurationFile);
core.debug(`configurationPath = '${configurationPath}'`);
const providedConfiguration = readConfiguration(configurationPath);
if (!providedConfiguration) {
core.info(`⚠️ Configuration provided, but it couldn't be found, or failed to parse. Fallback to Defaults`);
}
else {
configuration = providedConfiguration;
}
}
return configuration;
}
exports.resolveConfiguration = resolveConfiguration;
/**
* Reads in the configuration from the JSON file
*/
function readConfiguration(filename) { function readConfiguration(filename) {
try { try {
const rawdata = fs.readFileSync(filename, 'utf8'); const rawdata = fs.readFileSync(filename, 'utf8');
@@ -1078,23 +1129,25 @@ function readConfiguration(filename) {
return null; return null;
} }
} }
exports.readConfiguration = readConfiguration; /**
function directoryExistsSync(path, required) { * Checks if a given directory exists
if (!path) { */
function directoryExistsSync(inputPath, required) {
if (!inputPath) {
throw new Error("Arg 'path' must not be empty"); throw new Error("Arg 'path' must not be empty");
} }
let stats; let stats;
try { try {
stats = fs.statSync(path); stats = fs.statSync(inputPath);
} }
catch (error) { catch (error) {
if (error.code === 'ENOENT') { if (error.code === 'ENOENT') {
if (!required) { if (!required) {
return false; return false;
} }
throw new Error(`Directory '${path}' does not exist`); throw new Error(`Directory '${inputPath}' does not exist`);
} }
throw new Error(`Encountered an error when checking whether path '${path}' exists: ${error.message}`); throw new Error(`Encountered an error when checking whether path '${inputPath}' exists: ${error.message}`);
} }
if (stats.isDirectory()) { if (stats.isDirectory()) {
return true; return true;
@@ -1102,7 +1155,7 @@ function directoryExistsSync(path, required) {
else if (!required) { else if (!required) {
return false; return false;
} }
throw new Error(`Directory '${path}' does not exist`); throw new Error(`Directory '${inputPath}' does not exist`);
} }
exports.directoryExistsSync = directoryExistsSync; exports.directoryExistsSync = directoryExistsSync;
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+4 -4
View File
@@ -27,8 +27,8 @@ async function run(): Promise<void> {
// read in repository inputs // read in repository inputs
const token = core.getInput('token') const token = core.getInput('token')
const owner = core.getInput('owner') ?? github.context.repo.owner const owner = core.getInput('owner') || github.context.repo.owner
const repo = core.getInput('repo') ?? github.context.repo.repo const repo = core.getInput('repo') || github.context.repo.repo
// read in from, to tag inputs // read in from, to tag inputs
const fromTag = core.getInput('fromTag') const fromTag = core.getInput('fromTag')
let toTag = core.getInput('toTag') let toTag = core.getInput('toTag')
@@ -92,8 +92,8 @@ async function run(): Promise<void> {
core.setOutput( core.setOutput(
'changelog', 'changelog',
(await releaseNotes.pull(token)) ?? (await releaseNotes.pull(token)) ||
configuration.empty_template ?? configuration.empty_template ||
DefaultConfiguration.empty_template DefaultConfiguration.empty_template
) )
} catch (error) { } catch (error) {
+4 -4
View File
@@ -44,7 +44,7 @@ export class ReleaseNotes {
repo, repo,
toTag, toTag,
ignorePreReleases, ignorePreReleases,
configuration.max_tags_to_fetch ?? configuration.max_tags_to_fetch ||
DefaultConfiguration.max_tags_to_fetch DefaultConfiguration.max_tags_to_fetch
) )
if (previousTag == null) { if (previousTag == null) {
@@ -116,7 +116,7 @@ export class ReleaseNotes {
const toDate = lastCommit.date const toDate = lastCommit.date
const maxDays = const maxDays =
configuration.max_back_track_time_days ?? configuration.max_back_track_time_days ||
DefaultConfiguration.max_back_track_time_days DefaultConfiguration.max_back_track_time_days
const maxFromDate = toDate.clone().subtract(maxDays, 'days') const maxFromDate = toDate.clone().subtract(maxDays, 'days')
if (maxFromDate.isAfter(fromDate)) { if (maxFromDate.isAfter(fromDate)) {
@@ -134,7 +134,7 @@ export class ReleaseNotes {
repo, repo,
fromDate, fromDate,
toDate, toDate,
configuration.max_pull_requests ?? DefaultConfiguration.max_pull_requests configuration.max_pull_requests || DefaultConfiguration.max_pull_requests
) )
core.info( core.info(
@@ -143,7 +143,7 @@ export class ReleaseNotes {
const prCommits = pullRequestsApi.filterCommits( const prCommits = pullRequestsApi.filterCommits(
commits, commits,
configuration.exclude_merge_branches ?? configuration.exclude_merge_branches ||
DefaultConfiguration.exclude_merge_branches DefaultConfiguration.exclude_merge_branches
) )
+8 -8
View File
@@ -12,7 +12,7 @@ export function buildChangelog(
config: Configuration config: Configuration
): string { ): string {
// sort to target order // sort to target order
const sort = config.sort ?? DefaultConfiguration.sort const sort = config.sort || DefaultConfiguration.sort
const sortAsc = sort.toUpperCase() === 'ASC' const sortAsc = sort.toUpperCase() === 'ASC'
prs = sortPullRequests(prs, sortAsc) prs = sortPullRequests(prs, sortAsc)
core.info(`️ Sorted all pull requests ascending: ${sort}`) core.info(`️ Sorted all pull requests ascending: ${sort}`)
@@ -41,7 +41,7 @@ export function buildChangelog(
// bring PRs into the order of categories // bring PRs into the order of categories
const categorized = new Map<Category, string[]>() const categorized = new Map<Category, string[]>()
const categories = config.categories ?? DefaultConfiguration.categories const categories = config.categories || DefaultConfiguration.categories
for (const category of categories) { for (const category of categories) {
categorized.set(category, []) categorized.set(category, [])
} }
@@ -89,7 +89,7 @@ export function buildChangelog(
) )
// fill template // fill template
let transformedChangelog = config.template ?? DefaultConfiguration.template let transformedChangelog = config.template || DefaultConfiguration.template
transformedChangelog = transformedChangelog.replace( transformedChangelog = transformedChangelog.replace(
'${{CHANGELOG}}', '${{CHANGELOG}}',
changelog changelog
@@ -113,16 +113,16 @@ function fillTemplate(pr: PullRequestInfo, template: string): string {
transformed = transformed.replace('${{URL}}', pr.htmlURL) transformed = transformed.replace('${{URL}}', pr.htmlURL)
transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString()) transformed = transformed.replace('${{MERGED_AT}}', pr.mergedAt.toISOString())
transformed = transformed.replace('${{AUTHOR}}', pr.author) transformed = transformed.replace('${{AUTHOR}}', pr.author)
transformed = transformed.replace('${{LABELS}}', pr.labels?.join(', ') ?? '') transformed = transformed.replace('${{LABELS}}', pr.labels?.join(', ') || '')
transformed = transformed.replace('${{MILESTONE}}', pr.milestone ?? '') transformed = transformed.replace('${{MILESTONE}}', pr.milestone || '')
transformed = transformed.replace('${{BODY}}', pr.body) transformed = transformed.replace('${{BODY}}', pr.body)
transformed = transformed.replace( transformed = transformed.replace(
'${{ASSIGNEES}}', '${{ASSIGNEES}}',
pr.assignees?.join(', ') ?? '' pr.assignees?.join(', ') || ''
) )
transformed = transformed.replace( transformed = transformed.replace(
'${{REVIEWERS}}', '${{REVIEWERS}}',
pr.requestedReviewers?.join(', ') ?? '' pr.requestedReviewers?.join(', ') || ''
) )
return transformed return transformed
} }
@@ -142,7 +142,7 @@ function validateTransfomers(
specifiedTransformers: Transformer[] specifiedTransformers: Transformer[]
): RegexTransformer[] { ): RegexTransformer[] {
const transformers = const transformers =
specifiedTransformers ?? DefaultConfiguration.transformers specifiedTransformers || DefaultConfiguration.transformers
return transformers return transformers
.map(transformer => { .map(transformer => {
try { try {