Skip to content

Commit 1d662b4

Browse files
author
root
committed
fix: close HTTP response bodies during check runs fallbacks
1 parent bb3528c commit 1d662b4

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

pkg/github/check_runs.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,23 @@ func GetPullRequestCheckRuns(ctx context.Context, client *github.Client, owner,
4444
if !isAccessDenied(resp) {
4545
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get check runs", resp, err), nil
4646
}
47+
closeResponse(resp)
4748

4849
// Checks API is unavailable (common on hosted MCP without checks:read). Try fallbacks.
49-
if fallback, fbResp, fbErr := fetchCheckRunsFromWorkflowRuns(ctx, client, owner, repo, headSHA, pagination); fbErr == nil {
50-
return marshalCheckRunsResult(fallback)
51-
} else if fbResp != nil && !isAccessDenied(fbResp) {
52-
_ = fbResp.Body.Close()
50+
workflowFallback, workflowResp, workflowErr := fetchCheckRunsFromWorkflowRuns(ctx, client, owner, repo, headSHA, pagination)
51+
if workflowErr == nil {
52+
return marshalCheckRunsResult(workflowFallback)
5353
}
54+
if !isAccessDenied(workflowResp) {
55+
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to get check runs", workflowResp, workflowErr), nil
56+
}
57+
closeResponse(workflowResp)
5458

55-
if fallback, fbResp, fbErr := fetchCheckRunsFromCommitStatuses(ctx, client, owner, repo, headSHA, pagination); fbErr == nil {
56-
return marshalCheckRunsResult(fallback)
57-
} else if fbResp != nil {
58-
_ = fbResp.Body.Close()
59+
statusFallback, statusResp, statusErr := fetchCheckRunsFromCommitStatuses(ctx, client, owner, repo, headSHA, pagination)
60+
if statusErr == nil {
61+
return marshalCheckRunsResult(statusFallback)
5962
}
63+
closeResponse(statusResp)
6064

6165
return ghErrors.NewGitHubAPIErrorResponse(ctx,
6266
checkRunsAccessErrMsg("failed to get check runs", owner, repo),
@@ -192,6 +196,12 @@ func marshalCheckRunsResult(result MinimalCheckRunsResult) (*mcp.CallToolResult,
192196
return utils.NewToolResultText(string(r)), nil
193197
}
194198

199+
func closeResponse(resp *github.Response) {
200+
if resp != nil && resp.Body != nil {
201+
_ = resp.Body.Close()
202+
}
203+
}
204+
195205
func readResponseBody(resp *github.Response) ([]byte, error) {
196206
body, err := io.ReadAll(resp.Body)
197207
if err != nil {

0 commit comments

Comments
 (0)