Bump github.com/mikefarah/yq/v4 from 4.44.3 to 4.46.1 in /hack/internal/tools #374
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: PR Labeler | |
| on: | |
| pull_request: | |
| types: [opened, edited] | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| label-pr: | |
| if: | | |
| (github.event_name == 'pull_request' && | |
| (github.event.action == 'opened' || github.event.action == 'edited')) || | |
| (github.event_name == 'issue_comment' && | |
| github.event.issue.pull_request && | |
| github.event.comment.user.login != 'github-actions[bot]') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Parse /kind commands | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const kindMap = { | |
| 'bug': 'bug', | |
| 'cleanup': 'cleanup', | |
| 'documentation': 'documentation', | |
| 'feature': 'feature', | |
| 'design': 'design' | |
| }; | |
| let body = ''; | |
| let prNumber = 0; | |
| if (context.eventName === 'pull_request') { | |
| body = context.payload.pull_request.body || ''; | |
| prNumber = context.payload.pull_request.number; | |
| } else if (context.eventName === 'issue_comment') { | |
| body = context.payload.comment.body || ''; | |
| prNumber = context.payload.issue.number; | |
| } | |
| // Find all /kind commands in the body | |
| const kindRegex = /\/kind\s+(\w+)/g; | |
| const matches = [...body.matchAll(kindRegex)]; | |
| if (matches.length === 0) { | |
| console.log('No /kind commands found'); | |
| return; | |
| } | |
| // Get current labels | |
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber | |
| }); | |
| const currentLabelNames = currentLabels.map(label => label.name); | |
| const labelsToAdd = []; | |
| const labelsToRemove = []; | |
| // Remove all existing kind labels | |
| for (const label of currentLabelNames) { | |
| if (Object.values(kindMap).includes(label)) { | |
| labelsToRemove.push(label); | |
| } | |
| } | |
| // Add new kind labels | |
| for (const match of matches) { | |
| const kindType = match[1].toLowerCase(); | |
| if (kindMap[kindType]) { | |
| labelsToAdd.push(kindMap[kindType]); | |
| } | |
| } | |
| // Remove old kind labels | |
| for (const label of labelsToRemove) { | |
| if (!labelsToAdd.includes(label)) { | |
| try { | |
| await github.rest.issues.removeLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| name: label | |
| }); | |
| console.log(`Removed label: ${label}`); | |
| } catch (error) { | |
| console.log(`Failed to remove label ${label}: ${error.message}`); | |
| } | |
| } | |
| } | |
| // Add new labels | |
| if (labelsToAdd.length > 0) { | |
| try { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| labels: labelsToAdd | |
| }); | |
| console.log(`Added labels: ${labelsToAdd.join(', ')}`); | |
| } catch (error) { | |
| console.log(`Failed to add labels: ${error.message}`); | |
| } | |
| } | |
| // Post a comment if this was triggered by a comment | |
| if (context.eventName === 'issue_comment' && labelsToAdd.length > 0) { | |
| const comment = `✅ Applied labels: ${labelsToAdd.map(l => `\`${l}\``).join(', ')}`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: prNumber, | |
| body: comment | |
| }); | |
| } |