Skip to content

Filetered hotfix prs from release notes #3738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions scripts/release/prReleaseNotesCommon.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const _ = require('lodash');
const chalk = require('chalk');
const childProcess = require('child_process');
const readline = require('readline');

Expand Down Expand Up @@ -30,7 +31,7 @@ function parsePR(prContent) {
return PRInfo;
}

async function fetchMergedPRs(postMergedDate) {
async function fetchMergedPRs(postMergedDate, _repo, isPatchRelease) {
console.log('Find all merged PRs since - ', postMergedDate);
// process.stderr.write(`Loading page ${page}..`);
const str = childProcess.execSync('gh pr list --json headRefName,body,title,number,mergedAt,url,labels --limit 100 --state merged --search "base:master"',
Expand All @@ -44,27 +45,35 @@ async function fetchMergedPRs(postMergedDate) {
console.log('\x1b[31m', 'Something went wrong', PRs.message);
return;
}
const filteringMessageStyle = chalk.bgYellow.black;
console.log(filteringMessageStyle(isPatchRelease
? 'Patch release - only hotfix PRs will be included.'
: 'Non-patch release - hotfix PRs will be excluded.'));

const relevantPRs = _.flow(prs => _.filter(prs, pr => !!pr.mergedAt && new Date(pr.mergedAt) > postMergedDate),
prs => _.filter(prs, pr => {
const isHotfix = pr.labels.some(label => label.name === 'hotfix');
if (isHotfix && !isPatchRelease) {
console.log(filteringMessageStyle(`PR ${pr.number} is a hotfix and was excluded from the release notes.`));
}
return isPatchRelease ? isHotfix : !isHotfix;
}),
prs => _.sortBy(prs, 'mergedAt'),
prs =>
_.map(prs, pr => {
if (!pr.labels.some(label => label.name === 'hotfix')) {
try {
return {
mergedAt: pr.mergedAt,
url: pr.url,
branch: pr.headRefName,
number: pr.number,
title: pr.title,
info: parsePR(pr.body)
};
} catch {
console.error('Failed parsing PR: ', pr.url);
return null;
}
try {
return {
mergedAt: pr.mergedAt,
url: pr.url,
branch: pr.headRefName,
number: pr.number,
title: pr.title,
info: parsePR(pr.body)
};
} catch {
console.error('Failed parsing PR: ', pr.url);
return null;
}
return null;
}),
prs => _.compact(prs))(PRs);
return relevantPRs;
Expand Down Expand Up @@ -155,9 +164,9 @@ function getReleaseNotesForType(PRs, title) {
return releaseNotes;
}

async function _generateReleaseNotes(latestVersion, newVersion, fileNamePrefix, repo, header, tagPrefix, categories) {
async function _generateReleaseNotes(latestVersion, newVersion, fileNamePrefix, repo, header, tagPrefix, categories, isPatchRelease) {
const latestReleaseDate = fetchLatestReleaseDate(tagPrefix, latestVersion);
const PRs = await fetchMergedPRs(latestReleaseDate, repo);
const PRs = await fetchMergedPRs(latestReleaseDate, repo, isPatchRelease);
if (!PRs) {
return;
}
Expand Down Expand Up @@ -196,6 +205,13 @@ async function _generateReleaseNotes(latestVersion, newVersion, fileNamePrefix,
console.log(`\x1b[1m\x1b[32m✔\x1b[0m \x1b[32m${fileNamePrefix}-release-notes.txt was successfully written to ${process.env.HOME}/Downloads\x1b[0m \x1b[1m\x1b[32m✔\x1b[0m`);
}

function isPatchRelease(lastVersion, newVersion) {
const [lastMajor, lastMinor, lastPatch] = lastVersion.split('.').map(Number);
const [newMajor, newMinor, newPatch] = newVersion.split('.').map(Number);

return lastMajor === newMajor && lastMinor === newMinor && newPatch - lastPatch > 0;
}

async function generateReleaseNotes(latestVersion,
newVersion,
fileNamePrefix,
Expand All @@ -217,11 +233,12 @@ async function generateReleaseNotes(latestVersion,
});
});


rl.on('close', () => {
const header = getHeader(newVer);
console.info(`Current latest version is v${latestVer}`);
console.info(`Generating release notes out or PRs for v${newVer}`);
_generateReleaseNotes(latestVer, newVer, fileNamePrefix, repo, header, tagPrefix, categories);
_generateReleaseNotes(latestVer, newVer, fileNamePrefix, repo, header, tagPrefix, categories, isPatchRelease(latestVer, newVer));
});
}

Expand Down