mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Sort changelog entries in PRs by highest bump type
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -163,7 +163,7 @@ async function execWithOutput(
|
|||||||
|
|
||||||
await octokit.repos.createRelease({
|
await octokit.repos.createRelease({
|
||||||
tag_name: `${workspace.name}@${workspace.config.version}`,
|
tag_name: `${workspace.name}@${workspace.config.version}`,
|
||||||
body: changelogEntry,
|
body: changelogEntry.content,
|
||||||
prerelease: workspace.config.version.includes("-"),
|
prerelease: workspace.config.version.includes("-"),
|
||||||
...github.context.repo
|
...github.context.repo
|
||||||
});
|
});
|
||||||
@@ -251,11 +251,17 @@ async function execWithOutput(
|
|||||||
changelogContents,
|
changelogContents,
|
||||||
pkgJsonContent.version
|
pkgJsonContent.version
|
||||||
);
|
);
|
||||||
return (
|
return {
|
||||||
`## ${pkgJsonContent.name}@${pkgJsonContent.version}\n\n` + entry
|
highestLevel: entry.highestLevel,
|
||||||
);
|
content:
|
||||||
|
`## ${pkgJsonContent.name}@${pkgJsonContent.version}\n\n` +
|
||||||
|
entry.content
|
||||||
|
};
|
||||||
})
|
})
|
||||||
)).join("\n ")
|
))
|
||||||
|
.sort((a, b) => b.highestLevel - a.highestLevel)
|
||||||
|
.map(x => x.content)
|
||||||
|
.join("\n ")
|
||||||
);
|
);
|
||||||
})();
|
})();
|
||||||
await exec("git", ["add", "."]);
|
await exec("git", ["add", "."]);
|
||||||
@@ -288,11 +294,20 @@ async function execWithOutput(
|
|||||||
core.setFailed(err.message);
|
core.setFailed(err.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
enum BumpLevels {
|
||||||
|
dep = 0,
|
||||||
|
patch = 1,
|
||||||
|
minor = 2,
|
||||||
|
major = 3
|
||||||
|
}
|
||||||
|
|
||||||
function getChangelogEntry(changelog: string, version: string) {
|
function getChangelogEntry(changelog: string, version: string) {
|
||||||
let ast = unified()
|
let ast = unified()
|
||||||
.use(remarkParse)
|
.use(remarkParse)
|
||||||
.parse(changelog);
|
.parse(changelog);
|
||||||
|
|
||||||
|
let highestLevel = BumpLevels.dep;
|
||||||
|
|
||||||
let nodes = ast.children as Array<any>;
|
let nodes = ast.children as Array<any>;
|
||||||
let headingStartInfo:
|
let headingStartInfo:
|
||||||
| {
|
| {
|
||||||
@@ -304,24 +319,29 @@ function getChangelogEntry(changelog: string, version: string) {
|
|||||||
|
|
||||||
for (let i = 0; i < nodes.length; i++) {
|
for (let i = 0; i < nodes.length; i++) {
|
||||||
let node = nodes[i];
|
let node = nodes[i];
|
||||||
if (
|
if (node.type === "heading") {
|
||||||
headingStartInfo === undefined &&
|
let stringified: string = mdastToString(node);
|
||||||
node.type === "heading" &&
|
let match = stringified.toLowerCase().match(/(major|minor|patch)/);
|
||||||
mdastToString(node) === version
|
if (match !== null) {
|
||||||
) {
|
let level = BumpLevels[match[0] as "major" | "minor" | "patch"];
|
||||||
headingStartInfo = {
|
highestLevel = Math.max(level, highestLevel);
|
||||||
index: i,
|
}
|
||||||
depth: node.depth
|
if (headingStartInfo === undefined && stringified === version) {
|
||||||
};
|
headingStartInfo = {
|
||||||
continue;
|
index: i,
|
||||||
|
depth: node.depth
|
||||||
|
};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
endIndex === undefined &&
|
||||||
headingStartInfo !== undefined &&
|
headingStartInfo !== undefined &&
|
||||||
node.type === "heading" &&
|
node.type === "heading" &&
|
||||||
headingStartInfo.depth === node.depth
|
headingStartInfo.depth === node.depth
|
||||||
) {
|
) {
|
||||||
endIndex = i;
|
endIndex = i;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (headingStartInfo) {
|
if (headingStartInfo) {
|
||||||
@@ -330,7 +350,10 @@ function getChangelogEntry(changelog: string, version: string) {
|
|||||||
endIndex
|
endIndex
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return unified()
|
return {
|
||||||
.use(remarkStringify)
|
content: unified()
|
||||||
.stringify(ast);
|
.use(remarkStringify)
|
||||||
|
.stringify(ast),
|
||||||
|
highestLevel: highestLevel
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user