Documentation
¶
Overview ¶
Package github provides a lightweight GitHub REST API client for cloop. It supports issue sync, PR listing, and comment creation without requiring external dependencies beyond the standard library.
Index ¶
- func CheckRunSummary(runs []CheckRun) string
- func DetectRepo() (string, error)
- func ParseRepoFromRemote(remote string) (string, error)
- type APIError
- type CheckRun
- type CheckRunsResponse
- type Client
- func (c *Client) AddComment(number int, body string) error
- func (c *Client) CloseIssue(number int) error
- func (c *Client) CreateIssue(title, body string, labels []string) (*Issue, error)
- func (c *Client) CreatePR(head, base, title, body string, draft bool) (*PR, error)
- func (c *Client) CreateRelease(tagName, name, body string, draft bool) (*GHRelease, error)
- func (c *Client) FindPRByHead(branch, state string) (*PR, error)
- func (c *Client) GetIssue(number int) (*Issue, error)
- func (c *Client) GetPR(number int) (*PR, error)
- func (c *Client) GetPRFiles(number int) ([]PRFile, error)
- func (c *Client) ListCheckRuns(sha string) ([]CheckRun, error)
- func (c *Client) ListIssues(state string, labels []string) ([]Issue, error)
- func (c *Client) ListPRs(state string) ([]PR, error)
- func (c *Client) UpdateIssue(number int, updates map[string]interface{}) error
- type GHMilestone
- type GHRelease
- type Issue
- type Label
- type PR
- type PRFile
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckRunSummary ¶
CheckRunSummary returns a one-line summary of check run results.
func DetectRepo ¶
DetectRepo tries to discover the owner/repo from the git remote in the current directory. It returns "owner/repo" or an error if not detectable.
func ParseRepoFromRemote ¶
ParseRepoFromRemote extracts "owner/repo" from a GitHub remote URL. Handles HTTPS (https://github.com/owner/repo.git) and SSH (git@github.com:owner/repo.git).
Types ¶
type APIError ¶ added in v0.0.3
APIError is a non-success answer from the GitHub API. It carries the status so callers can tell "this pull request already exists" (422) from "this token may not do that" (401/403) without matching on message text.
func (*APIError) Unprocessable ¶ added in v0.0.3
Unprocessable reports whether the API refused the request as invalid (422) — for a pull request, most often because one already exists for the head.
type CheckRun ¶
type CheckRun struct {
Name string `json:"name"`
Status string `json:"status"`
Conclusion string `json:"conclusion"`
HTMLURL string `json:"html_url"`
}
CheckRun represents a CI check result.
type CheckRunsResponse ¶
type CheckRunsResponse struct {
CheckRuns []CheckRun `json:"check_runs"`
}
CheckRunsResponse is the GitHub API response for check runs.
type Client ¶
type Client struct {
Token string
Repo string // owner/repo
BaseURL string // default: https://api.github.com
}
Client is a minimal GitHub REST API client.
func (*Client) AddComment ¶
AddComment adds a comment to an issue or PR.
func (*Client) CloseIssue ¶
CloseIssue closes an issue by number.
func (*Client) CreateIssue ¶
CreateIssue creates a new issue and returns it.
func (*Client) CreatePR ¶
CreatePR creates a new pull request and returns it. head is the branch containing the changes (e.g. "feature/my-branch"). base is the branch the PR should merge into (e.g. "main").
func (*Client) CreateRelease ¶
CreateRelease creates a GitHub release for the given tag. tagName is the git tag (e.g. "v1.2.3"), name is the release title, body is the markdown release notes. Set draft=false to publish immediately.
func (*Client) FindPRByHead ¶ added in v0.0.3
FindPRByHead returns the most recent pull request whose head is branch in the repository's own owner namespace, or nil when there is none. state is "open", "closed" or "all".
It exists because creating a pull request for a head that already has an open one is refused (422), and the useful answer to "open a PR for this branch" in that case is the PR that is already open.
func (*Client) GetPR ¶ added in v0.0.3
GetPR fetches one pull request, including whether it was merged.
func (*Client) GetPRFiles ¶
GetPRFiles returns the list of files changed in a pull request.
func (*Client) ListCheckRuns ¶
ListCheckRuns returns CI check runs for a commit SHA.
func (*Client) ListIssues ¶
ListIssues fetches issues from the repository. state: "open", "closed", or "all" labels: filter by label names (empty = no filter)
type GHMilestone ¶
type GHMilestone struct {
Title string `json:"title"`
}
GHMilestone represents a GitHub milestone attached to an issue.
type GHRelease ¶
type GHRelease struct {
ID int `json:"id"`
TagName string `json:"tag_name"`
Name string `json:"name"`
Body string `json:"body"`
HTMLURL string `json:"html_url"`
Draft bool `json:"draft"`
}
GHRelease represents a GitHub release.
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"`
Labels []Label `json:"labels"`
Assignees []User `json:"assignees"`
Milestone *GHMilestone `json:"milestone"`
UpdatedAt time.Time `json:"updated_at"`
// PullRequest is non-nil when this is actually a PR (issues endpoint returns both).
PullRequest *struct{} `json:"pull_request,omitempty"`
}
Issue represents a GitHub issue.
func (*Issue) LabelNames ¶
LabelNames returns a comma-separated list of label names.
type PR ¶
type PR struct {
Number int `json:"number"`
Title string `json:"title"`
State string `json:"state"`
Draft bool `json:"draft"`
HTMLURL string `json:"html_url"`
User User `json:"user"`
Labels []Label `json:"labels"`
Head struct {
Ref string `json:"ref"`
SHA string `json:"sha"`
} `json:"head"`
Base struct {
Ref string `json:"ref"`
} `json:"base"`
UpdatedAt time.Time `json:"updated_at"`
Body string `json:"body"`
// Merged and MergedAt are only populated by the single-PR endpoint
// (GetPR); list endpoints omit them, so a false Merged from ListPRs
// means "not reported", not "not merged".
Merged bool `json:"merged"`
MergedAt *time.Time `json:"merged_at"`
}
PR represents a GitHub pull request.
func (*PR) LabelNames ¶
LabelNames returns a comma-separated list of label names for a PR.