Documentation
¶
Overview ¶
Package github is a minimal GitHub REST client used by `af github` commands.
Index ¶
- Variables
- type APIError
- type Client
- func (c *Client) AddLabels(ctx context.Context, owner, repo string, number int, labels []string) ([]Label, error)
- func (c *Client) CreateIssue(ctx context.Context, owner, repo string, input CreateIssueInput) (*Issue, error)
- func (c *Client) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*Comment, error)
- func (c *Client) GetAuthenticatedUser(ctx context.Context) (*User, error)
- func (c *Client) GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)
- func (c *Client) GetRepo(ctx context.Context, owner, repo string) (*Repo, error)
- func (c *Client) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)
- func (c *Client) ListIssues(ctx context.Context, owner, repo string, opts ListIssuesOptions) ([]Issue, error)
- func (c *Client) ListLabels(ctx context.Context, owner, repo string) ([]Label, error)
- func (c *Client) SetAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, error)
- func (c *Client) UpdateIssue(ctx context.Context, owner, repo string, number int, input UpdateIssueInput) (*Issue, error)
- type Comment
- type CreateIssueInput
- type GitHub
- type Issue
- type Label
- type ListIssuesOptions
- type Milestone
- type Repo
- type UpdateIssueInput
- type User
Constants ¶
This section is empty.
Variables ¶
var ErrForbidden = errors.New("github: forbidden — token lacks required scope")
ErrForbidden is returned when the authenticated identity lacks permission.
var ErrNotFound = errors.New("github: not found")
ErrNotFound is returned when a GitHub resource does not exist.
ErrUnauthorized is returned when the request is rejected due to authentication.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Message string `json:"message"`
DocURL string `json:"documentation_url"`
}
APIError represents an error response from the GitHub REST API.
type Client ¶
type Client struct {
BaseURL string
// contains filtered or unexported fields
}
Client is a minimal GitHub REST API client. It uses a personal access token or GitHub App installation token for authentication.
Authentication:
- Personal access token (classic or fine-grained): set GITHUB_TOKEN env var. All requests are sent with "Authorization: Bearer <token>".
- GitHub App installation token: obtained via the app's private-key JWT flow; same Bearer header format. Use NewClientWithToken to supply it directly.
The client targets GitHub's REST API v3 (api.github.com). No external dependencies beyond the Go standard library are needed.
func NewClient ¶
NewClient creates a Client authenticated with the given personal access token or GitHub App installation token.
func NewProxiedClient ¶
NewProxiedClient creates a GitHub client that routes REST requests through the platform's /api/cli/github/rest proxy. The platform authenticates the request via the rsk_ token and forwards it under the org's GitHub App installation credential.
baseURL is the platform's base URL (e.g. "https://app.rensei.ai"). token is the rsk_* session token from afclient.CredentialsFromDataSource.
func (*Client) AddLabels ¶
func (c *Client) AddLabels(ctx context.Context, owner, repo string, number int, labels []string) ([]Label, error)
AddLabels adds labels to an issue (non-destructive; existing labels are kept).
func (*Client) CreateIssue ¶
func (c *Client) CreateIssue(ctx context.Context, owner, repo string, input CreateIssueInput) (*Issue, error)
CreateIssue creates a new issue.
func (*Client) CreateIssueComment ¶
func (c *Client) CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*Comment, error)
CreateIssueComment posts a comment on an issue.
func (*Client) GetAuthenticatedUser ¶
GetAuthenticatedUser returns the currently authenticated user.
func (*Client) ListIssueComments ¶
func (c *Client) ListIssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)
ListIssueComments returns comments for an issue.
func (*Client) ListIssues ¶
func (c *Client) ListIssues(ctx context.Context, owner, repo string, opts ListIssuesOptions) ([]Issue, error)
ListIssues lists issues in a repository with optional filters.
func (*Client) ListLabels ¶
ListLabels lists all labels in a repository.
func (*Client) SetAssignees ¶
func (c *Client) SetAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, error)
SetAssignees replaces the assignees on an issue.
func (*Client) UpdateIssue ¶
func (c *Client) UpdateIssue(ctx context.Context, owner, repo string, number int, input UpdateIssueInput) (*Issue, error)
UpdateIssue updates an existing issue. Zero-value fields are omitted.
type Comment ¶
type Comment struct {
ID int64 `json:"id"`
Body string `json:"body"`
User *User `json:"user"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Comment represents a GitHub issue comment.
type CreateIssueInput ¶
type CreateIssueInput struct {
Title string `json:"title"`
Body string `json:"body,omitempty"`
Labels []string `json:"labels,omitempty"`
Assignees []string `json:"assignees,omitempty"`
Milestone *int `json:"milestone,omitempty"`
}
CreateIssueInput holds the fields for creating a new issue.
type GitHub ¶
type GitHub interface {
// Issues — read
GetIssue(ctx context.Context, owner, repo string, number int) (*Issue, error)
ListIssues(ctx context.Context, owner, repo string, opts ListIssuesOptions) ([]Issue, error)
ListIssueComments(ctx context.Context, owner, repo string, number int) ([]Comment, error)
// Issues — write
CreateIssue(ctx context.Context, owner, repo string, input CreateIssueInput) (*Issue, error)
UpdateIssue(ctx context.Context, owner, repo string, number int, input UpdateIssueInput) (*Issue, error)
CreateIssueComment(ctx context.Context, owner, repo string, number int, body string) (*Comment, error)
AddLabels(ctx context.Context, owner, repo string, number int, labels []string) ([]Label, error)
SetAssignees(ctx context.Context, owner, repo string, number int, assignees []string) (*Issue, error)
// Repos
GetRepo(ctx context.Context, owner, repo string) (*Repo, error)
ListLabels(ctx context.Context, owner, repo string) ([]Label, error)
// Users
GetAuthenticatedUser(ctx context.Context) (*User, error)
}
GitHub is the interface satisfied by Client; inject this for testability.
type Issue ¶
type Issue struct {
Number int `json:"number"`
Title string `json:"title"`
Body string `json:"body"`
State string `json:"state"`
HTMLURL string `json:"html_url"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Labels []Label `json:"labels"`
Assignees []User `json:"assignees"`
User *User `json:"user"`
Milestone *Milestone `json:"milestone"`
Comments int `json:"comments"`
}
Issue represents a GitHub issue.
type Label ¶
type Label struct {
ID int64 `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Description string `json:"description"`
}
Label represents a GitHub label.
type ListIssuesOptions ¶
type ListIssuesOptions struct {
State string // "open", "closed", "all" (default: "open")
Labels string // comma-separated label names
Assignee string // username or "none" or "*"
Creator string // username
Milestone string // milestone number or "*" or "none"
Sort string // "created", "updated", "comments" (default: "created")
Direction string // "asc", "desc" (default: "desc")
Since string // ISO 8601 timestamp
PerPage int // max items (default: 30, max: 100)
Page int
}
ListIssuesOptions filters for listing issues.
type Milestone ¶
type Milestone struct {
Number int `json:"number"`
Title string `json:"title"`
State string `json:"state"`
}
Milestone represents a GitHub milestone.
type Repo ¶
type Repo struct {
FullName string `json:"full_name"`
Name string `json:"name"`
Description string `json:"description"`
HTMLURL string `json:"html_url"`
Private bool `json:"private"`
OpenIssues int `json:"open_issues_count"`
}
Repo represents a GitHub repository.
type UpdateIssueInput ¶
type UpdateIssueInput struct {
Title string `json:"title,omitempty"`
Body string `json:"body,omitempty"`
State string `json:"state,omitempty"` // "open" or "closed"
Labels []string `json:"labels,omitempty"`
Assignees []string `json:"assignees,omitempty"`
Milestone *int `json:"milestone,omitempty"`
}
UpdateIssueInput holds the fields that can be updated on an issue. Only non-zero / non-nil fields are sent.