Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pkg/github/pullrequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2180,9 +2180,14 @@ func ResolveReviewThreadWithReason(ctx context.Context, client *githubv4.Client,
} `graphql:"resolveReviewThread(input: $input)"`
}

input := ResolveReviewThreadInput{
ThreadID: githubv4.ID(threadID),
ResolutionReason: newGQLStringlikePtr[githubv4.String](resolutionReason),
var input any
if resolutionReason == nil {
input = githubv4.ResolveReviewThreadInput{ThreadID: githubv4.ID(threadID)}
} else {
input = ResolveReviewThreadInput{
ThreadID: githubv4.ID(threadID),
ResolutionReason: newGQLStringlikePtr[githubv4.String](resolutionReason),
}
}

if err := client.Mutate(ctx, &mutation, input, nil); err != nil {
Expand Down
43 changes: 43 additions & 0 deletions pkg/github/pullrequests_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package github

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"strings"
"sync/atomic"
Expand All @@ -19,6 +21,31 @@ import (
"github.com/stretchr/testify/require"
)

type captureGraphQLTransport struct {
response string
variables map[string]any
}

func (t *captureGraphQLTransport) RoundTrip(req *http.Request) (*http.Response, error) {
body, err := io.ReadAll(req.Body)
if err != nil {
return nil, err
}
var request struct {
Variables map[string]any `json:"variables"`
}
if err := json.Unmarshal(body, &request); err != nil {
return nil, err
}
t.variables = request.Variables
return &http.Response{
StatusCode: http.StatusOK,
Header: make(http.Header),
Body: io.NopCloser(bytes.NewBufferString(t.response)),
Request: req,
}, nil
}

func Test_GetPullRequest(t *testing.T) {
// Verify tool definition once
serverTool := PullRequestRead(translations.NullTranslationHelper)
Expand Down Expand Up @@ -4877,3 +4904,19 @@ func TestResolveReviewThread(t *testing.T) {
})
}
}

func TestResolveReviewThreadWithoutReasonOmitsOptionalInputField(t *testing.T) {
transport := &captureGraphQLTransport{
response: `{"data":{"resolveReviewThread":{"thread":{"id":"PRRT_test","isResolved":true}}}}`,
}
client := githubv4.NewClient(&http.Client{Transport: transport})

result, err := ResolveReviewThread(context.Background(), client, "PRRT_test", true)
require.NoError(t, err)
require.False(t, result.IsError)
require.NotNil(t, transport.variables)
input, ok := transport.variables["input"].(map[string]any)
require.True(t, ok)
assert.Equal(t, "PRRT_test", input["threadId"])
assert.NotContains(t, input, "resolutionReason")
}
2 changes: 1 addition & 1 deletion pkg/http/oauth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func TestHandleProtectedResource(t *testing.T) {
host: "api.example.com",
method: http.MethodGet,
expectedStatusCode: http.StatusOK,
expectedScopes: []string{
expectedScopes: []string{
"repo",
"read:org",
"read:user",
Expand Down