Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reconstruct-chromium-version command #697

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
58 changes: 1 addition & 57 deletions src/e-cherry-pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const path = require('path');
const os = require('os');
const { Octokit } = require('@octokit/rest');

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

Expand All @@ -17,14 +17,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 +30,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