githubhttp

package
v0.3.32 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package githubhttp provides GitHub API-specific HTTP helpers shared across multiple packages (server, proxy, etc.).

Index

Constants

View Source
const GitHubUserAgent = "awmg/1.0"

GitHubUserAgent is the User-Agent header value sent on all GitHub API requests.

Variables

This section is empty.

Functions

func ApplyGitHubAPIHeaders

func ApplyGitHubAPIHeaders(req *http.Request, authHeader string)

ApplyGitHubAPIHeaders sets the standard GitHub API request headers on req. authHeader should be the full Authorization header value (e.g. "token xyz" or "******"). When authHeader is empty no Authorization header is set, which is appropriate when the caller has already decided that no auth is available.

func ComputeRetryAfter

func ComputeRetryAfter(resetAt time.Time) int

ComputeRetryAfter returns the number of seconds a client should wait before retrying after a rate-limit response. It accepts the parsed reset time from ParseRateLimitResetHeader. When resetAt is in the future the delay is clamped to [1, 3600] seconds. When resetAt is zero or already in the past a default of 60 seconds is returned.

func DoGitHubGET

func DoGitHubGET(ctx context.Context, apiBaseURL, path, authHeader string) (*http.Response, error)

DoGitHubGET sends an authenticated GET request to the GitHub API and returns the response. apiBaseURL is the API root (e.g. "https://api.github.com"), path is the request path (e.g. "/repos/owner/repo"), and authHeader is the full Authorization header value (e.g. "token xyz"). The caller is responsible for closing the response body. Request duration is bounded by whichever happens first: ctx cancellation/deadline or the helper client timeout.

func FetchCollaboratorPermission

func FetchCollaboratorPermission(
	ctx context.Context,
	owner, repo, username string,
	fetch func(ctx context.Context, apiPath string) (*http.Response, error),
	logPrintf func(format string, args ...interface{}),
) (interface{}, error)

FetchCollaboratorPermission executes a get_collaborator_permission REST call using the provided fetch function and returns the wrapped MCP text response.

The fetch callback should perform the authenticated HTTP request for the given API path and return the upstream response.

func LogAndWrapCollaboratorPermission

func LogAndWrapCollaboratorPermission(
	body []byte,
	owner, repo, username string,
	statusCode int,
	logPrintf func(format string, args ...interface{}),
) interface{}

LogAndWrapCollaboratorPermission parses the raw GitHub API response body for a get_collaborator_permission request, logs the resolved permission level for observability, and returns the body wrapped in MCP text-response format.

This helper is shared between the server and proxy packages to eliminate duplicated parse/log/wrap logic. Callers pass their own debug logger's Printf method so that log lines appear under the correct namespace.

func ParseCollaboratorPermissionArgs

func ParseCollaboratorPermissionArgs(argsMap map[string]interface{}) (owner, repo, username string, err error)

ParseCollaboratorPermissionArgs extracts and validates the owner, repo, and username fields from an args map for a get_collaborator_permission call. It returns the (possibly partial) values even on error so that callers can include them in diagnostic log messages.

func ParseRateLimitResetHeader

func ParseRateLimitResetHeader(value string) time.Time

ParseRateLimitResetHeader parses the Unix-timestamp value of the X-RateLimit-Reset HTTP header into a time.Time. Returns zero time when the header value is absent or malformed.

See also: parseRateLimitResetFromText in server/rate_limit.go, which parses the same timing information from MCP tool result text bodies instead of HTTP headers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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