|
6 | 6 | # For more info visit https://github.com/pulp/plugin_template
|
7 | 7 |
|
8 | 8 | ---
|
9 |
| -name: Python PR static checks |
| 9 | +name: "Python PR static checks" |
10 | 10 | on:
|
11 | 11 | pull_request_target:
|
12 |
| - types: [opened, synchronize, reopened] |
| 12 | + types: ["opened", "synchronize", "reopened"] |
13 | 13 |
|
14 | 14 | # This workflow runs with elevated permissions.
|
15 | 15 | # Do not even think about running a single bit of code from the PR.
|
16 | 16 | # Static analysis should be fine however.
|
17 | 17 |
|
18 | 18 | concurrency:
|
19 |
| - group: ${{ github.event.pull_request.number }}-${{ github.workflow }} |
| 19 | + group: "${{ github.event.pull_request.number }}-${{ github.workflow }}" |
20 | 20 | cancel-in-progress: true
|
21 | 21 |
|
22 | 22 | jobs:
|
23 |
| - single_commit: |
24 |
| - runs-on: ubuntu-latest |
25 |
| - name: Label multiple commit PR |
| 23 | + apply_labels: |
| 24 | + runs-on: "ubuntu-latest" |
| 25 | + name: "Label PR" |
26 | 26 | permissions:
|
27 |
| - pull-requests: write |
| 27 | + pull-requests: "write" |
28 | 28 | steps:
|
29 | 29 | - uses: "actions/checkout@v4"
|
30 | 30 | with:
|
31 | 31 | fetch-depth: 0
|
32 |
| - - name: Commit Count Check |
| 32 | + - uses: "actions/setup-python@v5" |
| 33 | + with: |
| 34 | + python-version: "3.11" |
| 35 | + - name: "Determine PR labels" |
33 | 36 | run: |
|
| 37 | + pip install GitPython==3.1.42 |
34 | 38 | git fetch origin ${{ github.event.pull_request.head.sha }}
|
35 |
| - echo "COMMIT_COUNT=$(git log --oneline --no-merges origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} | wc -l)" >> "$GITHUB_ENV" |
36 |
| - - uses: actions/github-script@v7 |
| 39 | + python .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV" |
| 40 | + - uses: "actions/github-script@v7" |
| 41 | + name: "Apply PR Labels" |
37 | 42 | with:
|
38 | 43 | script: |
|
39 |
| - const labelName = "multi-commit"; |
40 |
| - const { COMMIT_COUNT } = process.env; |
| 44 | + const { ADD_LABELS, REMOVE_LABELS } = process.env; |
41 | 45 |
|
42 |
| - if (COMMIT_COUNT == 1) |
43 |
| - { |
44 |
| - try { |
45 |
| - await github.rest.issues.removeLabel({ |
46 |
| - issue_number: context.issue.number, |
47 |
| - owner: context.repo.owner, |
48 |
| - repo: context.repo.repo, |
49 |
| - name: labelName, |
50 |
| - }); |
51 |
| - } catch(err) { |
| 46 | + if (REMOVE_LABELS.length) { |
| 47 | + for await (const labelName of REMOVE_LABELS.split(",")) { |
| 48 | + try { |
| 49 | + await github.rest.issues.removeLabel({ |
| 50 | + issue_number: context.issue.number, |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + name: labelName, |
| 54 | + }); |
| 55 | + } catch(err) { |
| 56 | + } |
52 | 57 | }
|
53 | 58 | }
|
54 |
| - else |
55 |
| - { |
| 59 | + if (ADD_LABELS.length) { |
56 | 60 | await github.rest.issues.addLabels({
|
57 | 61 | issue_number: context.issue.number,
|
58 | 62 | owner: context.repo.owner,
|
59 | 63 | repo: context.repo.repo,
|
60 |
| - labels: [labelName], |
| 64 | + labels: ADD_LABELS.split(","), |
61 | 65 | });
|
62 | 66 | }
|
| 67 | +... |
0 commit comments