-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: poll for linked PR after assigning Copilot to issue #1810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SamMorrowDrums
wants to merge
6
commits into
main
Choose a base branch
from
SamMorrowDrums/assign-copilot-poll-linked-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+367
−11
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1cfb91
feat: poll for linked PR after assigning Copilot to issue
SamMorrowDrums b23784f
fix: filter PRs by timestamp to avoid returning stale results
SamMorrowDrums cfdc6a1
fix: remove tool name reference from pending note message
SamMorrowDrums 6cfa8ce
fix: address review feedback
SamMorrowDrums 40849b1
refactor: use GraphQLFeaturesTransport internally
SamMorrowDrums 7184f60
Merge branch 'main' into SamMorrowDrums/assign-copilot-poll-linked-pr
SamMorrowDrums File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
| ) | ||
|
|
||
| // GraphQLFeaturesTransport is an http.RoundTripper that adds GraphQL-Features | ||
| // header to requests based on context values. This is required for using | ||
| // non-GA GraphQL API features like the agent assignment API. | ||
| // | ||
| // Usage: | ||
| // | ||
| // httpClient := &http.Client{ | ||
| // Transport: &github.GraphQLFeaturesTransport{ | ||
| // Transport: http.DefaultTransport, | ||
| // }, | ||
| // } | ||
| // gqlClient := githubv4.NewClient(httpClient) | ||
| // | ||
| // Then use withGraphQLFeatures(ctx, "feature_name") when calling GraphQL operations. | ||
| type GraphQLFeaturesTransport struct { | ||
| // Transport is the underlying HTTP transport. If nil, http.DefaultTransport is used. | ||
| Transport http.RoundTripper | ||
| } | ||
SamMorrowDrums marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // RoundTrip implements http.RoundTripper. | ||
| func (t *GraphQLFeaturesTransport) RoundTrip(req *http.Request) (*http.Response, error) { | ||
| transport := t.Transport | ||
| if transport == nil { | ||
| transport = http.DefaultTransport | ||
| } | ||
|
|
||
| // Clone the request to avoid mutating the original | ||
| req = req.Clone(req.Context()) | ||
|
|
||
| // Check for GraphQL-Features in context and add header if present | ||
| if features := GetGraphQLFeatures(req.Context()); len(features) > 0 { | ||
| req.Header.Set("GraphQL-Features", strings.Join(features, ", ")) | ||
| } | ||
|
|
||
| return transport.RoundTrip(req) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGraphQLFeaturesTransport(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| features []string | ||
| expectedHeader string | ||
| hasHeader bool | ||
| }{ | ||
| { | ||
| name: "no features in context", | ||
| features: nil, | ||
| expectedHeader: "", | ||
| hasHeader: false, | ||
| }, | ||
| { | ||
| name: "single feature in context", | ||
| features: []string{"issues_copilot_assignment_api_support"}, | ||
| expectedHeader: "issues_copilot_assignment_api_support", | ||
| hasHeader: true, | ||
| }, | ||
| { | ||
| name: "multiple features in context", | ||
| features: []string{"feature1", "feature2", "feature3"}, | ||
| expectedHeader: "feature1, feature2, feature3", | ||
| hasHeader: true, | ||
| }, | ||
| { | ||
| name: "empty features slice", | ||
| features: []string{}, | ||
| expectedHeader: "", | ||
| hasHeader: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var capturedHeader string | ||
| var headerExists bool | ||
|
|
||
| // Create a test server that captures the request header | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| capturedHeader = r.Header.Get("GraphQL-Features") | ||
| headerExists = r.Header.Get("GraphQL-Features") != "" | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| // Create the transport | ||
| transport := &GraphQLFeaturesTransport{ | ||
| Transport: http.DefaultTransport, | ||
| } | ||
|
|
||
| // Create a request | ||
| ctx := context.Background() | ||
| if tc.features != nil { | ||
| ctx = withGraphQLFeatures(ctx, tc.features...) | ||
| } | ||
|
|
||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, server.URL, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Execute the request | ||
| resp, err := transport.RoundTrip(req) | ||
| require.NoError(t, err) | ||
| defer resp.Body.Close() | ||
|
|
||
| // Verify the header | ||
| assert.Equal(t, tc.hasHeader, headerExists) | ||
| if tc.hasHeader { | ||
| assert.Equal(t, tc.expectedHeader, capturedHeader) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGraphQLFeaturesTransport_NilTransport(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| var capturedHeader string | ||
|
|
||
| // Create a test server | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| capturedHeader = r.Header.Get("GraphQL-Features") | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| // Create the transport with nil Transport (should use DefaultTransport) | ||
| transport := &GraphQLFeaturesTransport{ | ||
| Transport: nil, | ||
| } | ||
|
|
||
| // Create a request with features | ||
| ctx := withGraphQLFeatures(context.Background(), "test_feature") | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, server.URL, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Execute the request | ||
| resp, err := transport.RoundTrip(req) | ||
| require.NoError(t, err) | ||
| defer resp.Body.Close() | ||
|
|
||
| // Verify the header was added | ||
| assert.Equal(t, "test_feature", capturedHeader) | ||
| } | ||
|
|
||
| func TestGraphQLFeaturesTransport_DoesNotMutateOriginalRequest(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // Create a test server | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusOK) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| // Create the transport | ||
| transport := &GraphQLFeaturesTransport{ | ||
| Transport: http.DefaultTransport, | ||
| } | ||
|
|
||
| // Create a request with features | ||
| ctx := withGraphQLFeatures(context.Background(), "test_feature") | ||
| req, err := http.NewRequestWithContext(ctx, http.MethodPost, server.URL, nil) | ||
| require.NoError(t, err) | ||
|
|
||
| // Store the original header value | ||
| originalHeader := req.Header.Get("GraphQL-Features") | ||
|
|
||
| // Execute the request | ||
| resp, err := transport.RoundTrip(req) | ||
| require.NoError(t, err) | ||
| defer resp.Body.Close() | ||
|
|
||
| // Verify the original request was not mutated | ||
| assert.Equal(t, originalHeader, req.Header.Get("GraphQL-Features")) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.