Fix get preview channel changes script

This commit is contained in:
Joseph Lyons 2023-05-21 23:38:01 -04:00
parent d5cf595761
commit c701901c7b

View File

@ -2,8 +2,8 @@
const { execFileSync } = require("child_process");
const { GITHUB_ACCESS_TOKEN } = process.env;
const PR_REGEX = /pull request #(\d+)/;
const FIXES_REGEX = /(fixes|closes) (.+[/#]\d+.*)$/im;
const PR_REGEX = /#\d+/ // Ex: matches on #4241
const FIXES_REGEX = /(fixes|closes|completes) (.+[/#]\d+.*)$/im;
main();
@ -15,7 +15,7 @@ async function main() {
{ encoding: "utf8" }
)
.split("\n")
.filter((t) => t.startsWith("v") && t.endsWith('-pre'));
.filter((t) => t.startsWith("v") && t.endsWith("-pre"));
// Print the previous release
console.log(`Changes from ${oldTag} to ${newTag}\n`);
@ -34,37 +34,11 @@ async function main() {
}
// Get the PRs merged between those two tags.
const pullRequestNumbers = execFileSync(
"git",
[
"log",
`${oldTag}..${newTag}`,
"--oneline",
"--grep",
"Merge pull request",
],
{ encoding: "utf8" }
)
.split("\n")
.filter((line) => line.length > 0)
.map((line) => line.match(PR_REGEX)[1]);
const pullRequestNumbers = getPullRequestNumbers(oldTag, newTag)
// Get the PRs that were cherry-picked between main and the old tag.
const existingPullRequestNumbers = new Set(execFileSync(
"git",
[
"log",
`main..${oldTag}`,
"--oneline",
"--grep",
"Merge pull request",
],
{ encoding: "utf8" }
)
.split("\n")
.filter((line) => line.length > 0)
.map((line) => line.match(PR_REGEX)[1]));
const existingPullRequestNumbers = new Set(getPullRequestNumbers("main", oldTag))
// Filter out those existing PRs from the set of new PRs.
const newPullRequestNumbers = pullRequestNumbers.filter(number => !existingPullRequestNumbers.has(number));
@ -86,10 +60,39 @@ async function main() {
console.log(" URL: ", webURL);
// If the pull request contains a 'closes' line, print the closed issue.
const fixesMatch = (pullRequest.body || '').match(FIXES_REGEX);
const fixesMatch = (pullRequest.body || "").match(FIXES_REGEX);
if (fixesMatch) {
const fixedIssueURL = fixesMatch[2];
console.log(" Issue: ", fixedIssueURL);
}
let releaseNotes = (pullRequest.body || "").split("Release Notes:")[1];
if (releaseNotes) {
releaseNotes = releaseNotes.trim()
console.log(" Release Notes:");
console.log(` ${releaseNotes}`);
}
}
}
function getPullRequestNumbers(oldTag, newTag) {
const pullRequestNumbers = execFileSync(
"git",
[
"log",
`${oldTag}..${newTag}`,
"--oneline"
],
{ encoding: "utf8" }
)
.split("\n")
.filter(line => line.length > 0)
.map(line => {
const match = line.match(/#(\d+)/);
return match ? match[1] : null;
})
.filter(line => line)
return pullRequestNumbers
}