Skip to content

Commit 7818333

Browse files
authored
Replace hardcoded label list with kind/* label convention (#5)
* Replace hardcoded label list with kind/* label convention Aligns the PR label checker with the convention used across other Hyperlight projects, which require exactly one kind/* prefixed label instead of matching against a brittle hardcoded list. This ensures consistency across the organization and removes the need to manually update allowed labels when new categories are added. Fixes #4 Signed-off-by: James Sturtevant <jsturtevant@gmail.com> * Update issue label checker to use lifecycle/* label convention Aligns the issue label checker with the convention used across other Hyperlight projects by using lifecycle/* prefixed labels instead of plain 'needs review'. Ensures exactly one lifecycle label is applied, replacing any extras with lifecycle/needs-review. Signed-off-by: James Sturtevant <jsturtevant@gmail.com> --------- Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent b1baee1 commit 7818333

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

.github/workflows/IssueLabelChecker.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,22 @@ jobs:
1414
- uses: actions/checkout@v6
1515
- name: Check and Add label
1616
run: |
17-
LABELS=$(gh issue view ${{ github.event.issue.number }} --json labels -q '.labels[].name')
18-
if [[ $LABELS != *"needs review"* ]]; then
19-
gh issue edit ${{ github.event.issue.number }} --add-label "needs review"
17+
# The cryptic head -c -1 is because otherwise gh always terminates output with a newline
18+
readarray -d $'\0' lifecycles < <(gh issue view ${{ github.event.issue.number }} --json labels -q '[.labels[] | .name | select(startswith("lifecycle/"))] | join("\u0000")' | head -c -1)
19+
if [[ ${#lifecycles[@]} -ne 1 ]]; then
20+
if [[ ${#lifecycles[@]} -ge 1 ]]; then
21+
echo 'Too many lifecycle labels; replacing all with `lifecycle/needs-review`'
22+
fi
23+
commands=()
24+
for label in "${lifecycles[@]}"; do
25+
if [[ "$label" != "lifecycle/needs-review" ]]; then
26+
echo "Removing label ${label}"
27+
commands+=("--remove-label" "${label}")
28+
fi
29+
done
30+
echo 'Adding `lifecycle/needs-review`'
31+
commands+=("--add-label" "lifecycle/needs-review")
32+
gh issue edit ${{ github.event.issue.number }} "${commands[@]}"
2033
fi
2134
env:
2235
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/PRLabelChecker.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v6
15-
- name: Check for specific labels
15+
- name: Ensure exactly one "kind/*" label is applied
1616
run: |
17-
PR_NUMBER=$(echo ${{ github.event.pull_request.number }})
18-
LABELS_JSON=$(gh pr view $PR_NUMBER --json labels -q '.labels.[] | .name')
19-
REQUIRED_LABELS=("chore" "ignore" "breaking-change" "enhancement" "feature" "dependencies" "bug" "security" "performance" "refactor" "testing" "documentation" "github-actions")
20-
for REQUIRED_LABEL in "${REQUIRED_LABELS[@]}"; do
21-
if echo "$LABELS_JSON" | grep -q "$REQUIRED_LABEL"; then
22-
echo "One of the required labels is present"
23-
exit 0
24-
fi
25-
done
26-
echo "None of the required labels are present"
27-
exit 1
17+
# Count the number of "kind/*" labels directly from the PR labels
18+
PR_NUMBER=${{ github.event.pull_request.number }}
19+
KIND_LABEL_COUNT=$(gh pr view "$PR_NUMBER" --json labels -q '.labels.[].name' | grep -c '^kind/')
20+
21+
if [[ "$KIND_LABEL_COUNT" -eq 1 ]]; then
22+
echo "✅ Exactly one 'kind/*' label is applied."
23+
exit 0
24+
else
25+
echo "❌ PR must have exactly one 'kind/*' label, but found $KIND_LABEL_COUNT."
26+
exit 1
27+
fi
2828
env:
2929
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)