Skip to content

Commit 5135adf

Browse files
committed
fix: close reaction removal responses on errors
Register nil-safe response body cleanup before handling go-github errors for all reaction removal tools, and cover every API-error path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9acf9c83-49aa-41af-a42d-ad75de34d132
1 parent b971c95 commit 5135adf

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎pkg/github/granular_tools_test.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,19 @@ func TestGranularRemoveIssueCommentReaction(t *testing.T) {
26332633
},
26342634
expectedErrMsg: "missing required parameter: comment_id",
26352635
},
2636+
{
2637+
name: "API error",
2638+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
2639+
DeleteReposIssuesCommentsReactionsByOwnerByRepoByCommentID: mockResponse(t, http.StatusNotFound, `{"message":"Not Found"}`),
2640+
}),
2641+
args: map[string]any{
2642+
"owner": "owner",
2643+
"repo": "repo",
2644+
"comment_id": float64(999),
2645+
"reaction_id": float64(67890),
2646+
},
2647+
expectedErrMsg: "failed to remove reaction from issue comment",
2648+
},
26362649
}
26372650

26382651
for _, tc := range tests {
@@ -2746,6 +2759,19 @@ func TestGranularRemovePullRequestReviewCommentReaction(t *testing.T) {
27462759
},
27472760
expectedErrMsg: "missing required parameter: repo",
27482761
},
2762+
{
2763+
name: "API error",
2764+
mockedClient: MockHTTPClientWithHandlers(map[string]http.HandlerFunc{
2765+
DeleteReposPullsCommentsReactionsByOwnerByRepoByCommentID: mockResponse(t, http.StatusNotFound, `{"message":"Not Found"}`),
2766+
}),
2767+
args: map[string]any{
2768+
"owner": "owner",
2769+
"repo": "repo",
2770+
"comment_id": float64(888),
2771+
"reaction_id": float64(54321),
2772+
},
2773+
expectedErrMsg: "failed to remove reaction from pull request review comment",
2774+
},
27492775
}
27502776

27512777
for _, tc := range tests {

‎pkg/github/issues_granular.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,10 +1729,12 @@ func GranularRemoveIssueReaction(t translations.TranslationHelperFunc) inventory
17291729
}
17301730

17311731
resp, err := client.Reactions.DeleteIssueReaction(ctx, owner, repo, issueNumber, reactionID)
1732+
if resp != nil && resp.Body != nil {
1733+
defer func() { _ = resp.Body.Close() }()
1734+
}
17321735
if err != nil {
17331736
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to remove reaction from issue", resp, err), nil, nil
17341737
}
1735-
defer func() { _ = resp.Body.Close() }()
17361738

17371739
return utils.NewToolResultText("reaction successfully removed from issue"), nil, nil
17381740
},
@@ -1886,10 +1888,12 @@ func GranularRemoveIssueCommentReaction(t translations.TranslationHelperFunc) in
18861888
}
18871889

18881890
resp, err := client.Reactions.DeleteIssueCommentReaction(ctx, owner, repo, commentID, reactionID)
1891+
if resp != nil && resp.Body != nil {
1892+
defer func() { _ = resp.Body.Close() }()
1893+
}
18891894
if err != nil {
18901895
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to remove reaction from issue comment", resp, err), nil, nil
18911896
}
1892-
defer func() { _ = resp.Body.Close() }()
18931897

18941898
return utils.NewToolResultText("reaction successfully removed from issue comment"), nil, nil
18951899
},

‎pkg/github/pullrequests_granular.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,10 +960,12 @@ func GranularRemovePullRequestReviewCommentReaction(t translations.TranslationHe
960960
}
961961

962962
resp, err := client.Reactions.DeletePullRequestCommentReaction(ctx, owner, repo, commentID, reactionID)
963+
if resp != nil && resp.Body != nil {
964+
defer func() { _ = resp.Body.Close() }()
965+
}
963966
if err != nil {
964967
return ghErrors.NewGitHubAPIErrorResponse(ctx, "failed to remove reaction from pull request review comment", resp, err), nil, nil
965968
}
966-
defer func() { _ = resp.Body.Close() }()
967969

968970
return utils.NewToolResultText("reaction successfully removed from pull request review comment"), nil, nil
969971
},

0 commit comments

Comments
 (0)