Repository navigation
Remove audit and fuzz cron jobs #1163
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 | ||
|
Check warning on line 1 in .github/workflows/pr-labeler.yml
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
| jobs: | ||
| label-pr: | ||
| runs-on: ubuntu-slim | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Label PR based on changed files | ||
| uses: actions/github-script@v6 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const changedFiles = await github.paginate( | ||
| github.rest.pulls.listFiles, | ||
| { | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| pull_number: context.issue.number, | ||
| } | ||
| ); | ||
| // Paths of all the managed labels | ||
| const filePathsToLabels = { | ||
| 'bitcoind/': 'C-bitcoind', | ||
| 'bitreq/': 'C-bitreq', | ||
| 'client/': 'C-client', | ||
| 'electrsd/': 'C-electrsd', | ||
| 'integration_test/': 'C-integration-test', | ||
| 'jsonrpc/': 'C-jsonrpc', | ||
| 'types/': 'C-types', | ||
| 'verify/': 'C-verify', | ||
| }; | ||
| const labelsToAdd = new Set(); | ||
| changedFiles.forEach(file => { | ||
| const filePath = file.filename; | ||
| for (const [path, label] of Object.entries(filePathsToLabels)) { | ||
| if (filePath.startsWith(path)) { | ||
| labelsToAdd.add(label); | ||
| break; | ||
| } | ||
| } | ||
| }); | ||
| const allKnownLabels = new Set(Object.values(filePathsToLabels)); | ||
| // Add new managed labels. | ||
| if (labelsToAdd.size > 0) { | ||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| labels: Array.from(labelsToAdd) | ||
| }); | ||
| } | ||
| // Remove any managed labels that no longer apply. | ||
| const currentLabels = (await github.rest.issues.listLabelsOnIssue({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| })).data.map(label => label.name); | ||
| for (const label of currentLabels) { | ||
| if (allKnownLabels.has(label) && !labelsToAdd.has(label)) { | ||
| try { | ||
| await github.rest.issues.removeLabel({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| name: label, | ||
| }); | ||
| } catch (e) { | ||
| // Ignore 404 in case the label was already removed externally. | ||
| if (e.status !== 404) throw e; | ||
| } | ||
| } | ||
| } | ||