-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy pathmain.js
62 lines (53 loc) · 1.47 KB
/
main.js
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
// @ts-check
import core from "@actions/core";
import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
/**
* @param {string} appId
* @param {string} privateKey
* @param {string} repository
* @param {core} core
* @param {createAppAuth} createAppAuth
* @param {request} request
*/
export async function main(
appId,
privateKey,
repository,
core,
createAppAuth,
request
) {
// Get owner and repo name from GITHUB_REPOSITORY
const [owner, repo] = repository.split("/");
const auth = createAppAuth({
appId,
privateKey,
});
const appAuthentication = await auth({
type: "app",
});
// Get the installation ID
// https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app
const { data: installation } = await request(
"GET /repos/{owner}/{repo}/installation",
{
owner,
repo,
headers: {
authorization: `bearer ${appAuthentication.token}`,
},
}
);
// Create a new installation token
const authentication = await auth({
type: "installation",
installationId: installation.id,
repositoryNames: [repo],
});
// Register the token with the runner as a secret to ensure it is masked in logs
core.setSecret(authentication.token);
core.setOutput("token", authentication.token);
// Make token accessible to post function (so we can invalidate it)
core.saveState("token", authentication.token);
}