-
Notifications
You must be signed in to change notification settings - Fork 88
feat: support tokens scoped to multiple repositories within organization #46
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
Changes from 9 commits
12bf248
9c2fe6b
4e0d015
151c72e
84c746a
98d3657
63a98a7
8f5a382
a12bbe4
fb1cbf7
c21d2ca
6d39deb
90239ca
3cfbd0e
e8a138f
7c7676d
4b133dc
68894b6
02c936f
73f98bd
91b880c
80484a9
aa7595e
2df34b8
13b24f0
9dcf16e
dad2c36
0a057cb
7c0311c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,21 +3,23 @@ | |
/** | ||
* @param {string} appId | ||
* @param {string} privateKey | ||
* @param {string} repository | ||
* @param {string} org | ||
* @param {string} repositories | ||
* @param {import("@actions/core")} core | ||
* @param {import("@octokit/auth-app").createAppAuth} createAppAuth | ||
* @param {import("@octokit/request").request} request | ||
*/ | ||
export async function main( | ||
appId, | ||
privateKey, | ||
repository, | ||
org, | ||
repositories, | ||
core, | ||
createAppAuth, | ||
request | ||
) { | ||
// Get owner and repo name from GITHUB_REPOSITORY | ||
const [owner, repo] = repository.split("/"); | ||
|
||
const repos = repositories.split(",").map((repo) => repo.trim()); | ||
|
||
const auth = createAppAuth({ | ||
appId, | ||
|
@@ -32,23 +34,31 @@ export async function main( | |
// Get the installation ID | ||
// https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-a-repository-installation-for-the-authenticated-app | ||
const { data: installation } = await request( | ||
"GET /repos/{owner}/{repo}/installation", | ||
"GET /orgs/{org}/installation", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we need to get the installation ID for the current owner, we should keep doing it using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my suggested change at timreimherr#1 |
||
{ | ||
owner, | ||
repo, | ||
org, | ||
headers: { | ||
authorization: `bearer ${appAuthentication.token}`, | ||
}, | ||
} | ||
); | ||
|
||
// Create a new installation token | ||
const authentication = await auth({ | ||
type: "installation", | ||
installationId: installation.id, | ||
repositoryNames: [repo], | ||
}); | ||
let authentication; | ||
|
||
if (repositories.length == 0) { | ||
authentication = await auth({ | ||
type: "installation", | ||
installationId: installation.id, | ||
}); | ||
} else { | ||
authentication = await auth({ | ||
type: "installation", | ||
installationId: installation.id, | ||
repositoryNames: repos, | ||
}); | ||
} | ||
|
||
// Register the token with the runner as a secret to ensure it is masked in logs | ||
core.setSecret(authentication.token); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.