Skip to content

Commit 26c3eab

Browse files
Douglas Blankclaude
andcommitted
fix: treat empty ISSUE_NUMBER env as unset
A workflow that combines `on: issues` with `workflow_dispatch` will typically set `ISSUE_NUMBER: ${{ github.event.inputs.issue_number }}`, which evaluates to the empty string on the auto-trigger. The old check `"ISSUE_NUMBER" in os.environ` then took the env-var branch and crashed in int(""). Read with os.environ.get(..., "").strip() so empty/whitespace falls through to the event payload, where auto-detection already works. Update the README example to show the combined auto+manual trigger pattern and the matching ISSUE_NUMBER fallback so consumers copy the safe form. Add a regression test for the empty-string case and simplify the existing event-file test now that the workaround is no longer needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4df747b commit 26c3eab

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ name: Scout Issue Triage
4141
on:
4242
issues:
4343
types: [opened]
44+
workflow_dispatch:
45+
inputs:
46+
issue_number:
47+
description: Issue number to triage
48+
required: true
49+
type: number
4450

4551
# One Scout run per issue at a time
4652
concurrency:
47-
group: scout-issue-${{ github.event.issue.number }}
53+
group: scout-issue-${{ github.event.issue.number || github.event.inputs.issue_number }}
4854
cancel-in-progress: false
4955

5056
jobs:
@@ -67,6 +73,7 @@ jobs:
6773
SCOUT_GITHUB_REPO_NAME: ${{ vars.SCOUT_GITHUB_REPO_NAME }}
6874
OPIK_API_KEY: ${{ secrets.OPIK_API_KEY }}
6975
OPIK_WORKSPACE: ${{ vars.OPIK_WORKSPACE }}
76+
ISSUE_NUMBER: ${{ github.event.issue.number || github.event.inputs.issue_number }}
7077
```
7178
7279
## GitHub App requirements

scout.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ def _get_repo_owner_name() -> tuple[str, str]:
6060

6161
def _get_issue_number() -> int:
6262
"""Resolve issue number from ISSUE_NUMBER or the GitHub Actions event payload."""
63-
if "ISSUE_NUMBER" in os.environ:
64-
return int(os.environ["ISSUE_NUMBER"])
63+
# Treat empty as unset: workflows often pass `${{ github.event.inputs.foo }}`,
64+
# which evaluates to "" on triggers that don't carry the input.
65+
issue_env = os.environ.get("ISSUE_NUMBER", "").strip()
66+
if issue_env:
67+
return int(issue_env)
6568
event_path = os.environ.get("GITHUB_EVENT_PATH", "")
6669
if event_path and os.path.isfile(event_path):
6770
with open(event_path) as f:

test_scout.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,20 @@ def test_from_event_file(self, tmp_path):
6464
event = {"issue": {"number": 7}}
6565
event_file = tmp_path / "event.json"
6666
event_file.write_text(json.dumps(event))
67-
with patch.dict(os.environ, {"ISSUE_NUMBER": "", "GITHUB_EVENT_PATH": str(event_file)}):
68-
# Remove ISSUE_NUMBER key entirely so the function falls through to the file
69-
env = dict(os.environ)
70-
env.pop("ISSUE_NUMBER", None)
71-
with patch.dict(os.environ, env, clear=True):
72-
os.environ["GITHUB_EVENT_PATH"] = str(event_file)
73-
assert scout._get_issue_number() == 7
67+
env = {k: v for k, v in os.environ.items() if k != "ISSUE_NUMBER"}
68+
env["GITHUB_EVENT_PATH"] = str(event_file)
69+
with patch.dict(os.environ, env, clear=True):
70+
assert scout._get_issue_number() == 7
71+
72+
def test_empty_env_falls_through_to_event_file(self, tmp_path):
73+
# Workflows commonly pass `${{ github.event.inputs.foo }}`, which is the
74+
# empty string on triggers that don't carry that input. Empty must be
75+
# treated as unset so auto-detection from the event payload still works.
76+
event = {"issue": {"number": 11}}
77+
event_file = tmp_path / "event.json"
78+
event_file.write_text(json.dumps(event))
79+
with patch.dict(os.environ, {"ISSUE_NUMBER": "", "GITHUB_EVENT_PATH": str(event_file)}, clear=True):
80+
assert scout._get_issue_number() == 11
7481

7582
def test_raises_when_missing(self):
7683
env = {k: v for k, v in os.environ.items() if k not in ("ISSUE_NUMBER", "GITHUB_EVENT_PATH")}

0 commit comments

Comments
 (0)