Skip to content

Commit 47d2a55

Browse files
Replace fetch with node:htts
1 parent b0bd936 commit 47d2a55

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/utils/filesystem.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as fs from "node:fs";
22
import type { Config } from "../types/config";
33
import { info } from "@actions/core";
4+
import { get } from "node:https";
45

56
export const cwd = (): string => {
67
const path = process.env.GITHUB_WORKSPACE;
@@ -19,15 +20,31 @@ export const fileExists = (config: Config, filename: string): boolean =>
1920
fs.existsSync(filePath(config, filename));
2021

2122
export const readRemoteFile = async (url: string): Promise<string> => {
22-
const response: Response = await fetch(url);
23+
return new Promise((resolve) => {
24+
get(url, (res) => {
25+
if (res.statusCode !== 200) {
26+
info(
27+
`Failed to fetch ${url} with status code ${res.statusCode}`,
28+
);
29+
resolve("");
2330

24-
if (!response.ok) {
25-
info(`Failed to fetch ${url} with status code ${response.status}`);
31+
return;
32+
}
2633

27-
return "";
28-
}
34+
let data = "";
35+
36+
res.on("data", (chunk) => {
37+
data += chunk;
38+
});
2939

30-
return response.text();
40+
res.on("end", () => {
41+
resolve(data);
42+
});
43+
}).on("error", (err) => {
44+
info(`Failed to fetch ${url} with error: ${err.message}`);
45+
resolve("");
46+
});
47+
});
3148
};
3249

3350
export const readFile = (config: Config, filename: string): string => {

0 commit comments

Comments
 (0)