Visitar URL original
Convert last remaining Python CI scripts to TypeScript by mbg · Pull Request #4043 · github/codeql-action · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update processChangelogForBackports to use parseChangelog
  • Loading branch information
mbg committed Jul 24, 2026
commit adba0868a4038cf2cc306da86d5c53024f0109b4
80 changes: 34 additions & 46 deletions pr-checks/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,70 +155,58 @@ export function processChangelogForBackports(
targetBranchMajorVersion: string,
content: string,
): string {
const lines = content.split("\n");

// Changelog entries can use the following format to indicate
// that they only apply to newer versions
const someVersionsOnlyRegex = /\[v(\d+)\+ only\]/;

let output = "";
let i = 0;
// Parse the changelog.
const changelog = parseChangelog(content);

// Copy lines until we find the first section heading.
let foundFirstSection = false;
while (!foundFirstSection && i < lines.length) {
let line = lines[i];
if (line.startsWith("## ")) {
line = line.replace(
`## ${sourceBranchMajorVersion}`,
`## ${targetBranchMajorVersion}`,
);
foundFirstSection = true;
}
output += `${line}\n`;
i++;
}

if (!foundFirstSection) {
if (changelog.sections.length === 0) {
throw new Error("Could not find any change sections in CHANGELOG.md");
}

// Process remaining lines.
// `foundContent` tracks whether we hit two headings in a row
let foundContent = false;
output += "\n";

while (i < lines.length) {
let line = lines[i];
i++;

// Filter out changelog entries that only apply to newer versions.
const match = someVersionsOnlyRegex.exec(line);
if (match) {
// Filter out changelog entries that only apply to newer versions and
// update the section headings with the backport major version for
// sections we keep.
for (const section of changelog.sections) {
// Update the section headings with the backport major version.
section.headerLine = section.headerLine.replace(
`## ${sourceBranchMajorVersion}`,
`## ${targetBranchMajorVersion}`,
);

const filteredEntries: string[] = [];
let foundContent = false;

for (const line of section.bodyLines) {
// Skip the entry if `someVersionsOnlyRegex` matches and the major version
// of the target branch is smaller than the required version.
const match = someVersionsOnlyRegex.exec(line);
if (
match &&
Number.parseInt(targetBranchMajorVersion) < Number.parseInt(match[1])
) {
continue;
}
}

if (line.startsWith("## ")) {
line = line.replace(
`## ${sourceBranchMajorVersion}`,
`## ${targetBranchMajorVersion}`,
);
if (!foundContent) {
output += "No user facing changes.\n";
}
foundContent = false;
output += `\n${line}\n\n`;
} else {
// Keep the line.
filteredEntries.push(line);

// Set `foundContent` to `true` if the line is not empty.
if (line.trim() !== "") {
foundContent = true;
output += `${line}\n`;
}
Comment thread
navntoft marked this conversation as resolved.
Resolved
}

// Update the section with the retained entries.
section.bodyLines = filteredEntries;

// Add an entry if we didn't keep any.
if (!foundContent) {
section.bodyLines.push(NO_CHANGES_STR.trim());
}
}

return output;
return renderChangelog(changelog);
}