From d653ab62bc42cc11ee36171e9b7413a86fb634a1 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Thu, 17 Oct 2024 14:05:37 -0700 Subject: [PATCH] refactor: use fetch in e-cherry-pick.js --- src/e-cherry-pick.js | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/src/e-cherry-pick.js b/src/e-cherry-pick.js index efcc0f32..5926ef8e 100644 --- a/src/e-cherry-pick.js +++ b/src/e-cherry-pick.js @@ -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'); @@ -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')) { @@ -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); @@ -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',