forked from openai/codex-security
-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (121 loc) · 4.58 KB
/
Copy pathnode-release-labels.yml
File metadata and controls
135 lines (121 loc) · 4.58 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: node-release-labels
on:
pull_request_target:
branches: [main]
types: [opened, edited, reopened]
permissions:
contents: read
concurrency:
group: node-release-labels-${{ github.event.pull_request.number }}
cancel-in-progress: false
jobs:
categorize:
if: github.repository == 'openai/codex-security'
name: categorize release notes
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: write
steps:
- name: Categorize pull request without checking out its code
shell: bash
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
set -euo pipefail
release_note_label() {
case "$1" in
feat:* | feat\(*\):* | feat!:* | feat\(*\)!:*)
printf '%s\n' enhancement
;;
fix:* | fix\(*\):* | fix!:* | fix\(*\)!:*)
printf '%s\n' bug
;;
docs:* | docs\(*\):* | docs!:* | docs\(*\)!:*)
printf '%s\n' documentation
;;
release:* | release\(*\):* | release!:* | release\(*\)!:* | test:* | test\(*\):* | test!:* | test\(*\)!:*)
printf '%s\n' skip-release-notes
;;
*)
return 0
;;
esac
}
current_title="$(
gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER" \
--jq '.title'
)"
label="$(release_note_label "$current_title")"
current_labels="$(
gh api "repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" \
--jq '.[].name'
)"
preserve_skip_label=false
while IFS= read -r current_label; do
if [[ "$current_label" == "skip-release-notes" ]]; then
skip_label_actors="$(
gh api \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/timeline?per_page=100" \
--paginate \
--jq '.[] | select(.event == "labeled" and .label.name == "skip-release-notes") | if (.actor.login // "") == "" then "__unattributed__" else .actor.login end'
)"
skip_label_actor=""
while IFS= read -r event_actor; do
skip_label_actor="$event_actor"
done <<< "$skip_label_actors"
if [[ "$skip_label_actor" != "github-actions[bot]" ]]; then
echo "Preserving existing skip-release-notes label."
preserve_skip_label=true
fi
break
fi
done <<< "$current_labels"
label_already_present=false
while IFS= read -r current_label; do
case "$current_label" in
enhancement | bug | documentation | skip-release-notes)
if [[ "$current_label" == "skip-release-notes" &&
"$preserve_skip_label" == true ]]; then
if [[ "$current_label" == "$label" ]]; then
label_already_present=true
fi
elif [[ "$current_label" != "$label" ]]; then
gh api --method DELETE \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/$current_label" \
--silent
else
label_already_present=true
fi
;;
esac
done <<< "$current_labels"
if [[ -z "$label" ]]; then
echo "No automatic release-note category applies."
exit 0
fi
if [[ "$label_already_present" == true ]]; then
echo "The current release-note category is already applied."
exit 0
fi
if [[ "$label" == "skip-release-notes" ]]; then
if ! gh api \
"repos/$GITHUB_REPOSITORY/labels/skip-release-notes" \
--silent >/dev/null 2>&1; then
if ! gh api --method POST "repos/$GITHUB_REPOSITORY/labels" \
-f name=skip-release-notes \
-f color=ededed \
-f description="Omit internal changes from generated release notes" \
--silent >/dev/null 2>&1; then
gh api \
"repos/$GITHUB_REPOSITORY/labels/skip-release-notes" \
--silent >/dev/null
fi
fi
fi
gh api --method POST \
"repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels" \
-f "labels[]=$label" \
--silent