fix(changelog): changes here
This commit is contained in:
@@ -70,47 +70,62 @@ if (!GITEA_URL || !GITEA_USERNAME || !GITEA_REPO || !GITEA_TOKEN) {
|
||||
const getLatestChangelog = async () => {
|
||||
try {
|
||||
const changelogPath = path.resolve(__dirname, "../CHANGELOG.md");
|
||||
console.log(`Attempting to read changelog from: ${changelogPath}`); // Debugging line
|
||||
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
|
||||
// and split into lines for easier processing.
|
||||
const lines = changelogContent.trim().split(/\r?\n/); // Handles both \n and \r\n
|
||||
const lines = changelogContent.trim().split(/\r?\n/);
|
||||
|
||||
let latestReleaseNotes = [];
|
||||
let inLatestRelease = 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) {
|
||||
// Check for a release heading (e.g., "## [0.0.3-alpha.15] (2025-07-12)")
|
||||
if (line.match(/^## \[.*?\] \(.*?\)$/)) {
|
||||
// Trim each line to handle potential leading/trailing spaces when matching
|
||||
const trimmedLine = line.trim();
|
||||
|
||||
if (trimmedLine.match(releaseHeadingRegex)) {
|
||||
if (!foundFirstHeading) {
|
||||
// This is the first release heading we encounter, so start capturing
|
||||
// This is the first (latest) release heading we encounter
|
||||
inLatestRelease = true;
|
||||
foundFirstHeading = true;
|
||||
// Skip the heading line itself, or capture it if you want it in the notes
|
||||
// For typical release notes, you usually want the content *under* the heading.
|
||||
continue; // Skip the heading line itself from the notes
|
||||
// We skip the heading line itself from the notes body
|
||||
continue;
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
// If we are currently inside the latest release block, add the line
|
||||
if (inLatestRelease) {
|
||||
latestReleaseNotes.push(line);
|
||||
latestReleaseNotes.push(trimmedLine); // Use trimmedLine here
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up the collected notes
|
||||
const cleanedNotes = latestReleaseNotes.join("\n").trim();
|
||||
// Clean up the collected notes by filtering out empty lines if they are not meaningful content
|
||||
// and joining them back, then trimming.
|
||||
const cleanedNotes = latestReleaseNotes
|
||||
.filter((line) => line !== "") // Remove truly empty lines
|
||||
.join("\n")
|
||||
.trim();
|
||||
|
||||
if (cleanedNotes) {
|
||||
console.log("Successfully extracted latest changelog notes.");
|
||||
console.log(
|
||||
"Successfully extracted latest changelog notes:\n",
|
||||
cleanedNotes
|
||||
);
|
||||
return cleanedNotes;
|
||||
} else {
|
||||
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.";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user