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

Feat add input repository ids 2 #2

Merged
merged 5 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/create-installation-access-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type InstallationAccessTokenCreationOptions = Readonly<{
permissions?: Record<string, string>;
privateKey: string;
repositories?: string[];
repositoryIDs?: number[];
}>;

export const createInstallationAccessToken = async ({
Expand All @@ -23,6 +24,7 @@ export const createInstallationAccessToken = async ({
permissions,
privateKey,
repositories,
repositoryIDs,
}: InstallationAccessTokenCreationOptions): Promise<string> => {
try {
const app = createAppAuth({
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/parse-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ 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,
installationRetrievalDetails,
permissions,
privateKey,
repositories,
repositoryIDs,
};
};