Skip to content
Merged
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
35 changes: 25 additions & 10 deletions utils/draft_patch_release_notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// @ts-check

// Prints the draft notes of a patch release, for publish_manual.yml: the issues that the commits
// since the previous release fixed, and the browser versions when browsers.json changed.
// since the previous release fixed, the other commits that fixed no issue, and the browser versions
// when browsers.json changed.
// Run it before the commit that sets the new version.
//
// usage: draft_patch_release_notes.js <previous-release-tag>
Expand All @@ -32,6 +33,8 @@ const ROOT_PATH = path.join(__dirname, '..');
const REPOSITORY = 'microsoft/playwright';
const BROWSERS_JSON = 'packages/playwright-core/browsers.json';
const BROWSER_TITLES = { chromium: 'Chromium', firefox: 'Mozilla Firefox', webkit: 'WebKit' };
// Commits with these labels that fixed no issue are not in the notes.
const SKIPPED_LABELS = new Set(['devops', 'docs', 'test']);

/**
* @param {string} command
Expand All @@ -43,17 +46,18 @@ function run(command, args) {

/**
* @param {string} previousTag
* @returns {number[][]} The pull requests of each commit, oldest commit first.
* @returns {{ title: string, pullRequests: number[] }[]} The title and the pull requests of each commit, oldest commit first.
*/
function listPullRequests(previousTag) {
function listCommits(previousTag) {
const log = run('git', ['log', '--reverse', '--format=%s', `${previousTag}..HEAD`]);
return log.split('\n').filter(Boolean).map(subject => {
// "cherry-pick(#123): fix: foo (#456)" came from the pull request 123, "fix: foo (#123)" is the pull request 123.
const cherryPick = subject.match(/^cherry-pick\(([^)]*)\)/);
const cherryPick = subject.match(/^cherry-pick\(([^)]*)\):\s*(.*)$/);
const title = (cherryPick ? cherryPick[2] : subject).replace(/\s*\(#\d+\)$/, '');
if (cherryPick)
return [...cherryPick[1].matchAll(/#(\d+)/g)].map(match => +match[1]);
return { title, pullRequests: [...cherryPick[1].matchAll(/#(\d+)/g)].map(match => +match[1]) };
const squash = subject.match(/\(#(\d+)\)$/);
return squash ? [+squash[1]] : [];
return { title, pullRequests: squash ? [+squash[1]] : [] };
});
}

Expand Down Expand Up @@ -107,8 +111,9 @@ if (!previousTag) {
process.exit(1);
}

const pullRequests = listPullRequests(previousTag);
if (!pullRequests.length) {
const commits = listCommits(previousTag);
const pullRequests = commits.map(commit => commit.pullRequests);
if (!commits.length) {
console.error(`ERROR: there are no commits after ${previousTag}`);
process.exit(1);
}
Expand All @@ -121,9 +126,19 @@ for (const issue of pullRequests.flat().flatMap(number => fixedIssues.get(number
issueLines.set(issue.url, `- ${reference} ${issue.title}`);
}

// A commit that fixed no issue, for example a dependency roll, is in the notes with its own title.
const otherLines = [];
for (const commit of commits) {
if (commit.pullRequests.some(number => fixedIssues.get(number)?.length))
continue;
if (SKIPPED_LABELS.has(commit.title.match(/^\w+/)?.[0] ?? ''))
continue;
otherLines.push(`- ${[...commit.pullRequests.map(number => `#${number}`), commit.title].join(' ')}`);
}

const sections = [];
if (issueLines.size)
sections.push(['### Bug Fixes', '', ...issueLines.values()]);
if (issueLines.size || otherLines.length)
sections.push(['### Bug Fixes', '', ...issueLines.values(), ...otherLines]);
const versions = browserVersions(previousTag);
if (versions.length)
sections.push(['### Browser Versions', '', ...versions]);
Expand Down
Loading