|
1 | 1 | name: "Labelling new pull requests" |
| 2 | + |
| 3 | +permissions: |
| 4 | + contents: read |
| 5 | + |
2 | 6 | on: |
3 | | - workflow_run: |
4 | | - workflows: ["PR Receive"] |
| 7 | + # It's safe to use pull_request_target here, because we aren't checking out |
| 8 | + # code from the pull request branch. |
| 9 | + # See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
| 10 | + pull_request_target: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - reopened |
| 14 | + - ready_for_review |
| 15 | + - synchronize |
5 | 16 |
|
6 | 17 | jobs: |
7 | 18 | automate-prs-labels: |
8 | 19 | permissions: |
9 | | - contents: read |
10 | 20 | pull-requests: write |
11 | 21 | runs-on: ubuntu-latest |
| 22 | + # Ignore PRs with more than 10 commits. Pull requests with a lot of |
| 23 | + # commits tend to be accidents usually when someone made a mistake while trying |
| 24 | + # to rebase. We want to ignore these pull requests to avoid excessive |
| 25 | + # notifications. |
12 | 26 | if: > |
13 | 27 | github.repository == 'llvm/llvm-project' && |
14 | | - github.event.workflow_run.event == 'pull_request_target' && |
15 | | - github.event.workflow_run.conclusion == 'success' |
| 28 | + github.event.pull_request.draft == false && |
| 29 | + github.event.pull_request.commits < 10 |
16 | 30 | steps: |
17 | | - # From: https://securitylab.github.com/research/github-actions-preventing-pwn-requests/ |
18 | | - # Updated version here: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow |
19 | | - - name: Debug |
20 | | - run: | |
21 | | - echo "Event: ${{ github.event.workflow_run.event }} Conclusion: ${{ github.event.workflow_run.conclusion }}" |
22 | | - - name: 'Download artifact' |
23 | | - uses: actions/github-script@v6 |
24 | | - with: |
25 | | - script: | |
26 | | - const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
27 | | - owner: context.repo.owner, |
28 | | - repo: context.repo.repo, |
29 | | - run_id: context.payload.workflow_run.id |
30 | | - }); |
31 | | - const matchArtifact = artifacts.data.artifacts.find((artifact) => |
32 | | - artifact.name === 'pr' |
33 | | - ); |
34 | | - const download = await github.rest.actions.downloadArtifact({ |
35 | | - owner: context.repo.owner, |
36 | | - repo: context.repo.repo, |
37 | | - artifact_id: matchArtifact.id, |
38 | | - archive_format: 'zip' |
39 | | - }); |
40 | | - const { writeFileSync } = require('node:fs'); |
41 | | - writeFileSync('${{ github.workspace }}/pr.zip', Buffer.from(download.data)); |
42 | | -
|
43 | | - - run: unzip pr.zip |
44 | | - |
45 | | - - name: "Get PR Number" |
46 | | - id: vars |
47 | | - run: |
48 | | - echo "pr-number=$(cat NR)" >> "$GITHUB_OUTPUT" |
49 | | - |
50 | 31 | - uses: actions/labeler@v4 |
51 | 32 | with: |
52 | 33 | configuration-path: .github/new-prs-labeler.yml |
53 | 34 | # workaround for https://github.com/actions/labeler/issues/112 |
54 | 35 | sync-labels: '' |
55 | 36 | repo-token: ${{ secrets.ISSUE_SUBSCRIBER_TOKEN }} |
56 | | - pr-number: ${{ steps.vars.outputs.pr-number }} |
0 commit comments