-
Notifications
You must be signed in to change notification settings - Fork 61
Fix: Resolve syntax error in workflow and improve label checker error handling #4739
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||
| import os | ||||||||||||||||||||
| import requests | ||||||||||||||||||||
| import sys | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Get all existing labels in the repository | ||||||||||||||||||||
| labels = [] | ||||||||||||||||||||
|
|
@@ -11,22 +12,48 @@ | |||||||||||||||||||
| else: | ||||||||||||||||||||
| exit(0) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Get affected component | ||||||||||||||||||||
| i = os.environ["ISSUE_BODY"].index("### Affected Component") | ||||||||||||||||||||
| j = os.environ["ISSUE_BODY"].index("### Version") | ||||||||||||||||||||
| component = os.environ["ISSUE_BODY"][i+23:j].strip() | ||||||||||||||||||||
| component_label = "Component/" + component | ||||||||||||||||||||
| if component_label in all_existing_labels: | ||||||||||||||||||||
| labels.append(component_label) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Get component version | ||||||||||||||||||||
| version = os.environ["ISSUE_BODY"][j+13:j+18].strip() | ||||||||||||||||||||
| affected_label = "Affected/" + component + "-" + version | ||||||||||||||||||||
| if affected_label in all_existing_labels: | ||||||||||||||||||||
| labels.append(affected_label) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Return verified labels | ||||||||||||||||||||
| if len(labels) > 0: | ||||||||||||||||||||
| print(",".join(labels)) | ||||||||||||||||||||
| else: | ||||||||||||||||||||
| try: | ||||||||||||||||||||
| # Check if ISSUE_BODY environment variable exists | ||||||||||||||||||||
| issue_body = os.environ.get("ISSUE_BODY", "") | ||||||||||||||||||||
| if not issue_body: | ||||||||||||||||||||
| print("Missing/Component") | ||||||||||||||||||||
| sys.exit(0) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Get affected component | ||||||||||||||||||||
| if "### Affected Component" not in issue_body or "### Version" not in issue_body: | ||||||||||||||||||||
| print("Missing/Component") | ||||||||||||||||||||
| sys.exit(0) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| i = issue_body.index("### Affected Component") | ||||||||||||||||||||
| j = issue_body.index("### Version") | ||||||||||||||||||||
| component = issue_body[i+25:j].strip() | ||||||||||||||||||||
|
Comment on lines
+27
to
+29
|
||||||||||||||||||||
| i = issue_body.index("### Affected Component") | |
| j = issue_body.index("### Version") | |
| component = issue_body[i+25:j].strip() | |
| affected_header = "### Affected Component" | |
| i = issue_body.index(affected_header) | |
| j = issue_body.index("### Version") | |
| component = issue_body[i + len(affected_header):j].strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# Find the label_checker.py file and examine its content
find . -name "label_checker.py" -type fRepository: wso2/api-manager
Length of output: 96
🏁 Script executed:
# List files in .github directory to understand structure
ls -la .github/ | head -20Repository: wso2/api-manager
Length of output: 359
🏁 Script executed:
# Search for issue template files
find .github -type f \( -name "*.md" -o -name "*.yml" -o -name "*.yaml" \) | grep -i templateRepository: wso2/api-manager
Length of output: 328
🏁 Script executed:
# Read the label_checker.py file to see the implementation
cat -n .github/workflows/label_checker.pyRepository: wso2/api-manager
Length of output: 2416
🏁 Script executed:
# Check one of the issue template files to see the actual format
cat .github/ISSUE_TEMPLATE/bug.ymlRepository: wso2/api-manager
Length of output: 1039
🏁 Script executed:
# Check another issue template to see if format is consistent
cat .github/ISSUE_TEMPLATE/new-feature.ymlRepository: wso2/api-manager
Length of output: 895
🏁 Script executed:
# Search for "Affected Component" in the codebase to see if it's defined anywhere
rg -i "affected component" --type md --type yml --type yamlRepository: wso2/api-manager
Length of output: 87
🏁 Script executed:
# Check if there are any other references to this in the repository
rg -i "affected component" -type pyRepository: wso2/api-manager
Length of output: 87
🏁 Script executed:
# Let's check all issue templates to see which ones might have these fields
for file in .github/ISSUE_TEMPLATE/*.yml; do echo "=== $file ===" && cat "$file"; doneRepository: wso2/api-manager
Length of output: 5198
🏁 Script executed:
# Let's check the git history to see if these templates were recently changed
git log --oneline .github/ISSUE_TEMPLATE/ | head -20Repository: wso2/api-manager
Length of output: 149
🏁 Script executed:
# Check if there are any other references to "Affected Component" in the codebase
rg "Affected Component"Repository: wso2/api-manager
Length of output: 42
🏁 Script executed:
# Let's verify how GitHub renders issue form bodies by checking any documentation or examples
rg "### Affected" -A 3 -B 3Repository: wso2/api-manager
Length of output: 42
🏁 Script executed:
# Check when the label_checker.py was last modified and what the commit message says
git log --oneline .github/workflows/label_checker.py | head -10Repository: wso2/api-manager
Length of output: 149
🏁 Script executed:
# Check the git diff for the recent commit to understand what changed
git show 7eb7524 --statRepository: wso2/api-manager
Length of output: 1201
🏁 Script executed:
# See the full diff of the recent commit
git show 7eb7524Repository: wso2/api-manager
Length of output: 27211
🏁 Script executed:
# Check if there are any workflow files that reference ISSUE_BODY
rg "ISSUE_BODY"Repository: wso2/api-manager
Length of output: 42
🏁 Script executed:
# Let's verify how GitHub renders the issue body from these YAML form templates
# by checking if there's any example or documentation about the format
python3 << 'EOF'
# Simulate what GitHub would render from the question_form.yml template
# When a user fills out a GitHub issue form, the rendered body looks like:
# FieldLabel
# user_input
#
# Not as:
# ### FieldLabel
# user_input
template_example = """Description
Example question
Affected Component
APIM
Version
3.2.0"""
print("Example rendered issue body from GitHub form:")
print(template_example)
print("\nSearching for '### Affected Component' in this body:")
try:
index = template_example.index("### Affected Component")
print(f"Found at index {index}")
except ValueError:
print("NOT FOUND - ValueError would be raised")
print("\nThe code would fail at line 27 with ValueError")
print("This exception is caught by the broad except block")
print("Script always outputs: 'Missing/Component'")
EOFRepository: wso2/api-manager
Length of output: 409
Critical issue: Code expects markdown headers that GitHub issue forms don't produce.
The script searches for "### Affected Component" in the issue body (line 27), but GitHub's YAML form templates don't render field labels as markdown headers. The actual rendered issue body uses plain text format (e.g., Affected Component followed by the user input). This means index() will always raise ValueError, caught by the broad exception handler on line 56, causing the script to always output "Missing/Component" regardless of input.
The script is fundamentally incompatible with the current issue templates and needs to be rewritten to parse the correct plain-text format produced by GitHub forms. Additionally, remove the unused variable e on line 56 and replace the broad except Exception with specific exception handling.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In @.github/workflows/label_checker.py around lines 27 - 32, The current logic
that slices issue_body using index("### Affected Component") fails because
GitHub form output is plain text; replace that slicing with a regex search
against issue_body (e.g., a multiline regex that finds the plain "Affected
Component" label and captures the user-provided value on the same line or the
following line) to set component and component_label and append to labels only
if it matches all_existing_labels; also remove the unused variable e and change
the broad except Exception handler to catch specific errors (e.g.,
ValueError/IndexError from parsing or re-related exceptions) so parsing failures
fall back to adding "Missing/Component" without hiding other bugs.
Copilot
AI
Mar 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version_start = j + 13 offset is still hard-coded to a specific header+newline layout. This can break with different newline conventions or template formatting. Consider deriving the start index from len('### Version') and then skipping any following whitespace/newlines before extracting the value (or reuse the same section-parsing helper as for the component).
| version_start = j + 13 | |
| version_text = issue_body[version_start:].strip() | |
| header = "### Version" | |
| header_len = len(header) | |
| version_start = j + header_len | |
| # Skip any whitespace/newlines immediately after the header | |
| while version_start < len(issue_body) and issue_body[version_start] in (" ", "\t", "\r", "\n"): | |
| version_start += 1 | |
| version_text = issue_body[version_start:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback
print('Missing/Component')bypasses the existing-label check and will makegh issue edit --add-label $labelsfail if that label doesn’t already exist in the repo. Either verifyMissing/Componentis inall_existing_labelsbefore printing it, or print an empty string and have the workflow skip--add-labelwhen no valid labels were found.