actions / create-github-app-token

GitHub Action for creating a GitHub App Installation Access Token
https://github.com/marketplace/actions/create-github-app-token
MIT License
321 stars 46 forks source link

Handle `repositories` input with spaces between repositories #106

Open niodice opened 4 months ago

niodice commented 4 months ago

This action could handle a little more flexibility in the repositories input. A common mistake is to provide repositories: foo, bar instead of repositories: foo,bar if a token is needed for > 1 repository.

For example:

      - name: Generate Github Actions App token
        id: generate-token
        uses: actions/create-github-app-token@v1
        with:
          app-id: ${{ env.GH_APP_APP_ID }}
          private-key: ${{ env.GH_APP_PRIVATE_KEY }}
          repositories: foo, bar

Fails to get a token because the body in the HTTP request to GH will look like this:

  body: '{"repositories":["foo"," bar"]}',

I think trimming the repos, something like repos = repos.map(r => r.trim()), would catch this and make for a more intuitive API

gr2m commented 4 months ago

Yes, we should definitely do that. Pull request welcome! Please add a test or update one of the existing ones 🙏

krokofant commented 1 month ago

Should trailing commas be trimmed as well? Seems these lines needs to be changed https://github.com/actions/create-github-app-token/blob/c8f55efbd427e7465d6da1106e7979bc8aaee856/lib/main.js#L147 https://github.com/actions/create-github-app-token/blob/c8f55efbd427e7465d6da1106e7979bc8aaee856/lib/main.js#L157

For just spaces

'a, b,c , d'.split(/\s*,\s*/)

With trailing commas:

'a, b,c , d,'.replace(/,\s*$/,'').split(/\s*,\s*/)