-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathmain.ts
More file actions
57 lines (52 loc) · 1.4 KB
/
main.ts
File metadata and controls
57 lines (52 loc) · 1.4 KB
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
import { Octokit } from "octokit";
import { createAppAuth } from "@octokit/auth-app";
import * as fs from "fs";
export const getOctokit = async (
appId: string,
privateKey: string,
orgName: string
): Promise<Octokit> => {
const appOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId,
privateKey,
},
});
const installations = await appOctokit.request("GET /app/installations");
for (const d of installations.data) {
//@ts-ignore
if (d.account.login === orgName) {
const installationId = d.id;
const installationOctokit = new Octokit({
authStrategy: createAppAuth,
auth: {
appId,
privateKey,
installationId,
},
});
return installationOctokit;
}
}
throw new Error(`No installation found for organization ${orgName}`);
};
const ghAppId = process.env.GITHUB_APP_ID;
const ghAppPkFile = process.env.GITHUB_APP_PK_FILE;
const ghOrg = process.env.GITHUB_ORG;
(async () => {
if (!ghAppId || !ghAppPkFile || !ghOrg) {
throw new Error(
"Environment variables GITHUB_APP_ID, GITHUB_APP_PK_FILE, and GITHUB_ORG must be passed to this program."
);
}
const octokit = await getOctokit(
ghAppId,
fs.readFileSync(ghAppPkFile, "utf8"),
ghOrg
);
const repos = await octokit.request("GET /orgs/{org}/repos", {
org: ghOrg,
});
console.log(repos.data);
})();