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

refactor: use fetch in e-cherry-pick.js #666

Merged
merged 1 commit into from
Oct 17, 2024
Merged
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
28 changes: 5 additions & 23 deletions src/e-cherry-pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

const d = require('debug')('build-tools:cherry-pick');
const program = require('commander');
const https = require('https');
const got = require('got');
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
Expand All @@ -27,24 +25,6 @@ const gerritSources = [
'dawn-review.googlesource.com',
];

function fetchBase64(url) {
return new Promise((resolve, reject) => {
https
.request(url, res => {
let data = '';
res.setEncoding('ascii');
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
resolve(Buffer.from(data, 'base64').toString('utf8'));
});
res.on('error', reject);
})
.end();
});
}

async function getPatchDetailsFromURL(urlStr, security) {
const parsedUrl = new URL(urlStr);
if (parsedUrl.host.endsWith('.googlesource.com')) {
Expand Down Expand Up @@ -73,7 +53,9 @@ async function getGerritPatchDetailsFromURL(gerritUrl, security) {
gerritUrl,
);

const patch = await fetchBase64(patchUrl.toString());
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);

Expand Down Expand Up @@ -118,9 +100,9 @@ async function getGitHubPatchDetailsFromURL(gitHubUrl, security) {
fatal('Could not find commit sha in url');
}

const response = await got.get(`https://github.com/nodejs/node/commit/${commitSha}.patch`);
const response = await fetch(`https://github.com/nodejs/node/commit/${commitSha}.patch`);
const shortCommit = commitSha.slice(0, 7);
const patch = response.body;
const patch = await response.text();

return {
patchDirName: 'node',
Expand Down