Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit 85a4385

Browse files
Saviqtibdex
andauthored
Add support for remote repository (#11)
Co-authored-by: Thibault Derousseaux <[email protected]>
1 parent d196e95 commit 85a4385

File tree

6 files changed

+143
-217
lines changed

6 files changed

+143
-217
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
with:
2020
app_id: ${{ secrets.APP_ID }}
2121
private_key: ${{ secrets.PRIVATE_KEY }}
22+
# Optional (defaults to the current repository).
23+
# repository: owner/repo
2224
- name: Use token
2325
env:
2426
TOKEN: ${{ steps.generate_token.outputs.token }}

action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ inputs:
88
private_key:
99
description: Private key of the GitHub App (can be Base64 encoded).
1010
required: true
11+
repository:
12+
description: The full name of the repository for which the token will be requested (defaults to the current repository).
1113
outputs:
1214
token:
13-
description: An installation token for the GitHub App on the current repository.
15+
description: An installation token for the GitHub App on the requested repository.
1416
runs:
1517
using: node12
1618
main: dist/index.js

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "github-app-token",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"license": "MIT",
55
"files": [
66
"action.yml",
@@ -19,23 +19,22 @@
1919
"@actions/github": "^4.0.0",
2020
"@octokit/auth-app": "^2.10.5",
2121
"@types/is-base64": "^1.1.0",
22-
"@types/jest": "^26.0.18",
23-
"@types/node": "^14.14.11",
24-
"@typescript-eslint/eslint-plugin": "^4.9.1",
25-
"@typescript-eslint/parser": "^4.9.1",
26-
"@vercel/ncc": "^0.25.1",
27-
"eslint": "^7.15.0",
28-
"eslint-config-prettier": "^7.0.0",
22+
"@types/node": "^14.14.14",
23+
"@typescript-eslint/eslint-plugin": "^4.10.0",
24+
"@typescript-eslint/parser": "^4.10.0",
25+
"@vercel/ncc": "^0.26.1",
26+
"eslint": "^7.16.0",
27+
"eslint-config-prettier": "^7.1.0",
2928
"eslint-config-xo": "^0.33.1",
30-
"eslint-config-xo-typescript": "^0.36.0",
29+
"eslint-config-xo-typescript": "^0.37.0",
3130
"eslint-import-resolver-typescript": "^2.3.0",
3231
"eslint-plugin-import": "^2.22.1",
3332
"eslint-plugin-sort-destructure-keys": "^1.3.5",
3433
"eslint-plugin-typescript-sort-keys": "^1.5.0",
35-
"eslint-plugin-unicorn": "^23.0.0",
34+
"eslint-plugin-unicorn": "^24.0.0",
3635
"is-base64": "^1.1.0",
3736
"prettier": "^2.2.1",
3837
"promise-retry": "^2.0.1",
39-
"typescript": "^4.1.2"
38+
"typescript": "^4.1.3"
4039
}
4140
}

src/fetch-installation-token.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ import { createAppAuth } from "@octokit/auth-app";
33

44
export const fetchInstallationToken = async ({
55
appId,
6+
owner,
67
privateKey,
7-
}: Readonly<{ appId: string; privateKey: string }>): Promise<string> => {
8+
repo,
9+
}: Readonly<{
10+
appId: string;
11+
owner: string;
12+
privateKey: string;
13+
repo: string;
14+
}>): Promise<string> => {
815
const app = createAppAuth({ appId, privateKey });
916
const authApp = await app({ type: "app" });
1017
const octokit = getOctokit(authApp.token);
1118
const {
1219
data: { id: installationId },
13-
} = await octokit.apps.getRepoInstallation(context.repo);
20+
} = await octokit.apps.getRepoInstallation({ owner, repo });
1421
const installation = await app({ installationId, type: "installation" });
1522
return installation.token;
1623
};

src/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getInput, info, setFailed, setOutput, setSecret } from "@actions/core";
2+
import { context } from "@actions/github";
23

34
import isBase64 from "is-base64";
45

@@ -12,9 +13,16 @@ const run = async () => {
1213
? Buffer.from(privateKeyInput, "base64").toString("utf8")
1314
: privateKeyInput;
1415

16+
const repositoryInput = getInput("repository");
17+
const [owner, repo] = repositoryInput
18+
? repositoryInput.split("/")
19+
: [context.repo.owner, context.repo.repo];
20+
1521
const installationToken = await fetchInstallationToken({
1622
appId,
23+
owner,
1724
privateKey,
25+
repo,
1826
});
1927

2028
setSecret(installationToken);

0 commit comments

Comments
 (0)