|
| 1 | +name: PR Tagger |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize] |
| 6 | + |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + tag-pr: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Add tags based on changed files |
| 15 | + uses: actions/github-script@v6 |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const tag_map = { |
| 19 | + 'src/torchjd/_autogram/': 'package: autogram', |
| 20 | + 'src/torchjd/_autojac/': 'package: autojac', |
| 21 | + 'src/torchjd/aggregation/': 'package: aggregation', |
| 22 | + '.github/workflows/': 'CI', |
| 23 | + 'docs/': 'docs', |
| 24 | + 'tests/': 'test' |
| 25 | + }; |
| 26 | +
|
| 27 | + const tags_to_add = new Set(); |
| 28 | +
|
| 29 | + const files = await github.rest.pulls.listFiles({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + pull_number: context.issue.number, |
| 33 | + }); |
| 34 | +
|
| 35 | + for (const file of files.data) { |
| 36 | + for (const package_dir in tag_map) { |
| 37 | + if (file.filename.startsWith(package_dir)) { |
| 38 | + tags_to_add.add(tag_map[package_dir]); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +
|
| 43 | + if (tags_to_add.size > 0) { |
| 44 | + await github.rest.issues.addLabels({ |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + issue_number: context.issue.number, |
| 48 | + labels: Array.from(tags_to_add) |
| 49 | + }); |
| 50 | + console.log(`Added tags: ${Array.from(tags_to_add).join(', ')}`); |
| 51 | + } else { |
| 52 | + console.log('No relevant files changed, no tags added.'); |
| 53 | + } |
0 commit comments