-
Notifications
You must be signed in to change notification settings - Fork 20
/
get-releases.mjs
62 lines (51 loc) · 1.44 KB
/
get-releases.mjs
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Octokit } from "@octokit/rest";
import AdmZip from "adm-zip";
import fs from "fs";
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const repoInfo = {
owner: "AppliedEnergistics",
repo: "Applied-Energistics-2",
};
const { data } = await octokit.rest.repos.listReleases({
...repoInfo,
per_page: 50,
});
// Find the latest release from main that has javadocs attached
const mainRelease = data.find((r) => {
return (
(r.target_commitish === "master" || r.target_commitish === "main") &&
r.assets.find((a) => a.name.endsWith("-javadoc.jar"))
);
});
if (!mainRelease) {
throw new Error("Couldn't find latest master/main release!)");
}
// Find the javadoc jar
const javadocJar = mainRelease.assets.find((a) =>
a.name.endsWith("-javadoc.jar")
);
if (!javadocJar) {
throw new Error("No javadoc asset found!");
}
const javadocJarAsset = await octokit.repos.getReleaseAsset({
...repoInfo,
asset_id: javadocJar.id,
headers: {
accept: "application/octet-stream",
},
});
console.log("Downloaded", javadocJar.name);
const zip = new AdmZip(Buffer.from(javadocJarAsset.data));
fs.mkdirSync("public/javadoc", { recursive: true });
zip.extractAllTo("public/javadoc/", true);
// Grab API.md from Repository.
const apiContent = await octokit.repos.getContent({
...repoInfo,
path: "API.md",
headers: {
accept: "application/vnd.github.v3.raw",
},
});
// fs.writeFileSync("content/api.md", apiContent.data);