diff --git a/.github/actions/get-token/action.yml b/.github/actions/get-token/action.yml index 51b0a3f0..ce46af03 100644 --- a/.github/actions/get-token/action.yml +++ b/.github/actions/get-token/action.yml @@ -9,7 +9,7 @@ inputs: description: 'The permissions to request for the access token, in the format of "scope: permission", separated by newlines.' required: true target-repository: - description: 'The repository to target for the access token. Defaults to the current repository.' + description: 'The repositories to target for the access token, separated by commas or newlines. Defaults to the current repository.' required: false default: '${{ github.repository }}' @@ -60,6 +60,19 @@ runs: .map(line => line.split(':').map(part => part.trim())) ); + const targetRepositories = [ + ...new Set( + TARGET_REPOSITORY + .split(/[\n,]/) + .map(repo => repo.trim()) + .filter(Boolean) + ), + ]; + + if (targetRepositories.length === 0) { + return core.setFailed('"target-repository" must include at least one repository.'); + } + const response = await fetch(`${TOKEN_EXCHANGE_URL}/api/exchange/token`, { method: 'POST', headers: { @@ -67,7 +80,7 @@ runs: }, body: JSON.stringify({ oidcToken: OIDC_TOKEN, - targetRepo: TARGET_REPOSITORY, + targetRepo: targetRepositories, requested_permissions: requestedPermissions, }), }); diff --git a/CHANGELOG.md b/CHANGELOG.md index 4186e02b..bdf3a437 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Support multiple comma- or newline-separated repositories in the `get-token` action's `target-repository` input ([#354](https://github.com/MetaMask/github-tools/pull/354)) + ## [1.29.0] ### Added