fix(sigretests.filterOptionalJobs): consider http status#107
Merged
Conversation
Signed-off-by: Daniel Hiller <dhiller@redhat.com>
Signed-off-by: Daniel Hiller <dhiller@redhat.com>
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
filterOptionalJobs, you accessprowJobJSON.StatusCodebefore checking theerrfromhttp.Get; swap the order so you return on error before dereferencing a potentially nil response. - When skipping non-200 responses in
filterOptionalJobs, make sure to closeprowJobJSON.Bodybeforecontinue, and consider replacing the per-iterationdefer prowJobJSON.Body.Close()with an explicitClose()to avoid accumulating open connections in the loop.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `filterOptionalJobs`, you access `prowJobJSON.StatusCode` before checking the `err` from `http.Get`; swap the order so you return on error before dereferencing a potentially nil response.
- When skipping non-200 responses in `filterOptionalJobs`, make sure to close `prowJobJSON.Body` before `continue`, and consider replacing the per-iteration `defer prowJobJSON.Body.Close()` with an explicit `Close()` to avoid accumulating open connections in the loop.
## Individual Comments
### Comment 1
<location> `pkg/sigretests/main.go:169-170` </location>
<code_context>
var filteredJobs []job
for _, j := range unfilteredJobs {
prowJobJSON, err := http.Get(fmt.Sprintf(prowJobJSONURL, org, repo, prNumber, j.jobName, j.buildNumber))
+ if prowJobJSON.StatusCode != 200 {
+ continue
+ }
</code_context>
<issue_to_address>
**issue (bug_risk):** StatusCode is accessed before checking `err`, which can panic if `http.Get` fails.
If `http.Get` returns an error, `prowJobJSON` will be nil and accessing `prowJobJSON.StatusCode` will panic. You should check `err` before using the response, then check `StatusCode`, e.g.:
```go
prowJobJSON, err := http.Get(fmt.Sprintf(prowJobJSONURL, org, repo, prNumber, j.jobName, j.buildNumber))
if err != nil {
return nil, err
}
if prowJobJSON.StatusCode != http.StatusOK {
prowJobJSON.Body.Close()
continue
}
defer prowJobJSON.Body.Close()
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
pkg/sigretests/main.go
Outdated
Comment on lines
+169
to
+170
| prowJobJSON, err := http.Get(fmt.Sprintf(prowJobJSONURL, org, repo, prNumber, j.jobName, j.buildNumber)) | ||
| if prowJobJSON.StatusCode != 200 { |
There was a problem hiding this comment.
issue (bug_risk): StatusCode is accessed before checking err, which can panic if http.Get fails.
If http.Get returns an error, prowJobJSON will be nil and accessing prowJobJSON.StatusCode will panic. You should check err before using the response, then check StatusCode, e.g.:
prowJobJSON, err := http.Get(fmt.Sprintf(prowJobJSONURL, org, repo, prNumber, j.jobName, j.buildNumber))
if err != nil {
return nil, err
}
if prowJobJSON.StatusCode != http.StatusOK {
prowJobJSON.Body.Close()
continue
}
defer prowJobJSON.Body.Close()Signed-off-by: Daniel Hiller <dhiller@redhat.com>
Signed-off-by: Daniel Hiller <dhiller@redhat.com>
dollierp
reviewed
Feb 18, 2026
| } | ||
|
|
||
| defer prowJobJSON.Body.Close() | ||
| if prowJobJSON.StatusCode != 200 { |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this PR does / why we need it:
Adds a missing http status check when filtering for optional lanes.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #106
Special notes for your reviewer:
/cc @dollierp