Skip to content

Commit

Permalink
feat: reconstruct-chromium-version command
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Feb 18, 2025
1 parent 5b80e17 commit 5323496
Show file tree
Hide file tree
Showing 4 changed files with 378 additions and 58 deletions.
7 changes: 6 additions & 1 deletion src/e
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,12 @@ program
'Opens a PR to electron/electron that backport the given CL into our patches folder',
)
.alias('auto-cherry-pick')
.command('gh-auth', 'Generates a device oauth token');
.command('gh-auth', 'Generates a device oauth token')
.command(
'rcv <roll-pr> [chromium-version]',
'Attempts to reconstruct an intermediate Chromium version from a roll PR',
)
.alias('reconstruct-chromium-version');

program
.command('load-macos-sdk')
Expand Down
57 changes: 0 additions & 57 deletions src/e-cherry-pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const path = require('path');
const os = require('os');
const { Octokit } = require('@octokit/rest');

const { getCveForBugNr } = require('./utils/crbug');
const { getGitHubAuthToken } = require('./utils/github-auth');
const { fatal, color } = require('./utils/logging');

Expand All @@ -17,14 +16,6 @@ const ELECTRON_REPO_DATA = {
repo: 'electron',
};

const gerritSources = [
'chromium-review.googlesource.com',
'skia-review.googlesource.com',
'webrtc-review.googlesource.com',
'pdfium-review.googlesource.com',
'dawn-review.googlesource.com',
];

async function getPatchDetailsFromURL(urlStr, security) {
const parsedUrl = new URL(urlStr);
if (parsedUrl.host.endsWith('.googlesource.com')) {
Expand All @@ -38,54 +29,6 @@ async function getPatchDetailsFromURL(urlStr, security) {
);
}

async function getGerritPatchDetailsFromURL(gerritUrl, security) {
const { host, pathname } = gerritUrl;

if (!gerritSources.includes(host)) {
fatal('Unsupported gerrit host');
}
const [, repo, number] = /^\/c\/(.+?)\/\+\/(\d+)/.exec(pathname);

d(`fetching patch from gerrit`);
const changeId = `${repo}~${number}`;
const patchUrl = new URL(
`/changes/${encodeURIComponent(changeId)}/revisions/current/patch`,
gerritUrl,
);

const patch = await fetch(patchUrl)
.then((resp) => resp.text())
.then((text) => Buffer.from(text, 'base64').toString('utf8'));

const [, commitId] = /^From ([0-9a-f]+)/.exec(patch);

const bugNumber =
/^(?:Bug|Fixed)[:=] ?(.+)$/im.exec(patch)?.[1] || /^Bug= ?chromium:(.+)$/m.exec(patch)?.[1];

let cve = '';
if (security) {
try {
cve = await getCveForBugNr(bugNumber.replace('chromium:', ''));
} catch (err) {
d(err);
console.error(
`${color.warn} Failed to fetch CVE for ${bugNumber} - you'll need to find it manually`,
);
}
}

const patchDirName =
{
'chromium-review.googlesource.com:chromium/src': 'chromium',
'skia-review.googlesource.com:skia': 'skia',
'webrtc-review.googlesource.com:src': 'webrtc',
}[`${host}:${repo}`] || repo.split('/').reverse()[0];

const shortCommit = commitId.substr(0, 12);

return { patchDirName, shortCommit, patch, bugNumber, cve };
}

async function getGitHubPatchDetailsFromURL(gitHubUrl, security) {
if (security) {
fatal('GitHub cherry-picks can not be security backports currently');
Expand Down
Loading

0 comments on commit 5323496

Please sign in to comment.