Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github_url input defaulting to GITHUB_API_URL #43

Merged
merged 3 commits into from Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Expand Up @@ -14,6 +14,8 @@ inputs:
description: The full name of the repository for which the token will be requested (defaults to the current repository).
permissions:
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).
github_url:
cliffchapmanrbx marked this conversation as resolved.
Show resolved Hide resolved
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding default: ${{ github.api_url }}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other inputs aren't written that way so I was sticking with the same pattern. I'm open to using this if the repo maintainer would prefer it.

outputs:
token:
description: An installation token for the GitHub App on the requested repository.
Expand Down
7 changes: 3 additions & 4 deletions src/fetch-installation-token.ts
@@ -1,4 +1,3 @@
import { env } from "node:process";
import { getOctokit } from "@actions/github";
import { createAppAuth } from "@octokit/auth-app";
import { request } from "@octokit/request";
Expand All @@ -11,21 +10,21 @@ export const fetchInstallationToken = async ({
permissions,
privateKey,
repo,
baseUrl,
}: Readonly<{
appId: string;
installationId?: number;
owner: string;
permissions?: Record<string, string>;
privateKey: string;
repo: string;
baseUrl: URL;
}>): Promise<string> => {
const app = createAppAuth({
appId,
privateKey,
request: request.defaults({
// GITHUB_API_URL is part of GitHub Actions' built-in environment variables.
// See https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
baseUrl: env.GITHUB_API_URL,
baseUrl: baseUrl.toString(),
}),
});

Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
@@ -1,4 +1,5 @@
import { Buffer } from "node:buffer";
import { env } from "node:process";
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
import { context } from "@actions/github";
import ensureError from "ensure-error";
Expand Down Expand Up @@ -29,13 +30,21 @@ const run = async () => {
? repositoryInput.split("/")
: [context.repo.owner, context.repo.repo];

// GITHUB_API_URL is part of GitHub Actions' built-in environment variables.
// See https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables.
const githubUrlInput = getInput("github_url");
const baseUrl = githubUrlInput
? new URL(githubUrlInput)
: new URL(env.GITHUB_API_URL);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is unnecessary if you have a default set to ${{ github.api_url }}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same deal, mostly duplicating the existing pattern in the code instead of introducing a new one. I'm also open to changing it around if the maintainer would prefer.


const installationToken = await fetchInstallationToken({
appId,
installationId,
owner,
permissions,
privateKey,
repo,
baseUrl
});

setSecret(installationToken);
Expand Down