-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_mac.ts
More file actions
30 lines (24 loc) · 836 Bytes
/
fetch_mac.ts
File metadata and controls
30 lines (24 loc) · 836 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Octokit } from "octokit";
const token = Deno.env.get("GITHUB_AUTH_TOKEN");
if (!token) {
console.error("GITHUB_AUTH_TOKEN environment variable is not set.");
Deno.exit(1);
}
const octokit = new Octokit({ auth: token });
try {
const response = await octokit.rest.repos.getContent({
owner: "ablunier",
repo: "manfred",
path: "CV/MAC.json",
});
if (!("content" in response.data)) {
throw new Error("Unexpected response: missing content field.");
}
const bytes = Uint8Array.from(atob(response.data.content), (c) => c.charCodeAt(0));
const json = JSON.parse(new TextDecoder().decode(bytes));
await Deno.writeTextFile("./_data/mac.json", JSON.stringify(json, null, 2));
console.log("MAC has been fetched and saved successfully.");
} catch (error) {
console.error(error);
Deno.exit(1);
}