-
-
Notifications
You must be signed in to change notification settings - Fork 15
83 lines (72 loc) · 2.7 KB
/
Copy pathlabeler.yml
File metadata and controls
83 lines (72 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: "Issue and Pull Request Labeler"
on:
issues:
types: [opened]
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
issues: write
pull-requests: write
jobs:
labeler:
if: github.event_name == 'pull_request_target'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Label PR
uses: actions/labeler@v5
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
sync-labels: true
classify:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Classify issue or pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number || github.event.pull_request.number }}
TITLE: ${{ github.event.issue.title || github.event.pull_request.title }}
BODY: ${{ github.event.issue.body || github.event.pull_request.body }}
shell: bash
run: |
set -euo pipefail
text="$(printf '%s\n%s' "$TITLE" "$BODY" | tr '[:upper:]' '[:lower:]')"
labels=()
matches() {
[[ "$text" =~ $1 ]]
}
if matches '(^|[^[:alnum:]])(bug|broken|crash|error|fail|failure|regression)([^[:alnum:]]|$)'; then
labels+=("bug")
elif matches '(^|[^[:alnum:]])(question|how do|how to|why)([^[:alnum:]]|$)'; then
labels+=("question")
elif matches '(^|[^[:alnum:]])(docs|documentation|readme)([^[:alnum:]]|$)'; then
labels+=("documentation")
elif matches '(^|[^[:alnum:]])(add|feature|enhancement|improve|support)([^[:alnum:]]|$)'; then
labels+=("enhancement")
fi
if matches '(^|[^[:alnum:]])(app|audio|dictation|hotkey|menu bar|microphone|swift|transcription|whisper)([^[:alnum:]]|$)'; then
labels+=("app")
fi
if matches '(^|[^[:alnum:]])(homepage|site|vocamac.com|web|website)([^[:alnum:]]|$)'; then
labels+=("web")
fi
if matches '(^|[^[:alnum:]])(docs|documentation|readme|release notes)([^[:alnum:]]|$)'; then
labels+=("docs")
fi
if matches '(^|[^[:alnum:]])(action|build|ci|release|test|workflow)([^[:alnum:]]|$)'; then
labels+=("ci")
fi
if [ "${#labels[@]}" -eq 0 ]; then
exit 0
fi
mapfile -t labels < <(printf '%s\n' "${labels[@]}" | sort -u)
fields=()
for label in "${labels[@]}"; do
fields+=(-f "labels[]=$label")
done
gh api "repos/$REPO/issues/$NUMBER/labels" --method POST "${fields[@]}"