Fix dependabot auto-merge #290
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: PR Labeler | |
| on: | |
| pull_request: | |
| types: [opened, synchronize] | |
| permissions: | |
| contents: read | |
| jobs: | |
| label-areas: | |
| name: Label PR by area | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Apply area labels | |
| uses: actions/labeler@v6 | |
| with: | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| configuration-path: .github/labeler.yml | |
| label-size: | |
| name: Label PR by size | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| steps: | |
| - name: Apply size label | |
| continue-on-error: true | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| retries: 3 | |
| retry-exempt-status-codes: 400,401,403,404,422 | |
| script: | | |
| // Note: Retry logic is handled by the built-in retries option above | |
| try { | |
| const { data: pullRequest } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.payload.pull_request.number, | |
| }); | |
| const changedFiles = pullRequest.changed_files; | |
| const sizeLabels = ['size/XS', 'size/S', 'size/M', 'size/L', 'size/XL']; | |
| let newLabel; | |
| if (changedFiles <= 10) { | |
| newLabel = 'size/XS'; | |
| } else if (changedFiles <= 50) { | |
| newLabel = 'size/S'; | |
| } else if (changedFiles <= 200) { | |
| newLabel = 'size/M'; | |
| } else if (changedFiles <= 500) { | |
| newLabel = 'size/L'; | |
| } else { | |
| newLabel = 'size/XL'; | |
| } | |
| // Get current labels on the PR | |
| const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| }); | |
| const currentLabelNames = currentLabels.map(label => label.name); | |
| // Remove any existing size labels that differ from the new one | |
| for (const sizeLabel of sizeLabels) { | |
| if (currentLabelNames.includes(sizeLabel) && sizeLabel !== newLabel) { | |
| await github.rest.issues.removeLabel({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| name: sizeLabel, | |
| }); | |
| } | |
| } | |
| // Add the new size label if not already present | |
| if (!currentLabelNames.includes(newLabel)) { | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.payload.pull_request.number, | |
| labels: [newLabel], | |
| }); | |
| } | |
| console.log(`PR has ${changedFiles} changed files, labeled as ${newLabel}`); | |
| } catch (error) { | |
| console.log(`Warning: Failed to apply size label: ${error.message}`); | |
| console.log('This is a non-critical failure and will not block the PR.'); | |
| } |