Skip to content

refactor(platform): Share the GitHub REST headers and GraphQL envelope through platform/githubapi - #1012

Draft
roychying wants to merge 1 commit into
mainfrom
chenghan.ying/platform-github
Draft

roychying wants to merge 1 commit into
mainfrom
chenghan.ying/platform-github

Conversation

@roychying

Copy link
Copy Markdown
Contributor

Why?

Five callers of the GitHub API each repeat the same request plumbing. The REST callers copy the same three headers and their own pin of the API version, so a version bump has to find every copy. The two GraphQL callers each define their own request, response and error types and their own send-and-decode code, and the copies have already drifted: one calls client.Do directly, the other goes through platform/http.SendRequest.

The endpoint methods stay with each caller: no endpoint has two callers, each reads statuses its own way, and one GraphQL query per caller keeps its GitHub App permissions minimal. An endpoint group can be moved to platform when a second extension calls it.

What?

  • New platform/githubapi:
    • SetRESTHeaders sets the JSON media type and pins the REST API version in one Version constant.
    • QueryGraphQL posts a GraphQLRequest to /graphql and decodes data into the caller's type. A non-200 reply is a platform/http.StatusError, so platform/errs/http classifies it as before. A 200 reply with GraphQL errors fails even when it also carries data.
    • It is not a client: callers keep their own *http.Client and typed requests.
  • Moved onto it: platform/githubactions, runway/extension/merger/github and test/testutil/githubtestrepo (REST), and submitqueue/extension/changeprovider/github and submitqueue/extension/validator/github (GraphQL).
  • The request headers, API version and error classification are unchanged. A GraphQL error now reads GraphQL errors: TYPE: message; … instead of a struct dump.

Test Plan

bazel test //platform/githubapi/... //platform/githubactions/... //runway/extension/merger/github/... //submitqueue/extension/changeprovider/github/... //submitqueue/extension/validator/github/... //submitqueue/extension/buildrunner/githubactions/... //stovepipe/extension/buildrunner/githubactions/...

Issue

…e through platform/githubapi instead of repeating them in each GitHub caller

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant