outcomment #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
| name: Provide approval for bot PRs | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| labels: | ||
| description: List of labels in JSON format, i.e. '["trivial", "documentation"]', to indicate that a PR should be approved. When a pull request contains at least one of those labels, the PR will be approved. | ||
| type: string | ||
| default: '["trivial"]' | ||
| jobs: | ||
| approve_pr: | ||
| name: Approve PR for matching label | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'pull_request' | ||
| steps: | ||
| - name: Approve PR for matching label | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const owner = context.payload.repository.full_name.split('/')[0]; | ||
| const repo = context.payload.repository.full_name.split('/')[1]; | ||
| const reviews = await github.rest.pulls.listReviews({ | ||
| owner: owner, | ||
| repo: repo, | ||
| pull_number: context.payload.number, | ||
| }).data; | ||
| console.log("Reviews: " + JSON.stringify(reviews)); | ||
| # for (const review of reviews) { | ||
| # if (review.user.login === github.actor && review.state === 'APPROVED') { | ||
| # console.log("PR already approved by " + github.actor); | ||
| # return; | ||
| # } | ||
| # } | ||
| const pull = (await github.rest.pulls.get({ | ||
| owner: owner, | ||
| repo: repo, | ||
| pull_number: context.payload.number, | ||
| })).data; | ||
| const labels = JSON.parse('${{ inputs.labels }}'); | ||
| let found = false; | ||
| for (const prLabel of pull.labels) { | ||
| if (labels.includes(prLabel.name)) { | ||
| console.log("Found a matching label '" + prLabel.name + "', will approve PR"); | ||
| await github.rest.pulls.createReview({ | ||
| owner: owner, | ||
| repo: repo, | ||
| pull_number: pull.number, | ||
| event: 'APPROVE' | ||
| }); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!found) { | ||
| console.log("No matching label found, will not approve PR"); | ||
| } | ||