-
Notifications
You must be signed in to change notification settings - Fork 12
fix(#479): add create-on-missing fallback for ready-for-review label #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
89083e8
feat(#479): add labels.lib.sh with forge_ensure_label for mandatory l…
maruiz93 c0bce03
fix(#479): ensure ready-for-review label exists before applying in po…
maruiz93 0afc80e
fix(#479): ensure ready-to-code label exists before applying in post-…
maruiz93 7e2bb53
fix(#479): remove --force from ready-for-triage creation in post-retro
maruiz93 207896f
fix(#479): fix shellcheck SC2188 in labels-test.sh
maruiz93 3d31c5c
fix(#479): sanitize gh stderr in label error handlers
maruiz93 b2d17f7
fix(#479): align labels.lib.sh naming with repo conventions
maruiz93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #!/usr/bin/env bash | ||
| # labels-test.sh — Tests for scripts/lib/labels.lib.sh | ||
| # | ||
| # Run from the repo root: | ||
| # bash scripts/labels-test.sh | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [[ "${SCRIPT_TEST_TARGET:-source}" == "bundled" ]]; then | ||
| echo "SKIP: labels-test (lib tests skipped in bundled mode)" | ||
| exit 0 | ||
| fi | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| FAILURES=0 | ||
|
|
||
| # --- Test helpers --- | ||
|
|
||
| GH_CALLS_FILE=$(mktemp) | ||
| export GH_CALLS_FILE | ||
| trap 'rm -f "${GH_CALLS_FILE}"' EXIT | ||
|
|
||
| setup_test() { | ||
| true > "${GH_CALLS_FILE}" | ||
| export GH_EXIT_CODE=0 | ||
| export GH_STDERR="" | ||
| export REPO_FULL_NAME="test-org/test-repo" | ||
| unset REPO 2>/dev/null || true | ||
| } | ||
|
|
||
| get_gh_call() { | ||
| local index="${1:-0}" | ||
| sed -n "$((index + 1))p" "${GH_CALLS_FILE}" | ||
| } | ||
|
|
||
| get_gh_call_count() { | ||
| wc -l < "${GH_CALLS_FILE}" | tr -d ' ' | ||
| } | ||
|
|
||
| # Stub gh that records calls and returns configured exit/stderr. | ||
| gh() { | ||
| echo "$*" >> "${GH_CALLS_FILE}" | ||
| if [[ ${GH_EXIT_CODE} -ne 0 ]]; then | ||
| echo "${GH_STDERR}" >&2 | ||
| return ${GH_EXIT_CODE} | ||
| fi | ||
| } | ||
| export -f gh 2>/dev/null || true | ||
|
|
||
| run_test() { | ||
| local test_name="$1" | ||
| local expected_pattern="$2" | ||
| local actual="$3" | ||
|
|
||
| if [[ "${actual}" == *"${expected_pattern}"* ]] || [[ "${expected_pattern}" == "${actual}" ]]; then | ||
| echo "PASS: ${test_name}" | ||
| else | ||
| echo "FAIL: ${test_name}" | ||
| echo " expected pattern: '${expected_pattern}'" | ||
| echo " actual: '${actual}'" | ||
| FAILURES=$((FAILURES + 1)) | ||
| fi | ||
| } | ||
|
|
||
| # Source the lib under test (after defining gh stub). | ||
| # shellcheck source=lib/labels.lib.sh | ||
| source "${SCRIPT_DIR}/lib/labels.lib.sh" | ||
|
|
||
| # --- Tests --- | ||
|
|
||
| # Test 1: Mandatory label emits gh label create with correct args. | ||
| setup_test | ||
| forge_ensure_label "ready-for-review" | ||
| run_test "mandatory-label-creates" \ | ||
| "label create ready-for-review --repo test-org/test-repo" \ | ||
| "$(get_gh_call 0)" | ||
|
|
||
| # Test 2: Non-mandatory label is a no-op. | ||
| setup_test | ||
| forge_ensure_label "question" | ||
| run_test "non-mandatory-is-noop" \ | ||
| "0" \ | ||
| "$(get_gh_call_count)" | ||
|
|
||
| # Test 3: "already exists" error produces no warning. | ||
| setup_test | ||
| GH_EXIT_CODE=1 | ||
| GH_STDERR='label with name "ready-for-review" already exists; use `--force` to update' | ||
| stderr_output=$(forge_ensure_label "ready-for-review" 2>&1 >/dev/null) | ||
| run_test "already-exists-silent" \ | ||
| "" \ | ||
| "${stderr_output}" | ||
|
|
||
| # Test 4: Other errors produce a warning. | ||
| setup_test | ||
| GH_EXIT_CODE=1 | ||
| GH_STDERR="HTTP 403: Resource not accessible by integration" | ||
| stderr_output=$(forge_ensure_label "ready-for-review" 2>&1 >/dev/null) | ||
| run_test "other-error-warns" \ | ||
| "Warning:" \ | ||
| "${stderr_output}" | ||
|
|
||
| # Test 5: Defaults are applied when no description/color provided. | ||
| setup_test | ||
| forge_ensure_label "ready-to-code" | ||
| run_test "defaults-applied-description" \ | ||
| "--description" \ | ||
| "$(get_gh_call 0)" | ||
| run_test "defaults-applied-color" \ | ||
| "--color" \ | ||
| "$(get_gh_call 0)" | ||
|
|
||
| # Test 6: Explicit description/color overrides defaults. | ||
| setup_test | ||
| forge_ensure_label "ready-for-review" "Custom desc" "FF0000" | ||
| run_test "explicit-overrides-default" \ | ||
| "--description Custom desc --color FF0000" \ | ||
| "$(get_gh_call 0)" | ||
|
|
||
| # Test 7: Uses REPO when REPO_FULL_NAME is unset. | ||
| setup_test | ||
| unset REPO_FULL_NAME | ||
| export REPO="triage-org/triage-repo" | ||
| forge_ensure_label "ready-for-triage" | ||
| run_test "falls-back-to-REPO" \ | ||
| "--repo triage-org/triage-repo" \ | ||
| "$(get_gh_call 0)" | ||
|
|
||
| # Test 8: No --force flag in the gh call. | ||
| setup_test | ||
| forge_ensure_label "ready-for-review" | ||
| gh_call=$(get_gh_call 0) | ||
| if [[ "${gh_call}" == *"--force"* ]]; then | ||
| echo "FAIL: no-force-flag" | ||
| echo " gh call contains --force: '${gh_call}'" | ||
| FAILURES=$((FAILURES + 1)) | ||
| else | ||
| echo "PASS: no-force-flag" | ||
| fi | ||
|
|
||
| echo "" | ||
| if [ ${FAILURES} -gt 0 ]; then | ||
| echo "${FAILURES} test(s) failed" | ||
| exit 1 | ||
| fi | ||
| echo "All tests passed" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env bash | ||
| # labels.lib.sh — Mandatory label management for fullsend agent scripts. | ||
| # | ||
| # Provides forge_ensure_label() which creates mandatory dispatch labels | ||
| # without --force, preserving admin customizations. Non-mandatory labels | ||
| # are silently skipped (no-op). | ||
|
|
||
| # shellcheck shell=bash | ||
|
|
||
| [[ -n "${LABELS_SH_LOADED:-}" ]] && return 0 | ||
| LABELS_SH_LOADED=1 | ||
|
|
||
| MANDATORY_LABELS=("ready-for-review" "ready-to-code" "ready-for-triage") | ||
|
|
||
| _labels_mandatory_defaults() { | ||
| printf '%s\t%s\t%s\n' \ | ||
| "ready-for-review" "Triggers review agent dispatch" "0E8A16" \ | ||
| "ready-to-code" "Triggers code agent dispatch" "0E8A16" \ | ||
| "ready-for-triage" "Triggers triage agent dispatch" "0E8A16" | ||
| } | ||
|
|
||
| forge_ensure_label() { | ||
| local name="$1" | ||
| local description="${2:-}" | ||
| local color="${3:-}" | ||
|
|
||
| local is_mandatory=false | ||
| local m | ||
| for m in "${MANDATORY_LABELS[@]}"; do | ||
| [[ "${m}" == "${name}" ]] && is_mandatory=true && break | ||
| done | ||
| if [[ "${is_mandatory}" != "true" ]]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| if [[ -z "${description}" || -z "${color}" ]]; then | ||
| local line | ||
| line=$(_labels_mandatory_defaults | grep "^${name} " || true) | ||
| if [[ -n "${line}" ]]; then | ||
| [[ -z "${description}" ]] && description=$(printf '%s' "${line}" | cut -f2) | ||
| [[ -z "${color}" ]] && color=$(printf '%s' "${line}" | cut -f3) | ||
| fi | ||
| fi | ||
|
|
||
| local create_args=("${name}" --repo "${REPO_FULL_NAME:-${REPO}}") | ||
| [[ -n "${description}" ]] && create_args+=(--description "${description}") | ||
| [[ -n "${color}" ]] && create_args+=(--color "${color}") | ||
|
|
||
| local err | ||
| if ! err=$(gh label create "${create_args[@]}" 2>&1); then | ||
| case "${err}" in | ||
| *already\ exists*) ;; | ||
|
maruiz93 marked this conversation as resolved.
maruiz93 marked this conversation as resolved.
|
||
| *) | ||
| err="${err//$'\n'/ }" | ||
| err="${err//::/:}" | ||
| err="${err//%0A/}" | ||
| err="${err//%0a/}" | ||
| err="${err//%0D/}" | ||
| err="${err//%0d/}" | ||
| echo "Warning: gh label create ${name}: ${err}" >&2 | ||
| ;; | ||
| esac | ||
| fi | ||
|
maruiz93 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.