Skip to content

Commit e0a4490

Browse files
committed
fix: omit resolution reason from standard thread resolution
1 parent c71961c commit e0a4490

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

‎pkg/github/pullrequests.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,9 +2180,14 @@ func ResolveReviewThreadWithReason(ctx context.Context, client *githubv4.Client,
21802180
} `graphql:"resolveReviewThread(input: $input)"`
21812181
}
21822182

2183-
input := ResolveReviewThreadInput{
2184-
ThreadID: githubv4.ID(threadID),
2185-
ResolutionReason: newGQLStringlikePtr[githubv4.String](resolutionReason),
2183+
var input any
2184+
if resolutionReason == nil {
2185+
input = githubv4.ResolveReviewThreadInput{ThreadID: githubv4.ID(threadID)}
2186+
} else {
2187+
input = ResolveReviewThreadInput{
2188+
ThreadID: githubv4.ID(threadID),
2189+
ResolutionReason: newGQLStringlikePtr[githubv4.String](resolutionReason),
2190+
}
21862191
}
21872192

21882193
if err := client.Mutate(ctx, &mutation, input, nil); err != nil {

‎pkg/github/pullrequests_test.go‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package github
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
7+
"io"
68
"net/http"
79
"strings"
810
"sync/atomic"
@@ -19,6 +21,31 @@ import (
1921
"github.com/stretchr/testify/require"
2022
)
2123

24+
type captureGraphQLTransport struct {
25+
response string
26+
variables map[string]any
27+
}
28+
29+
func (t *captureGraphQLTransport) RoundTrip(req *http.Request) (*http.Response, error) {
30+
body, err := io.ReadAll(req.Body)
31+
if err != nil {
32+
return nil, err
33+
}
34+
var request struct {
35+
Variables map[string]any `json:"variables"`
36+
}
37+
if err := json.Unmarshal(body, &request); err != nil {
38+
return nil, err
39+
}
40+
t.variables = request.Variables
41+
return &http.Response{
42+
StatusCode: http.StatusOK,
43+
Header: make(http.Header),
44+
Body: io.NopCloser(bytes.NewBufferString(t.response)),
45+
Request: req,
46+
}, nil
47+
}
48+
2249
func Test_GetPullRequest(t *testing.T) {
2350
// Verify tool definition once
2451
serverTool := PullRequestRead(translations.NullTranslationHelper)
@@ -4877,3 +4904,19 @@ func TestResolveReviewThread(t *testing.T) {
48774904
})
48784905
}
48794906
}
4907+
4908+
func TestResolveReviewThreadWithoutReasonOmitsOptionalInputField(t *testing.T) {
4909+
transport := &captureGraphQLTransport{
4910+
response: `{"data":{"resolveReviewThread":{"thread":{"id":"PRRT_test","isResolved":true}}}}`,
4911+
}
4912+
client := githubv4.NewClient(&http.Client{Transport: transport})
4913+
4914+
result, err := ResolveReviewThread(context.Background(), client, "PRRT_test", true)
4915+
require.NoError(t, err)
4916+
require.False(t, result.IsError)
4917+
require.NotNil(t, transport.variables)
4918+
input, ok := transport.variables["input"].(map[string]any)
4919+
require.True(t, ok)
4920+
assert.Equal(t, "PRRT_test", input["threadId"])
4921+
assert.NotContains(t, input, "resolutionReason")
4922+
}

‎pkg/http/oauth/oauth_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ func TestHandleProtectedResource(t *testing.T) {
436436
host: "api.example.com",
437437
method: http.MethodGet,
438438
expectedStatusCode: http.StatusOK,
439-
expectedScopes: []string{
439+
expectedScopes: []string{
440440
"repo",
441441
"read:org",
442442
"read:user",

0 commit comments

Comments
 (0)