github

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRunSummary

func CheckRunSummary(runs []CheckRun) string

CheckRunSummary returns a one-line summary of check run results.

func DetectRepo

func DetectRepo() (string, error)

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

func ParseRepoFromRemote(remote string) (string, error)

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

type APIError struct {
	Status int
	Body   string
}

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) Error added in v0.0.3

func (e *APIError) Error() string

func (*APIError) Unprocessable added in v0.0.3

func (e *APIError) Unprocessable() bool

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 New

func New(token, repo string) *Client

New creates a new GitHub client. Token may be empty for public repos (read-only).

func (*Client) AddComment

func (c *Client) AddComment(number int, body string) error

AddComment adds a comment to an issue or PR.

func (*Client) CloseIssue

func (c *Client) CloseIssue(number int) error

CloseIssue closes an issue by number.

func (*Client) CreateIssue

func (c *Client) CreateIssue(title, body string, labels []string) (*Issue, error)

CreateIssue creates a new issue and returns it.

func (*Client) CreatePR

func (c *Client) CreatePR(head, base, title, body string, draft bool) (*PR, error)

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

func (c *Client) CreateRelease(tagName, name, body string, draft bool) (*GHRelease, error)

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

func (c *Client) FindPRByHead(branch, state string) (*PR, error)

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) GetIssue

func (c *Client) GetIssue(number int) (*Issue, error)

GetIssue fetches a single issue by number.

func (*Client) GetPR added in v0.0.3

func (c *Client) GetPR(number int) (*PR, error)

GetPR fetches one pull request, including whether it was merged.

func (*Client) GetPRFiles

func (c *Client) GetPRFiles(number int) ([]PRFile, error)

GetPRFiles returns the list of files changed in a pull request.

func (*Client) ListCheckRuns

func (c *Client) ListCheckRuns(sha string) ([]CheckRun, error)

ListCheckRuns returns CI check runs for a commit SHA.

func (*Client) ListIssues

func (c *Client) ListIssues(state string, labels []string) ([]Issue, error)

ListIssues fetches issues from the repository. state: "open", "closed", or "all" labels: filter by label names (empty = no filter)

func (*Client) ListPRs

func (c *Client) ListPRs(state string) ([]PR, error)

ListPRs lists pull requests. state: "open", "closed", "all"

func (*Client) UpdateIssue

func (c *Client) UpdateIssue(number int, updates map[string]interface{}) error

UpdateIssue updates an existing issue (title, body, state).

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) IsPR

func (i *Issue) IsPR() bool

IsPR returns true if this issue is actually a pull request.

func (*Issue) LabelNames

func (i *Issue) LabelNames() string

LabelNames returns a comma-separated list of label names.

type Label

type Label struct {
	Name  string `json:"name"`
	Color string `json:"color"`
}

Label represents a GitHub label.

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

func (p *PR) LabelNames() string

LabelNames returns a comma-separated list of label names for a PR.

type PRFile

type PRFile struct {
	Filename string `json:"filename"`
	Status   string `json:"status"` // added, modified, removed, renamed
	Changes  int    `json:"changes"`
}

PRFile represents a file changed in a pull request.

type User

type User struct {
	Login string `json:"login"`
}

User represents a GitHub user.

Jump to

Keyboard shortcuts

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