Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix(ci): apply inferred issue type labels (#17218)

Engel Nyst23ca81c9ff6e
diff --git a/.github/scripts/check_issue_readiness.py b/.github/scripts/check_issue_readiness.py
index d2ca83534e..1718e6c177 100644
--- a/.github/scripts/check_issue_readiness.py
+++ b/.github/scripts/check_issue_readiness.py
@@ -109,6 +109,7 @@ class ReadinessResult:
ready: bool
reasons: list[str] = field(default_factory=list)
+ issue_type: str | None = None
def add(self, reason: str) -> None:
self.reasons.append(reason)
@@ -184,7 +185,7 @@ def has_checklist_item(text: str) -> bool:
def check_bug(sections: dict[str, str]) -> ReadinessResult:
- result = ReadinessResult(ready=True)
+ result = ReadinessResult(ready=True, issue_type=BUG_LABEL)
reproduction = visible_text(find_section(sections, "steps to reproduce", "reproduction"))
if not reproduction:
@@ -220,7 +221,7 @@ def check_bug(sections: dict[str, str]) -> ReadinessResult:
def check_enhancement(sections: dict[str, str]) -> ReadinessResult:
- result = ReadinessResult(ready=True)
+ result = ReadinessResult(ready=True, issue_type=ENHANCEMENT_LABEL)
desired = visible_text(find_section(sections, "desired behavior", "desired"))
if not desired:
@@ -250,10 +251,22 @@ def evaluate_readiness(body: str, labels: list[str]) -> ReadinessResult:
is accepted for backwards compatibility but is not consulted.
"""
sections = extract_sections(body or "")
+ has_bug_sections = any(label in sections for label in BUG_SECTION_LABELS)
+ has_enhancement_sections = any(
+ label in sections for label in ENHANCEMENT_SECTION_LABELS
+ )
- if any(label in sections for label in BUG_SECTION_LABELS):
+ if has_bug_sections and has_enhancement_sections:
+ return ReadinessResult(
+ ready=False,
+ reasons=[
+ "The issue contains both bug-report and feature-request sections, "
+ "so its type cannot be inferred. Use only one issue template."
+ ],
+ )
+ if has_bug_sections:
return check_bug(sections)
- if any(label in sections for label in ENHANCEMENT_SECTION_LABELS):
+ if has_enhancement_sections:
return check_enhancement(sections)
return ReadinessResult(
@@ -319,7 +332,15 @@ def main() -> int:
result = evaluate_readiness(body, labels)
if args.json:
- print(json.dumps({"ready": result.ready, "reasons": result.reasons}))
+ print(
+ json.dumps(
+ {
+ "ready": result.ready,
+ "reasons": result.reasons,
+ "issue_type": result.issue_type,
+ }
+ )
+ )
else:
if result.ready:
print("Issue meets ready-for-dev criteria.")
diff --git a/.github/scripts/tests/test_issue_readiness.py b/.github/scripts/tests/test_issue_readiness.py
index 615134ad6c..5ee6bae953 100644
--- a/.github/scripts/tests/test_issue_readiness.py
+++ b/.github/scripts/tests/test_issue_readiness.py
@@ -202,6 +202,7 @@ def test_enhancement_not_ready_prose_acceptance():
def test_no_type_section_not_ready():
result = evaluate_readiness("### Something\nSome text", [])
assert not result.ready
+ assert result.issue_type is None
assert any("neither" in r.lower() for r in result.reasons)
@@ -209,10 +210,12 @@ def test_type_inferred_from_body_ignores_labels():
# A bug-shaped body is treated as a bug even without a `bug` label.
result = evaluate_readiness(BUG_BODY_READY, [])
assert result.ready, result.reasons
+ assert result.issue_type == BUG_LABEL
# A feature-shaped body is treated as an enhancement even with a `bug` label.
result = evaluate_readiness(ENHANCEMENT_BODY_READY, ["bug"])
assert result.ready, result.reasons
+ assert result.issue_type == ENHANCEMENT_LABEL
# A body with only an `### Actual Behavior` section (no Steps to Reproduce)
# is still recognized as a bug report.
@@ -224,9 +227,18 @@ def test_type_inferred_from_body_ignores_labels():
def test_empty_type_section_is_still_classified():
result = evaluate_readiness("### Actual Behavior\n### Acceptance Criteria\n", [])
assert not result.ready
+ assert result.issue_type == BUG_LABEL
assert any("Steps to Reproduce" in r for r in result.reasons)
+def test_ambiguous_body_does_not_infer_type():
+ body = f"{BUG_BODY_READY}\n{ENHANCEMENT_BODY_READY}"
+ result = evaluate_readiness(body, [])
+ assert not result.ready
+ assert result.issue_type is None
+ assert any("both" in reason.lower() for reason in result.reasons)
+
+
# ---------------------------------------------------------------------------
# Unit-level helpers
# ---------------------------------------------------------------------------
@@ -407,6 +419,7 @@ def test_main_json_not_ready(tmp_path, capsys, monkeypatch):
captured = capsys.readouterr()
data = json.loads(captured.out)
assert data["ready"] is False
+ assert data["issue_type"] == BUG_LABEL
assert len(data["reasons"]) > 0
@@ -431,6 +444,7 @@ def test_main_json_ready(tmp_path, capsys, monkeypatch):
captured = capsys.readouterr()
data = json.loads(captured.out)
assert data["ready"] is True
+ assert data["issue_type"] == BUG_LABEL
assert len(data["reasons"]) == 0
@@ -500,5 +514,5 @@ def test_main_event_path_json_ready(tmp_path, capsys, monkeypatch):
captured = capsys.readouterr()
data = json.loads(captured.out)
assert data["ready"] is True
+ assert data["issue_type"] == BUG_LABEL
assert len(data["reasons"]) == 0
-
diff --git a/.github/workflows/issue-readiness-check.yml b/.github/workflows/issue-readiness-check.yml
index 9fa5a4aba9..c92b70960e 100644
--- a/.github/workflows/issue-readiness-check.yml
+++ b/.github/workflows/issue-readiness-check.yml
@@ -7,6 +7,8 @@ name: Issue Readiness Check
# a `##`/`### Steps to Reproduce` or `##`/`### Actual Behavior` section is
# checked as a bug report, and a body with a `##`/`### Desired Behavior`
# section is checked as an enhancement. The criteria themselves are unchanged.
+# When exactly one type is inferred, the workflow also synchronizes the `bug`
+# and `enhancement` labels so API-created issues do not require manual labeling.
#
# When criteria are met the label is added (idempotently); when they are not the
# label is removed. A feedback comment is posted (or updated) in three cases:
@@ -47,11 +49,58 @@ jobs:
set -euo pipefail
python .github/scripts/check_issue_readiness.py --json > /tmp/result.json || true
echo "ready=$(jq -r '.ready' /tmp/result.json)" >> "$GITHUB_OUTPUT"
+ echo "issue_type=$(jq -r '.issue_type // empty' /tmp/result.json)" >> "$GITHUB_OUTPUT"
# Write reasons to a file so the comment step can read them
# without shell-escaping multiline text.
jq -r '.reasons[]?' /tmp/result.json > /tmp/reasons.txt || true
echo "reasons_file=/tmp/reasons.txt" >> "$GITHUB_OUTPUT"
+ - name: Synchronize inferred issue type label
+ if: steps.readiness.outputs.issue_type != ''
+ env:
+ GH_TOKEN: ${{ github.token }}
+ ISSUE_TYPE: ${{ steps.readiness.outputs.issue_type }}
+ run: |
+ set -euo pipefail
+
+ if ! issue_labels_json=$(gh issue view \
+ "${{ github.event.issue.number }}" \
+ --repo "${{ github.repository }}" \
+ --json labels --jq '[.labels[].name]' 2>/tmp/gh-err.txt); then
+ echo "::warning::Failed to read current issue labels:" \
+ >> "$GITHUB_STEP_SUMMARY"
+ cat /tmp/gh-err.txt >> "$GITHUB_STEP_SUMMARY"
+ exit 0
+ fi
+
+ if [ "$ISSUE_TYPE" = "bug" ]; then
+ other_type="enhancement"
+ else
+ other_type="bug"
+ fi
+
+ label_args=()
+ if ! jq -e --arg label "$ISSUE_TYPE" \
+ 'index($label) != null' <<< "$issue_labels_json" >/dev/null; then
+ label_args+=(--add-label "$ISSUE_TYPE")
+ fi
+ if jq -e --arg label "$other_type" \
+ 'index($label) != null' <<< "$issue_labels_json" >/dev/null; then
+ label_args+=(--remove-label "$other_type")
+ fi
+
+ if [ "${#label_args[@]}" -eq 0 ]; then
+ exit 0
+ fi
+
+ if ! gh issue edit "${{ github.event.issue.number }}" \
+ --repo "${{ github.repository }}" \
+ "${label_args[@]}" 2>/tmp/gh-err.txt; then
+ echo "::warning::Failed to synchronize inferred issue type label:" \
+ >> "$GITHUB_STEP_SUMMARY"
+ cat /tmp/gh-err.txt >> "$GITHUB_STEP_SUMMARY"
+ fi
+
- name: Add ready-for-dev label
if: steps.readiness.outputs.ready == 'true'
env: