Skip to content

Commit 27ee7e4

Browse files
Export WithGraphQLFeatures for remote server tests
Co-authored-by: SamMorrowDrums <4811358+SamMorrowDrums@users.noreply.github.com>
1 parent 7333546 commit 27ee7e4

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

pkg/github/issues.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,7 +1789,7 @@ func AssignCopilotToIssue(t translations.TranslationHelperFunc) inventory.Server
17891789

17901790
// Add the GraphQL-Features header for the agent assignment API
17911791
// The header will be read by the HTTP transport if it's configured to do so
1792-
ctxWithFeatures := withGraphQLFeatures(ctx, "issues_copilot_assignment_api_support")
1792+
ctxWithFeatures := WithGraphQLFeatures(ctx, "issues_copilot_assignment_api_support")
17931793

17941794
if err := client.Mutate(
17951795
ctxWithFeatures,

pkg/github/transport.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
// These flags enable preview or experimental GitHub API features that are not yet GA.
1111
type graphQLFeaturesKey struct{}
1212

13-
// withGraphQLFeatures adds GraphQL feature flags to the context.
13+
// WithGraphQLFeatures adds GraphQL feature flags to the context.
1414
// The flags are read by GraphQLFeaturesTransport and sent as the GraphQL-Features header.
15-
// This is used internally by tool handlers that require experimental GitHub API features.
16-
func withGraphQLFeatures(ctx context.Context, features ...string) context.Context {
15+
// This is used by tool handlers that require experimental GitHub API features.
16+
// Remote servers can also use this function in tests to simulate feature flag contexts.
17+
func WithGraphQLFeatures(ctx context.Context, features ...string) context.Context {
1718
return context.WithValue(ctx, graphQLFeaturesKey{}, features)
1819
}
1920

@@ -30,7 +31,7 @@ func GetGraphQLFeatures(ctx context.Context) []string {
3031
}
3132

3233
// GraphQLFeaturesTransport is an http.RoundTripper that adds GraphQL-Features
33-
// header based on context values set by withGraphQLFeatures.
34+
// header based on context values set by WithGraphQLFeatures.
3435
//
3536
// This transport should be used in the HTTP client chain for githubv4.Client
3637
// to ensure GraphQL feature flags are properly sent to the GitHub API.
@@ -59,7 +60,7 @@ func GetGraphQLFeatures(ctx context.Context) []string {
5960
// gqlClient := githubv4.NewClient(httpClient)
6061
//
6162
// The transport reads feature flags from request context using GetGraphQLFeatures.
62-
// Feature flags are added to context by the tool handler via withGraphQLFeatures.
63+
// Feature flags are added to context by the tool handler via WithGraphQLFeatures.
6364
type GraphQLFeaturesTransport struct {
6465
// Transport is the underlying http.RoundTripper. If nil, http.DefaultTransport is used.
6566
Transport http.RoundTripper

pkg/github/transport_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestGraphQLFeaturesTransport(t *testing.T) {
6161
// Create request with or without features in context
6262
ctx := context.Background()
6363
if tt.features != nil {
64-
ctx = withGraphQLFeatures(ctx, tt.features...)
64+
ctx = WithGraphQLFeatures(ctx, tt.features...)
6565
}
6666

6767
req, err := http.NewRequestWithContext(ctx, "GET", server.URL, nil)
@@ -97,7 +97,7 @@ func TestGraphQLFeaturesTransport_NilTransport(t *testing.T) {
9797
},
9898
}
9999

100-
ctx := withGraphQLFeatures(context.Background(), "test_feature")
100+
ctx := WithGraphQLFeatures(context.Background(), "test_feature")
101101
req, err := http.NewRequestWithContext(ctx, "GET", server.URL, nil)
102102
require.NoError(t, err)
103103

@@ -123,7 +123,7 @@ func TestGraphQLFeaturesTransport_PreservesOtherHeaders(t *testing.T) {
123123
},
124124
}
125125

126-
ctx := withGraphQLFeatures(context.Background(), "feature1")
126+
ctx := WithGraphQLFeatures(context.Background(), "feature1")
127127
req, err := http.NewRequestWithContext(ctx, "GET", server.URL, nil)
128128
require.NoError(t, err)
129129

0 commit comments

Comments
 (0)