fix(changelog): changes here

This commit is contained in:
2025-07-12 17:30:12 -05:00
parent cded5982d4
commit 46579ac6d9

View File

@@ -70,47 +70,62 @@ if (!GITEA_URL || !GITEA_USERNAME || !GITEA_REPO || !GITEA_TOKEN) {
const getLatestChangelog = async () => { const getLatestChangelog = async () => {
try { try {
const changelogPath = path.resolve(__dirname, "../CHANGELOG.md"); const changelogPath = path.resolve(__dirname, "../CHANGELOG.md");
console.log(`Attempting to read changelog from: ${changelogPath}`); // Debugging line
const changelogContent = await fs.readFile(changelogPath, "utf8"); const changelogContent = await fs.readFile(changelogPath, "utf8");
console.log(
"Changelog content read successfully (first 200 chars):",
changelogContent.substring(0, 200)
); // Debugging line
// Trim the content to remove potential leading/trailing whitespace const lines = changelogContent.trim().split(/\r?\n/);
// and split into lines for easier processing.
const lines = changelogContent.trim().split(/\r?\n/); // Handles both \n and \r\n
let latestReleaseNotes = []; let latestReleaseNotes = [];
let inLatestRelease = false; let inLatestRelease = false;
let foundFirstHeading = false; let foundFirstHeading = false;
// Regex to match a conventional changelog heading format: "## [version](url) (date)"
// The key is to correctly parse the URL part in parentheses.
const releaseHeadingRegex = /^## \[.*?\]\(.*?\)\s\(.*\)$/;
for (const line of lines) { for (const line of lines) {
// Check for a release heading (e.g., "## [0.0.3-alpha.15] (2025-07-12)") // Trim each line to handle potential leading/trailing spaces when matching
if (line.match(/^## \[.*?\] \(.*?\)$/)) { const trimmedLine = line.trim();
if (trimmedLine.match(releaseHeadingRegex)) {
if (!foundFirstHeading) { if (!foundFirstHeading) {
// This is the first release heading we encounter, so start capturing // This is the first (latest) release heading we encounter
inLatestRelease = true; inLatestRelease = true;
foundFirstHeading = true; foundFirstHeading = true;
// Skip the heading line itself, or capture it if you want it in the notes // We skip the heading line itself from the notes body
// For typical release notes, you usually want the content *under* the heading. continue;
continue; // Skip the heading line itself from the notes
} else { } else {
// We've found a second release heading, meaning the latest release notes have ended // This is a subsequent release heading, meaning we've passed the latest release's content
break; break;
} }
} }
// If we are currently inside the latest release block, add the line // If we are currently inside the latest release block, add the line
if (inLatestRelease) { if (inLatestRelease) {
latestReleaseNotes.push(line); latestReleaseNotes.push(trimmedLine); // Use trimmedLine here
} }
} }
// Clean up the collected notes // Clean up the collected notes by filtering out empty lines if they are not meaningful content
const cleanedNotes = latestReleaseNotes.join("\n").trim(); // and joining them back, then trimming.
const cleanedNotes = latestReleaseNotes
.filter((line) => line !== "") // Remove truly empty lines
.join("\n")
.trim();
if (cleanedNotes) { if (cleanedNotes) {
console.log("Successfully extracted latest changelog notes."); console.log(
"Successfully extracted latest changelog notes:\n",
cleanedNotes
);
return cleanedNotes; return cleanedNotes;
} else { } else {
console.warn( console.warn(
"Could not find any content for the latest changelog entry in CHANGELOG.md." "Could not find any content for the latest changelog entry in CHANGELOG.md. This might mean the file is empty, or the regex for headings is incorrect, or there's no content after the heading."
); );
return "No changelog notes available."; return "No changelog notes available.";
} }