feat!: Refactor request context #22
Conversation
Signed-off-by: Steve Hipwell <steve.hipwell@gmail.com>
This comment was marked as outdated.
This comment was marked as outdated.
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Refactors how request-scoped context is propagated through the GitHub client by moving context.Context onto request creation (NewRequest) and removing it from request execution (Do).
Changes:
- Updated most service methods to pass
ctxintoNewRequest(ctx, ...)and callDo(req, ...)without an explicit context parameter. - Updated redirect/“bare” request helpers call sites to match the new context propagation model.
- Updated
tools/extraneousnewanalyzer + testdata to recognize the newDo(req, v)signature.
Reviewed changes
Copilot reviewed 184 out of 184 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/extraneousnew/testdata/src/no-warnings/main.go | Updates testdata to new Do(req, v) API and removes context usage. |
| tools/extraneousnew/testdata/src/has-warnings/main.go | Updates warning expectations/call patterns for new Do(req, v) signature. |
| tools/extraneousnew/extraneousnew.go | Updates analyzer logic to find the correct argument for Do calls after signature change. |
| test/fields/fields.go | Passes ctx into NewRequest and relies on request context for Do. |
| github/users_ssh_signing_keys.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_social_accounts.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_keys.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_gpg_keys.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_followers.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_emails.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_blocking.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_attestations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/users_administration.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/sub_issue.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/security_advisories.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/secret_scanning_pattern_configs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/search.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/scim.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_traffic.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_tags.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_statuses.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_stats.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_rules.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_properties.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_prereceive_hooks.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_merging.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_lfs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_keys.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_invitations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_immutable_releases.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_hooks_deliveries.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_hooks_configuration.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_forks.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_environments.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...) (incl. internal retry path). |
| github/repos_deployment_protection_rules.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_deployment_branch_policies.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_contents.go | Propagates ctx via NewRequest(ctx, ...); updates redirect helper call sites. |
| github/repos_community_health.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_comments.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_collaborators.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_codeowners.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_autolinks.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_attestations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_actions_allowed.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/repos_actions_access.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/rate_limit.go | Moves bypass flag onto request context and updates NewRequest/Do call pattern. |
| github/pulls_reviewers.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/private_registries.go | Propagates ctx via NewRequest(ctx, ...) (with version option) and switches to Do(req, ...). |
| github/orgs_users_blocking.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_security_managers.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_rules.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_properties.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_personal_access_tokens.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_outside_collaborators.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_organization_properties.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_network_configurations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_issue_types.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_immutable_releases.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_hooks_deliveries.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_hooks_configuration.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_hooks.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_custom_repository_roles.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_credential_authorizations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_audit_log.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_attestations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/orgs_artifacts.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/migrations_user.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/migrations.go | Propagates ctx via NewRequest(ctx, ...); updates redirect helper call sites. |
| github/meta.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/markdown.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/licenses.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issues_timeline.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issues_milestones.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issues_events.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issues_comments.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issues_assignees.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/issue_import.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/interactions_repos.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/interactions_orgs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/gitignore.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/git_trees.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/git_tags.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/git_refs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/git_commits.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/git_blobs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/gists_comments.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_rules.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_properties.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_network_configurations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_manage_ghes_ssh.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_manage_ghes_maintenance.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_manage_ghes.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_licenses.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_code_security_and_analysis.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_budgets.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_audit_log_stream.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_audit_log.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_apps.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_app_installation.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/enterprise_actions_runners.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/emojis.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/dependency_graph_snapshots.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/dependency_graph.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/dependabot_alerts.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/credentials.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/codespaces_machines.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/codesofconduct.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/classroom.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/authorizations.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/apps_marketplace.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/apps_manifest.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/apps_installation.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/apps_hooks_deliveries.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/apps_hooks.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/admin_users.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/admin_stats.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/admin_orgs.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/admin.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/activity_watching.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/activity_star.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/activity.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/actions_workflows.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...) (incl. helper). |
| github/actions_workflow_jobs.go | Propagates ctx via NewRequest(ctx, ...); updates redirect helper call sites. |
| github/actions_oidc.go | Propagates ctx via NewRequest(ctx, ...) and switches to Do(req, ...). |
| github/actions_artifacts.go | Propagates ctx via NewRequest(ctx, ...); updates redirect helper call sites. |
| CONTRIBUTING.md | Updates example code to pass ctx into NewRequest. |
Comments suppressed due to low confidence (2)
tools/extraneousnew/extraneousnew.go:1
- The analyzer now only recognizes
Docalls with 2 arguments. Iftools/extraneousnewis intended to be resilient across mixed call sites (or to analyze older code/tests), consider supporting bothDo(ctx, req, v)andDo(req, v)by accepting both arities and selecting the correct target argument (arg[2] vs arg[1]).
github/rate_limit.go:1 - The comment says the resource is not subject to rate limits, but the bypass flag is now only applied when rate-limit checks are enabled. Consider clarifying the comment to reflect that the bypass is only relevant when
DisableRateLimitCheckis false (or alternatively apply the bypass unconditionally if that matches prior semantics).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| u := fmt.Sprintf("repos/%v/%v", owner, repo) | ||
| req, err := s.client.NewRequest("GET", u, nil) | ||
| req, err := s.client.NewRequest(ctx, "GET", u, nil) | ||
| ... |
There was a problem hiding this comment.
The CONTRIBUTING example was updated to pass ctx into NewRequest, but it no longer demonstrates how to execute the request with the new Do(req, v) signature. Consider extending the snippet to include the corresponding Do(req, ...) call so contributors don’t keep copying the older Do(ctx, req, ...) pattern.
| ... | |
| if err != nil { | |
| return nil, nil, err | |
| } | |
| repository := new(Repository) | |
| resp, err := s.client.Do(req, repository) | |
| if err != nil { | |
| return nil, resp, err | |
| } | |
| return repository, resp, nil |
No description provided.