How to use the github-actions bot

I’ve created a couple of GitHub actions that add labels to an issue and assign it to a user. But, after the action executes the issue reflects that user-a has added labels a and b. This is probably because I’m using user-as API token to authorise the adding of theses labels.

I’m looking for a way to authorise the github-actions[bot] to perform these operations so that users would know that they were triggered by automation.

Any help / links are appreciated. Thanks!

The GitHub Actions bot already has the permissions you want by default. Simply call the GitHub API using the token that is generated by GitHub Actions in the GITHUB_TOKEN secret. For example:

jobs:
  assign:
    runs-on: ubuntu-latest

steps:
      - name: Assign user
        env:
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: |
          curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -X POST -d '{"assignees": ["oldskool"]}' \
          https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/assignees

Will result in the github-actions bot assigning me to the PR that triggered this workflow:

2 Likes

Thanks so much @oldskool 

I had generated an API token and was using that to authenticate the Github API.
I was not aware of the default API token available already!