Skip to content

Commit 22db619

Browse files
Add github_api_url input defaulting to env.GITHUB_API_URL (#43)
1 parent 8905248 commit 22db619

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

action.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ inputs:
1414
description: The full name of the repository for which the token will be requested (defaults to the current repository).
1515
permissions:
1616
description: The JSON-stringified permissions granted to the token (defaults to all the GitHub app permissions, see https://docs.github.com/en/rest/apps/apps#create-an-installation-access-token-for-an-app).
17+
github_api_url:
18+
description: The API URL of the GitHub server, such as https://api.github.com. Defaults to the environment variable GITHUB_API_URL, see https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
1719
outputs:
1820
token:
1921
description: An installation token for the GitHub App on the requested repository.

src/fetch-installation-token.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { env } from "node:process";
21
import { getOctokit } from "@actions/github";
32
import { createAppAuth } from "@octokit/auth-app";
43
import { request } from "@octokit/request";
54
import ensureError from "ensure-error";
65

76
export const fetchInstallationToken = async ({
87
appId,
8+
baseUrl,
99
installationId,
1010
owner,
1111
permissions,
1212
privateKey,
1313
repo,
1414
}: Readonly<{
1515
appId: string;
16+
baseUrl: URL;
1617
installationId?: number;
1718
owner: string;
1819
permissions?: Record<string, string>;
@@ -23,9 +24,7 @@ export const fetchInstallationToken = async ({
2324
appId,
2425
privateKey,
2526
request: request.defaults({
26-
// GITHUB_API_URL is part of GitHub Actions' built-in environment variables.
27-
// See https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
28-
baseUrl: env.GITHUB_API_URL,
27+
baseUrl: baseUrl.toString().replace(/\/+$/, ''),
2928
}),
3029
});
3130

src/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Buffer } from "node:buffer";
2+
import { env } from "node:process";
23
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
34
import { context } from "@actions/github";
45
import ensureError from "ensure-error";
@@ -29,8 +30,16 @@ const run = async () => {
2930
? repositoryInput.split("/")
3031
: [context.repo.owner, context.repo.repo];
3132

33+
// GITHUB_API_URL is part of GitHub Actions' built-in environment variables.
34+
// See https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
35+
const githubUrlInput = getInput("github_api_url");
36+
const baseUrl = githubUrlInput
37+
? new URL(githubUrlInput)
38+
: new URL(env.GITHUB_API_URL!);
39+
3240
const installationToken = await fetchInstallationToken({
3341
appId,
42+
baseUrl,
3443
installationId,
3544
owner,
3645
permissions,

0 commit comments

Comments
 (0)