Add GitHub workflows for automatic PR labeling for needs-review and needs-changes #5
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
| name: Auto-label PR for review | |
| on: | |
| pull_request: | |
| types: [opened, edited, ready_for_review] | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| auto-label: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event_name == 'pull_request' && | |
| github.event.pull_request.draft == false && | |
| github.event.pull_request.user.login != 'red-hat-konflux' && | |
| !contains(github.event.pull_request.title, 'WIP') | |
| steps: | |
| - name: Add needs-review label | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| labels: ['needs-review'] | |
| }); | |
| manual-needs-review: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'issue_comment' && github.event.issue.pull_request | |
| steps: | |
| - name: Add needs-review label via comment | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const comment = context.payload.comment.body.toLowerCase(); | |
| if (comment.includes('needs-review') || comment.includes('/needs-review')) { | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.payload.issue.number; | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner, | |
| repo, | |
| issue_number, | |
| labels: ['needs-review'] | |
| }); | |
| console.log('Added needs-review label via comment'); | |
| } catch (error) { | |
| console.log('Error adding needs-review label:', error.message); | |
| } | |
| } |