#!/usr/bin/env node --redirect-warnings=/dev/null const { execFileSync } = require("child_process"); let { GITHUB_ACCESS_TOKEN } = process.env; const GITHUB_URL = "https://github.com"; const SKIPPABLE_NOTE_REGEX = /^\s*-?\s*n\/?a\s*/ims; const PULL_REQUEST_WEB_URL = "https://github.com/zed-industries/zed/pull"; const PULL_REQUEST_API_URL = "https://api.github.com/repos/zed-industries/zed/pulls"; const DIVIDER = "-".repeat(80); // Maintain list manually, as our GitHub organization has community members in it. const STAFF_MEMBERS = new Set([ "as-cii", "bennetbo", "ConradIrwin", "danilobleal", "iamnbutler", "JosephTLyons", "jvmncs", "maxbrunsfeld", "maxdeviant", "mikayla-maki", "nathansobo", "notpeter", "osiewicz", "rgbkrk", "rtfeldman", "SomeoneToIgnore", "thorstenball", ]); main(); async function main() { // Get the last two preview tags const [newTag, oldTag] = execFileSync( "git", ["tag", "--sort", "-committerdate"], { encoding: "utf8" }, ) .split("\n") .filter((t) => t.startsWith("v") && t.endsWith("-pre")); // Print the previous release console.log(`Changes from ${oldTag} to ${newTag}\n`); if (!GITHUB_ACCESS_TOKEN) { try { GITHUB_ACCESS_TOKEN = execFileSync("gh", ["auth", "token"]).toString(); } catch (error) { console.log(error); console.log("No GITHUB_ACCESS_TOKEN, and no `gh auth token`"); process.exit(1); } } // Get the PRs merged between those two tags. const pullRequestNumbers = getPullRequestNumbers(oldTag, newTag); // Get the PRs that were cherry-picked between main and the old tag. 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), ); // Fetch the pull requests from the GitHub API. console.log("Merged Pull requests:"); console.log(DIVIDER); for (const pullRequestNumber of newPullRequestNumbers) { const pullRequestApiURL = `${PULL_REQUEST_API_URL}/${pullRequestNumber}`; const response = await fetch(pullRequestApiURL, { headers: { Authorization: `token ${GITHUB_ACCESS_TOKEN}`, }, }); const pullRequest = await response.json(); const releaseNotesHeader = /^\s*Release Notes:(.+)/ims; let releaseNotes = pullRequest.body || ""; let contributor = pullRequest.user?.login ?? "Unable to identify contributor"; const captures = releaseNotesHeader.exec(releaseNotes); let notes = captures ? captures[1] : "MISSING"; notes = notes.trim(); if (SKIPPABLE_NOTE_REGEX.exec(notes) != null) { continue; } let credit = getCreditString(pullRequestNumber, contributor); const isStaff = STAFF_MEMBERS.has(contributor); contributor = isStaff ? `${contributor} (staff)` : contributor; console.log(`PR Title: ${pullRequest.title}`); console.log(`Contributor: ${contributor}`); console.log(`Credit: (${credit})`); console.log("Release Notes:"); console.log(); console.log(notes); console.log(DIVIDER); } } function getCreditString(pullRequestNumber, contributor) { let credit = ""; if (pullRequestNumber) { let pullRequestMarkdownLink = `[#${pullRequestNumber}](${PULL_REQUEST_WEB_URL}/${pullRequestNumber})`; credit += pullRequestMarkdownLink; } if (contributor && !STAFF_MEMBERS.has(contributor)) { const contributorMarkdownLink = `[${contributor}](${GITHUB_URL}/${contributor})`; credit += `; thanks ${contributorMarkdownLink}`; } return credit; } 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; }