githubapi

package
v0.3.0-20261118151855-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

GitHub API conventions

The parts of a GitHub API request that every direct caller would otherwise repeat:

  • SetRESTHeaders sets the JSON media type and pins the REST API version (Version), so every REST caller moves to a new version together. Pass it as platform/http.SendRequest's setHeaders.
  • QueryGraphQL posts a GraphQLRequest to /graphql and decodes the response's data into the caller's type. A non-200 reply is a platform/http.StatusError, so platform/errs/http classifies it like any other HTTP failure; a 200 reply that carries GraphQL errors fails even when it also carries data.

This package is not a client. Each caller keeps its own *http.Client (API root from platform/http.BaseURLTransport, auth from a transport) and its own typed requests and responses, and decides what a missing resource means for it.

Its Phabricator counterpart, platform/conduit, does hold a client, because Conduit reads the API token from the request body, where a transport cannot add it.

Who uses it

  • platform/githubactions and runway/extension/merger/github (REST)
  • submitqueue/extension/changeprovider/github and submitqueue/extension/validator/github (GraphQL)
  • test/testutil/githubtestrepo (REST)

Documentation

Overview

Package githubapi holds the request conventions shared by every component that calls the GitHub API directly: the REST headers, pinned to one API version, and the GraphQL request and response envelope.

It is not a client. Callers keep their own *http.Client, with the API root resolved by platform/http.BaseURLTransport and auth set by a transport, and their own typed requests; this package only removes the parts every caller would otherwise repeat.

Index

Constants

View Source
const Version = "2026-03-10"

Version is the GitHub REST API version every REST request pins.

Variables

This section is empty.

Functions

func QueryGraphQL

func QueryGraphQL(ctx context.Context, client *http.Client, req GraphQLRequest, data any) error

QueryGraphQL posts req to the client's /graphql and decodes the response's data into data. A non-200 reply is a *platform/http.StatusError, so error classifiers can read its code; a 200 reply that carries errors fails even when it also carries data. A null data leaves data untouched.

func SetRESTHeaders

func SetRESTHeaders(req *http.Request)

SetRESTHeaders sets the headers of a JSON request to the GitHub REST API. It has the signature platform/http.SendRequest takes for its setHeaders.

Types

type GraphQLRequest

type GraphQLRequest struct {
	// Query is the GraphQL document.
	Query string `json:"query"`
	// Variables binds the query's variables by name.
	Variables map[string]any `json:"variables"`
}

GraphQLRequest is the body of a request to the GitHub GraphQL API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL