Documentation
¶
Index ¶
- Constants
- Variables
- func BaseURL() string
- func CheckResponse(resp *http.Response) error
- func DecodeJSON(resp *http.Response, dest any) error
- func IsHTTPErrorStatus(err error, status int) bool
- func RequireSecureURL(baseURL string) error
- func ResolveURL(path string) (string, error)
- func ResolveURLFromBase(baseURL, path string) (string, error)
- type Client
- func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) GetStream(ctx context.Context, path string, headers http.Header) (*http.Response, error)
- func (c *Client) ListRepositories(ctx context.Context, sort RepositorySort) ([]Repository, error)
- func (c *Client) ListTokens(ctx context.Context) ([]Token, error)
- func (c *Client) Patch(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) Put(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) RevokeCurrentToken(ctx context.Context) error
- func (c *Client) RevokeToken(ctx context.Context, id string) error
- type ErrorResponse
- type HTTPError
- type RepositoriesResponse
- type Repository
- type RepositorySort
- type Token
- type TokensResponse
- type TrailCreateRequest
- type TrailCreateResponse
- type TrailDetailResponse
- type TrailListResponse
- type TrailResource
- type TrailUpdateRequest
- type TrailUpdateResponse
Constants ¶
const ( // DefaultBaseURL is the production Entire API origin. DefaultBaseURL = "https://entire.io" // BaseURLEnvVar overrides the Entire API origin for local development. BaseURLEnvVar = "ENTIRE_API_BASE_URL" )
Variables ¶
var ErrInsecureHTTP = errors.New("refusing to use insecure http:// base URL for authentication (use --insecure-http-auth to override)")
ErrInsecureHTTP is returned when the base URL uses HTTP without an explicit opt-in.
Functions ¶
func BaseURL ¶
func BaseURL() string
BaseURL returns the effective Entire API base URL. ENTIRE_API_BASE_URL takes precedence over the production default.
func CheckResponse ¶ added in v0.5.2
CheckResponse returns an error if the response status code indicates failure. For non-2xx responses, it reads and parses the error message from the body and returns it as an *HTTPError. The caller is responsible for closing resp.Body.
func DecodeJSON ¶ added in v0.5.2
DecodeJSON reads the response body and decodes it into dest. It limits the body size to protect against unbounded reads. The caller is responsible for closing resp.Body.
func IsHTTPErrorStatus ¶ added in v0.6.0
IsHTTPErrorStatus reports whether err wraps an *HTTPError with the given HTTP status.
func RequireSecureURL ¶
RequireSecureURL returns ErrInsecureHTTP if the base URL uses the http scheme. Call this before making authenticated requests unless --insecure-http-auth is set.
func ResolveURL ¶
ResolveURL joins an API-relative path against the effective base URL.
func ResolveURLFromBase ¶
ResolveURLFromBase joins an API-relative path against an explicit base URL. Only http and https schemes are accepted.
Types ¶
type Client ¶ added in v0.5.2
type Client struct {
// contains filtered or unexported fields
}
Client is an authenticated HTTP client for the Entire API. It attaches the bearer token to all outgoing requests via the Authorization header.
func NewClient ¶ added in v0.5.2
NewClient creates a new authenticated API client with an explicit bearer token.
func (*Client) Delete ¶ added in v0.5.2
Delete sends an authenticated DELETE request to the given API-relative path.
func (*Client) Get ¶ added in v0.5.2
Get sends an authenticated GET request to the given API-relative path.
func (*Client) GetStream ¶ added in v0.6.2
func (c *Client) GetStream(ctx context.Context, path string, headers http.Header) (*http.Response, error)
GetStream sends an authenticated GET request with optional extra request headers (e.g. Accept: text/event-stream, Last-Event-ID) and returns the response with the body still open. Callers are responsible for reading and closing resp.Body. Intended for streaming endpoints such as Server-Sent Events; for normal JSON requests use Get.
func (*Client) ListRepositories ¶ added in v0.5.6
func (c *Client) ListRepositories(ctx context.Context, sort RepositorySort) ([]Repository, error)
ListRepositories lists the authenticated user's repositories. An empty sort uses the server default.
func (*Client) ListTokens ¶ added in v0.6.0
ListTokens returns the authenticated user's non-expired API tokens. Backed by GET /api/v1/auth/tokens.
func (*Client) Patch ¶ added in v0.5.2
Patch sends an authenticated PATCH request with a JSON body to the given API-relative path.
func (*Client) Post ¶ added in v0.5.2
Post sends an authenticated POST request with a JSON body to the given API-relative path.
func (*Client) Put ¶ added in v0.5.2
Put sends an authenticated PUT request with a JSON body to the given API-relative path.
func (*Client) RevokeCurrentToken ¶ added in v0.6.0
RevokeCurrentToken revokes the bearer token used to authenticate this client. Backed by DELETE /api/v1/auth/tokens/current.
type ErrorResponse ¶ added in v0.5.2
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse represents a standard API error response.
type HTTPError ¶ added in v0.6.0
HTTPError is returned by CheckResponse for non-2xx responses. Callers can use errors.As to inspect the HTTP status, or IsHTTPErrorStatus for a quick check.
type RepositoriesResponse ¶ added in v0.5.6
type RepositoriesResponse struct {
Repositories []Repository `json:"repositories"`
}
RepositoriesResponse is the envelope returned by GET /api/v1/repositories.
type Repository ¶ added in v0.5.6
type Repository struct {
FullName string `json:"full_name"`
CheckpointCount int `json:"checkpoint_count"`
}
Repository is a single entry returned by GET /api/v1/repositories. Only fields currently consumed by callers are decoded; extras are ignored.
type RepositorySort ¶ added in v0.5.6
type RepositorySort string
const ( RepositorySortRecent RepositorySort = "recent" RepositorySortName RepositorySort = "name" )
type Token ¶ added in v0.6.0
type Token struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Scope string `json:"scope"`
ExpiresAt string `json:"expires_at"`
LastUsedAt *string `json:"last_used_at"`
CreatedAt string `json:"created_at"`
}
Token is a single API token row returned by GET /api/v1/auth/tokens. Plaintext token values are never returned by the server — only metadata.
type TokensResponse ¶ added in v0.6.0
type TokensResponse struct {
Tokens []Token `json:"tokens"`
}
TokensResponse is the envelope returned by GET /api/v1/auth/tokens.
type TrailCreateRequest ¶ added in v0.5.2
type TrailCreateRequest struct {
Title string `json:"title"`
Body string `json:"body,omitempty"`
BranchName string `json:"branch_name"`
Base string `json:"base,omitempty"`
Status string `json:"status,omitempty"`
Assignees []string `json:"assignees,omitempty"`
Labels []string `json:"labels,omitempty"`
Priority string `json:"priority,omitempty"`
Type string `json:"type,omitempty"`
}
TrailCreateRequest is the body for POST /api/v1/trails/:host/:owner/:repo.
type TrailCreateResponse ¶ added in v0.5.2
type TrailCreateResponse struct {
Trail TrailResource `json:"trail"`
BranchCreated bool `json:"branch_created"`
}
TrailCreateResponse is the response from POST /api/v1/trails/:org/:repo.
type TrailDetailResponse ¶ added in v0.5.2
type TrailDetailResponse struct {
Trail TrailResource `json:"trail"`
Discussion trail.Discussion `json:"discussion"`
Checkpoints trail.Checkpoints `json:"checkpoints"`
}
TrailDetailResponse is the response from GET /api/v1/trails/:org/:repo/:trailId.
type TrailListResponse ¶ added in v0.5.2
type TrailListResponse struct {
Trails []TrailResource `json:"trails"`
RepoFullName string `json:"repo_full_name"`
DefaultBranch string `json:"default_branch"`
UpdatedAt time.Time `json:"updated_at"`
}
TrailListResponse is the response from GET /api/v1/trails/:org/:repo.
type TrailResource ¶ added in v0.5.2
type TrailResource struct {
Number int `json:"number,omitempty"`
TrailID string `json:"trail_id"`
Branch string `json:"branch"`
Base string `json:"base"`
Title string `json:"title"`
Body string `json:"body"`
Status string `json:"status"`
Author *trail.Author `json:"author"`
Assignees []string `json:"assignees"`
Labels []string `json:"labels"`
Priority string `json:"priority,omitempty"`
Type string `json:"type,omitempty"`
Reviewers []trail.Reviewer `json:"reviewers,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MergedAt *time.Time `json:"merged_at,omitempty"`
CommentCount int `json:"comment_count,omitempty"`
UnresolvedCount int `json:"unresolved_count,omitempty"`
CheckpointCount int `json:"checkpoint_count,omitempty"`
CommitsAhead int `json:"commits_ahead,omitempty"`
}
TrailResource represents a single trail from the API.
func (*TrailResource) ToMetadata ¶ added in v0.5.2
func (r *TrailResource) ToMetadata() *trail.Metadata
ToMetadata converts a TrailResource to a trail.Metadata for display.
type TrailUpdateRequest ¶ added in v0.5.2
type TrailUpdateRequest struct {
Branch *string `json:"branch,omitempty"`
Base *string `json:"base,omitempty"`
Status *string `json:"status,omitempty"`
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Assignees *[]string `json:"assignees,omitempty"`
Labels *[]string `json:"labels,omitempty"`
Priority *string `json:"priority,omitempty"`
Type *string `json:"type,omitempty"`
}
TrailUpdateRequest is the body for PATCH /api/v1/trails/:host/:owner/:repo/:trailId. Pointer fields distinguish "not provided" (nil) from "set to value". For slices, *[]string is used so nil means "no change" while &[]string{} means "clear".
type TrailUpdateResponse ¶ added in v0.5.2
type TrailUpdateResponse struct {
Trail TrailResource `json:"trail"`
}
TrailUpdateResponse is the response from PATCH /api/v1/trails/:org/:repo/:trailId.