Skip to content

Commit da40f50

Browse files
authored
Upgrade deps and cleanup (#51)
1 parent fba8a67 commit da40f50

File tree

7 files changed

+307
-397
lines changed

7 files changed

+307
-397
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install
1414
run: yarn install --frozen-lockfile
1515
- name: Deduplicate dependencies
16-
run: yarn run yarn-deduplicate --fail
16+
run: yarn run yarn-deduplicate --fail --strategy fewer
1717
- name: Build
1818
run: yarn run build
1919
- name: Format

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ jobs:
2424
with:
2525
app_id: ${{ secrets.APP_ID }}
2626

27-
# Optional (defaults to ID of the repository's installation).
27+
# Optional.
28+
# github_api_url: https://api.example.com
29+
30+
# Optional.
2831
# installation_id: 1337
2932

30-
# Optional (defaults to all the Github App permissions).
33+
# Optional.
3134
# Using a YAML multiline string to avoid escaping the JSON quotes.
3235
# permissions: >-
3336
# {"members": "read"}
3437

3538
private_key: ${{ secrets.PRIVATE_KEY }}
3639

37-
# Optional (defaults to the current repository).
38-
# repository: "owner/repo"
40+
# Optional.
41+
# repository: owner/repo
3942

4043
- name: Use token
4144
env:

action.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ inputs:
55
app_id:
66
description: ID of the GitHub App.
77
required: true
8-
private_key:
9-
description: Private key of the GitHub App (can be Base64 encoded).
10-
required: true
118
installation_id:
129
description: The ID of the installation for which the token will be requested (defaults to the ID of the repository's installation).
13-
repository:
14-
description: The full name of the repository for which the token will be requested (defaults to the current repository).
10+
github_api_url:
11+
description: The API URL of the GitHub server.
12+
default: ${{ github.api_url }}
1513
permissions:
1614
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.
15+
private_key:
16+
description: Private key of the GitHub App (can be Base64 encoded).
17+
required: true
18+
repository:
19+
description: The full name of the repository for which the token will be requested.
20+
default: ${{ github.repository }}
1921
outputs:
2022
token:
2123
description: An installation token for the GitHub App on the requested repository.

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-app-token",
3-
"version": "1.6.0",
3+
"version": "1.7.0",
44
"license": "MIT",
55
"type": "module",
66
"files": [
@@ -15,9 +15,9 @@
1515
},
1616
"dependencies": {
1717
"@actions/core": "^1.10.0",
18-
"@actions/github": "^5.0.3",
19-
"@octokit/auth-app": "^4.0.4",
20-
"@octokit/request": "^6.0.2",
18+
"@actions/github": "^5.1.1",
19+
"@octokit/auth-app": "^4.0.7",
20+
"@octokit/request": "^6.2.2",
2121
"ensure-error": "^4.0.0",
2222
"is-base64": "^1.1.0"
2323
},
@@ -30,10 +30,10 @@
3030
"eslint-plugin-import": "^2.26.0",
3131
"eslint-plugin-sort-destructure-keys": "^1.4.0",
3232
"eslint-plugin-typescript-sort-keys": "^2.1.0",
33-
"prettier": "^2.6.2",
34-
"prettier-plugin-packagejson": "^2.2.18",
35-
"typescript": "^4.7.4",
36-
"xo": "^0.50.0",
33+
"prettier": "^2.7.1",
34+
"prettier-plugin-packagejson": "^2.3.0",
35+
"typescript": "^4.8.4",
36+
"xo": "^0.52.4",
3737
"yarn-deduplicate": "^5.0.0"
3838
}
3939
}

src/fetch-installation-token.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import ensureError from "ensure-error";
55

66
export const fetchInstallationToken = async ({
77
appId,
8-
baseUrl,
8+
githubApiUrl,
99
installationId,
1010
owner,
1111
permissions,
1212
privateKey,
1313
repo,
1414
}: Readonly<{
1515
appId: string;
16-
baseUrl: URL;
16+
githubApiUrl: URL;
1717
installationId?: number;
1818
owner: string;
1919
permissions?: Record<string, string>;
@@ -24,12 +24,16 @@ export const fetchInstallationToken = async ({
2424
appId,
2525
privateKey,
2626
request: request.defaults({
27-
baseUrl: baseUrl.toString().replace(/\/+$/, ''),
27+
baseUrl: githubApiUrl
28+
.toString()
29+
// Remove optional trailing `/`.
30+
.replace(/\/$/, ""),
2831
}),
2932
});
3033

3134
const authApp = await app({ type: "app" });
3235
const octokit = getOctokit(authApp.token);
36+
3337
if (installationId === undefined) {
3438
try {
3539
({
@@ -49,7 +53,7 @@ export const fetchInstallationToken = async ({
4953
installation_id: installationId,
5054
permissions,
5155
});
52-
return installation?.token;
56+
return installation.token;
5357
} catch (error: unknown) {
5458
throw new Error("Could not create installation access token.", {
5559
cause: ensureError(error),

src/index.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Buffer } from "node:buffer";
2-
import { env } from "node:process";
32
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
4-
import { context } from "@actions/github";
53
import ensureError from "ensure-error";
64
import isBase64 from "is-base64";
75
import { fetchInstallationToken } from "./fetch-installation-token.js";
@@ -25,21 +23,15 @@ const run = async () => {
2523
? Buffer.from(privateKeyInput, "base64").toString("utf8")
2624
: privateKeyInput;
2725

28-
const repositoryInput = getInput("repository");
29-
const [owner, repo] = repositoryInput
30-
? repositoryInput.split("/")
31-
: [context.repo.owner, context.repo.repo];
26+
const repositoryInput = getInput("repository", { required: true });
27+
const [owner, repo] = repositoryInput.split("/");
3228

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!);
29+
const githubApiUrlInput = getInput("github_api_url", { required: true });
30+
const githubApiUrl = new URL(githubApiUrlInput);
3931

4032
const installationToken = await fetchInstallationToken({
4133
appId,
42-
baseUrl,
34+
githubApiUrl,
4335
installationId,
4436
owner,
4537
permissions,

0 commit comments

Comments
 (0)