Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 3, 2025

Problem

The "Add Files Changed Label" workflow was failing with a cryptic error when attempting to process GitHub API responses:

jq: error (at <stdin>:5): Cannot index string with string "name"
Error: Process completed with exit code 5.

This error occurred at the "Checking if label exists in repository..." step, even though the workflow successfully:

  • Identified the PR and fetched files changed information
  • Determined the correct label name and color

Root Cause

The workflow was attempting to extract label names from GitHub API responses without first validating that the response was actually an array. When the API returned an error object (e.g., due to permission issues, authentication failures, or other API errors), the workflow tried to use the array indexing operator .[].name on a non-array object:

ALL_REPO_LABELS=$(echo "$ALL_LABELS_RESPONSE" | jq -r '.[].name')

When $ALL_LABELS_RESPONSE contains an error like {"message": "Not Found"}, jq fails because it cannot iterate over a JSON object with array syntax.

Solution

Added proper type validation before processing API responses at two critical points in the workflow:

  1. Repository labels fetch (lines 87-93): Validates response before extracting repository label names
  2. PR labels fetch (lines 127-133): Validates response before extracting PR label names

The fix uses jq -e 'type == "array"' to check if the response is actually an array before attempting to extract names:

# Check if the API request was successful before processing
if echo "$ALL_LABELS_RESPONSE" | jq -e 'type == "array"' > /dev/null 2>&1; then
  ALL_REPO_LABELS=$(echo "$ALL_LABELS_RESPONSE" | jq -r '.[].name')
else
  echo "Error: Could not fetch repository labels. Response: $ALL_LABELS_RESPONSE"
  exit 1
fi

Benefits

  • Prevents cryptic errors: No more "Cannot index string with string 'name'" messages
  • Clear error messages: Displays the actual API response for easier debugging
  • Graceful degradation: Workflow exits cleanly instead of crashing with jq errors
  • Better troubleshooting: Full error response is logged to help identify root cause (permissions, authentication, etc.)
  • Minimal changes: Only 12 net lines added, no functional changes to successful execution paths
  • Backward compatible: No changes to workflow behavior when API calls succeed

Testing

Validated the fix with multiple scenarios:

  • ✅ Valid array responses (successful API calls)
  • ✅ Error object responses (API failures)
  • ✅ Permission errors
  • ✅ Empty arrays
  • ✅ Original error scenario now produces helpful error messages
Original prompt

fix add files changed label - Starting Files Changed Label workflow for PR #4570 in OWASP-BLT/BLT
Fetching files changed information...
Files changed in PR #4570: 3
Determined label: files-changed: 3 with color: fbca04
Checking if label exists in repository...
jq: error (at :5): Cannot index string with string "name"
Error: Process completed with exit code 5.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor

coderabbitai bot commented Oct 3, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@Copilot Copilot AI changed the title fix add files changed label - Starting Files Changed Label workflow for PR #4570 in OWASP-BLT/BLT Fetching files changed information... Files changed in PR #4570: 3 Determined label: files-changed: 3 with color: fbca04 Checking if label exists in repos... Fix jq error handling in add-files-changed-label workflow Oct 3, 2025
@Copilot Copilot AI requested a review from DonnieBLT October 3, 2025 15:13
Copilot finished work on behalf of DonnieBLT October 3, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants