-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for organization and user installation retrieval and repo…
…sitory scoping (#84)
- Loading branch information
Showing
15 changed files
with
302 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getOctokit } from "@actions/github"; | ||
import { createAppAuth } from "@octokit/auth-app"; | ||
import { request } from "@octokit/request"; | ||
|
||
import { | ||
InstallationRetrievalDetails, | ||
retrieveInstallationId, | ||
} from "./installation-retrieval.js"; | ||
|
||
export type InstallationAccessTokenCreationOptions = Readonly<{ | ||
appId: string; | ||
githubApiUrl: URL; | ||
installationRetrievalDetails: InstallationRetrievalDetails; | ||
permissions?: Record<string, string>; | ||
privateKey: string; | ||
repositories?: string[]; | ||
}>; | ||
|
||
export const createInstallationAccessToken = async ({ | ||
appId, | ||
githubApiUrl, | ||
installationRetrievalDetails, | ||
permissions, | ||
privateKey, | ||
repositories, | ||
}: InstallationAccessTokenCreationOptions): Promise<string> => { | ||
try { | ||
const app = createAppAuth({ | ||
appId, | ||
privateKey, | ||
request: request.defaults({ | ||
baseUrl: githubApiUrl | ||
.toString() | ||
// Remove optional trailing `/`. | ||
.replace(/\/$/, ""), | ||
}), | ||
}); | ||
|
||
const authApp = await app({ type: "app" }); | ||
const octokit = getOctokit(authApp.token); | ||
|
||
const installationId = await retrieveInstallationId( | ||
installationRetrievalDetails, | ||
{ octokit }, | ||
); | ||
|
||
const { | ||
data: { token }, | ||
} = await octokit.request( | ||
"POST /app/installations/{installation_id}/access_tokens", | ||
{ installation_id: installationId, permissions, repositories }, | ||
); | ||
return token; | ||
} catch (error: unknown) { | ||
throw new Error("Could not create installation access token.", { | ||
cause: error, | ||
}); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.