Skip to content

Commit 239445b

Browse files
feat(skip ci): add automatic-pr-labeler workflow to auto-label PRs based on changed files (#20)
1 parent 0e62e79 commit 239445b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
3+
# The workflow template for automatic PR labeler.
4+
# It requires to have a configuration file with labels and conditions to apply them.
5+
# The configuration file should be placed in the .github folder and named auto-labeler-config.yaml.
6+
# Example file can be found there:
7+
# https://github.com/Netcracker/.github/blob/main/config/examples/auto-labeler-config.yaml
8+
9+
name: Automatic PR Labeler
10+
11+
on:
12+
pull_request:
13+
branches: [main]
14+
types:
15+
[opened, reopened, synchronize]
16+
17+
permissions:
18+
contents: read
19+
20+
jobs:
21+
assign-labels:
22+
if: (github.event.pull_request.merged == false) && (github.event.pull_request.user.login != 'dependabot[bot]') && (github.event.pull_request.user.login != 'github-actions[bot]')
23+
permissions:
24+
pull-requests: write
25+
contents: read
26+
issues: write
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
30+
with:
31+
persist-credentials: false
32+
33+
- name: "Execute assign labels"
34+
id: action-assign-labels
35+
uses: mauroalderete/action-assign-labels@671a4ca2da0f900464c58b8b5540a1e07133e915 # v1.5.1
36+
with:
37+
pull-request-number: ${{ github.event.pull_request.number }}
38+
github-token: ${{ github.token }}
39+
conventional-commits: "./.github/auto-labeler-config.yaml"
40+
maintain-labels-not-matched: true
41+
apply-changes: ${{ github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id }}
42+
43+
- name: Set labels-next safely
44+
if: ${{ github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id }}
45+
run: |
46+
echo "LABELS_NEXT=$(echo ${STEPS_ACTION_ASSIGN_LABELS_OUTPUTS_LABELS_NEXT} | tr -dc 'a-zA-Z0-9-,')" >> $GITHUB_ENV
47+
env:
48+
STEPS_ACTION_ASSIGN_LABELS_OUTPUTS_LABELS_NEXT: ${{ steps.action-assign-labels.outputs.labels-next }}
49+
- name: "Drop warning if PR from fork"
50+
if: ${{ github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id }}
51+
run: |
52+
{
53+
echo "⚠️ Pull request from fork! ⚠️";
54+
echo "Labels will not be applied to PR. Assign them manually please.";
55+
echo "Labels to assign: '${LABELS_NEXT}'";
56+
} >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)