diff --git a/README.md b/README.md index 6e23369..a75194d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,13 @@ jobs: # repositories: >- # ["actions/toolkit", "github/docs"] + # Optional. + # List of repository IDs that the token should have access to + # https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app + # https://docs.github.com/en/actions/learn-github-actions/contexts#github-context + # repository_ids: >- + # [${{github.repository_id}}] + # Optional. # revoke: false diff --git a/action.yml b/action.yml index 4146f35..e064de8 100644 --- a/action.yml +++ b/action.yml @@ -41,6 +41,11 @@ inputs: The JSON-stringified array of the full names of the repositories the token should have access to. Defaults to all repositories that the installation can access. See https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app's `repositories`. + repository_ids: + description: >- + The JSON-stringified array of the ids of the repositories the token should have access to. + Defaults to all repositories that the installation can access. + See https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#create-an-installation-access-token-for-an-app's `repository_ids`. revoke: description: Revoke the token at the end of the job. default: true diff --git a/src/create-installation-access-token.ts b/src/create-installation-access-token.ts index 2054fad..a536bd9 100644 --- a/src/create-installation-access-token.ts +++ b/src/create-installation-access-token.ts @@ -14,6 +14,7 @@ export type InstallationAccessTokenCreationOptions = Readonly<{ permissions?: Record; privateKey: string; repositories?: string[]; + repositoryIDs?: number[]; }>; export const createInstallationAccessToken = async ({ @@ -23,6 +24,7 @@ export const createInstallationAccessToken = async ({ permissions, privateKey, repositories, + repositoryIDs, }: InstallationAccessTokenCreationOptions): Promise => { try { const app = createAppAuth({ @@ -48,7 +50,12 @@ export const createInstallationAccessToken = async ({ data: { token }, } = await octokit.request( "POST /app/installations/{installation_id}/access_tokens", - { installation_id: installationId, permissions, repositories }, + { + installation_id: installationId, + permissions, + repositories, + repository_ids: repositoryIDs, + }, ); return token; } catch (error: unknown) { diff --git a/src/parse-options.ts b/src/parse-options.ts index 07d2efd..ebb8102 100644 --- a/src/parse-options.ts +++ b/src/parse-options.ts @@ -46,6 +46,12 @@ export const parseOptions = (): InstallationAccessTokenCreationOptions => { : undefined; debug(`Requested repositories: ${JSON.stringify(repositories)}.`); + const repositoryIDsInput = getInput("repository_ids"); + const repositoryIDs = repositoryIDsInput + ? (JSON.parse(repositoryIDsInput) as number[]) + : undefined; + debug(`Requested repository_ids: ${JSON.stringify(repositoryIDs)}.`); + return { appId, githubApiUrl, @@ -53,5 +59,6 @@ export const parseOptions = (): InstallationAccessTokenCreationOptions => { permissions, privateKey, repositories, + repositoryIDs, }; };