Visitar URL original
Convert `update-release-branch.py` to TypeScript by mbg · Pull Request #4010 · github/codeql-action · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4c2bf01
Scaffold basic `update-release-branch.ts`
mbg Jul 14, 2026
8505293
Add constants
mbg Jul 14, 2026
1495237
Add `getGitHubToken`
mbg Jul 14, 2026
a10d7a7
Parse command line options
mbg Jul 14, 2026
d0b11ca
Make script executable
mbg Jul 14, 2026
1b146d1
Validate target branch and extract major version
mbg Jul 14, 2026
440cebc
Add `getCurrentVersion`
mbg Jul 14, 2026
4ca9f53
Add `runGit` and use it to obtain the source branch SHA
mbg Jul 14, 2026
c3da0a9
Fetch commit info
mbg Jul 14, 2026
5579217
Check whether the new branch exists
mbg Jul 14, 2026
460cc0c
Add dry run support and push branch
mbg Jul 14, 2026
212aa33
Add `runCommand`
mbg Jul 14, 2026
c8ed70e
Add `rebuildAction` function
mbg Jul 14, 2026
639fc5d
Add changelog helpers
mbg Jul 14, 2026
5e21203
Add `prepareNewBranch`
mbg Jul 14, 2026
78d71fb
Create PR
mbg Jul 14, 2026
5c030f4
Add summary comment
mbg Jul 14, 2026
2c45c81
Add `DryRunOption` interface
mbg Jul 14, 2026
4b861b8
Move changelog-related definitions into their own module
mbg Jul 14, 2026
e2472fc
Make `processChangelogForBackports` dry-run-aware
mbg Jul 14, 2026
fd0ae66
Restore some comments
mbg Jul 14, 2026
d4b3323
Use TS script in workflow
mbg Jul 14, 2026
f9a9f48
Run `npm ci` in `release-initialise` workflow.
mbg Jul 14, 2026
583bf3e
Fix comment typos
mbg Jul 14, 2026
d694648
Make `changelog.ts` more testable and add tests
mbg Jul 14, 2026
9b314f4
Make `replaceVersionInPackageJson` dry-run-aware
mbg Jul 14, 2026
a464bf1
Move `package.json` helpers into their own file
mbg Jul 14, 2026
ae48798
Make `versions.ts` testable and add basic tests
mbg Jul 14, 2026
41c7af7
Use `paginate`
mbg Jul 15, 2026
423e341
Delete python version
mbg Jul 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fetch commit info
  • Loading branch information
mbg committed Jul 14, 2026
commit c3da0a9ad35618d79e3a45187fd4fdfc85d5e16f
90 changes: 90 additions & 0 deletions pr-checks/update-release-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { execFileSync, type ExecFileSyncOptions } from "node:child_process";
import * as fs from "node:fs";
import { parseArgs } from "node:util";

import { type ApiClient, getApiClient } from "./api-client";
import { PACKAGE_JSON } from "./config";

/** Placeholder changelog content for a new release. */
Expand Down Expand Up @@ -99,6 +100,73 @@ export function getCurrentVersion(): string | undefined {
return pkg.version;
}

/** Represents commits returned by the GitHub API (relevant fields only). */
export interface GitHubCommit {
sha: string;
commit: { message: string; author: { date?: string } | null };
author: { login: string } | null;
committer: { login: string } | null;
parents: Array<{ sha: string }>;
}

/** Returns true if the commit is an automatic PR merge commit made by GitHub. */
export function isPrMergeCommit(commit: GitHubCommit): boolean {
return commit.committer?.login === "web-flow" && commit.parents.length > 1;
}

/**
* Gets a list of commits on the source branch that are not on the target branch,
* excluding automatic PR merge commits.
*
* Uses `git log` to find the SHAs, then fetches each commit from the GitHub API
* to obtain full metadata (author, parents, associated PRs, etc.).
*
* @param client - An authenticated GitHub API client.
* @param owner - The repository owner.
* @param repo - The repository name.
* @param sourceBranch - The source branch name (without `origin/` prefix).
* @param targetBranch - The target branch name (without `origin/` prefix).
* @returns The list of non-merge commits unique to the source branch.
*/
export async function getCommitDifference(
client: ApiClient,
owner: string,
repo: string,
sourceBranch: string,
targetBranch: string,
): Promise<GitHubCommit[]> {
const logOutput = runGit([
"log",
"--pretty=format:%H",
`${ORIGIN}/${targetBranch}..${ORIGIN}/${sourceBranch}`,
]);

// An empty log output means no commits to merge.
if (logOutput === "") {
return [];
}

const shas = logOutput.split("\n");

// Fetch full commit objects from the API.
console.info(
`Fetching information about ${shas.length} commits from the API...`,
);

const commits: GitHubCommit[] = [];
for (const sha of shas) {
const { data } = await client.rest.repos.getCommit({
owner,
repo,
ref: sha,
});
commits.push(data as GitHubCommit);
}

// Filter out automatic PR merge commits.
return commits.filter((c) => !isPrMergeCommit(c));
}

interface MainOptions {
repositoryNwo: string;
sourceBranch: string;
Expand Down Expand Up @@ -144,12 +212,18 @@ function parseCliOptions(): MainOptions {
async function main(): Promise<void> {
const options = parseCliOptions();
const token = getGitHubToken();
const client = getApiClient(token);
Comment thread
mbg marked this conversation as resolved.
Resolved

if (!options.targetBranch.startsWith(RELEASE_BRANCH_PREFIX)) {
throw new Error(
`Expected target branch to start with '${RELEASE_BRANCH_PREFIX}', but got '${options.targetBranch}'.`,
);
}
if (!options.repositoryNwo.includes("/")) {
throw new Error(
`Expected repository name with owner in 'owner/repo' format, but got '${options.repositoryNwo}'`,
);
}

const targetBranchMajorVersion = options.targetBranch.replace(
RELEASE_BRANCH_PREFIX,
Expand Down Expand Up @@ -178,6 +252,22 @@ async function main(): Promise<void> {
`Current head of ${options.sourceBranch} is ${sourceBranchShortSha}.`,
);

const [owner, repo] = options.repositoryNwo.split("/");
const commits = await getCommitDifference(
client,
owner,
repo,
options.sourceBranch,
options.targetBranch,
);

if (commits.length === 0) {
console.log(
`No commits to merge from ${options.sourceBranch} to ${options.targetBranch}.`,
);
return;
}

console.log(`Target version: ${version}`);
}

Expand Down