I'm trying to do a simple thing: label a pull request (later objective is automerging, but bear with me here). Here's what I've tried
- using github-script simply does not work. It does not give write access to a pull request
- I remembered that if you used
curl
instead of the API, it would work. I tried this:
name: "Etiquetador de pull request"
on:
pull_request:
paths:
- 'objetivos/*'
jobs:
Etiquetador:
runs-on: ubuntu-latest
steps:
- name: Etiqueta el PR con "objetivos"
env:
REPO: ${{ github.repository }}
run: |
PR_NUMBER=$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')
echo "https://api.github.com/repos/${OWNER}/${REPO}/issues/${PR_NUMBER}/labels"
curl -X PUT -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${REPO}/issues/${PR_NUMBER}/labels \
-d '{"labels":["objetivos"]}'
It does not work either, with the result:
{
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/reference/issues#set-labels-for-an-issue"
}
As an alternative, I tried to create a personal access token. However, there does not seem to be a scope for this kind of thing (there's not really a way to authorize specifically to write labels or pull-request related info).
Alternatively, you can create a GitHub app. It seems overkill for simply labeling a PR, though.
Scheduled actions could be run to perform this kind of things. Of course, bad comes to worse, that could be an alternative. However, it misses context information, and it would need to run over all PRs to perform the action.
Apps already in the marketplace, like this one, do not actually label based on file paths, which what I am looking for.
Any other idea here? Thanks!
Have you tried using a dedicated
actions/labeler
?