ghcli

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrMissingProjectScope = errors.New("missing 'project' scope - run 'gh auth refresh -s project' to enable")

ErrMissingProjectScope is returned when the token lacks project scope

Functions

This section is empty.

Types

type BatchIssueUpdate added in v0.2.0

type BatchIssueUpdate struct {
	Number         string   // Issue number
	Title          *string  // New title (nil = no change)
	Body           *string  // New body (nil = no change)
	Milestone      *string  // New milestone title (nil = no change, empty string = remove)
	Labels         []string // Final set of labels (nil = no change)
	Assignees      []string // Final set of assignees (nil = no change)
	ClearMilestone bool     // If true, remove milestone
	ClearLabels    bool     // If true and Labels is nil, remove all labels
	ClearAssignees bool     // If true and Assignees is nil, remove all assignees
}

BatchIssueUpdate represents updates to apply to a single issue.

type BatchUpdateResult added in v0.2.0

type BatchUpdateResult struct {
	Updated []string          // Issue numbers that were updated
	Errors  map[string]string // Issue number -> error message
}

BatchUpdateResult contains the result of a batch update operation.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(runner Runner, repo string) *Client

func (*Client) AddBlockedBy

func (c *Client) AddBlockedBy(ctx context.Context, issueNumber string, blockingNumber string) error

AddBlockedBy adds a blocking relationship (issueNumber is blocked by blockingNumber).

func (*Client) AddToProject

func (c *Client) AddToProject(ctx context.Context, issueNumber string, projectID string) error

AddToProject adds an issue to a project. Returns nil if successful, or an error (including scope errors).

func (*Client) BatchEditIssues added in v0.2.0

func (c *Client) BatchEditIssues(ctx context.Context, updates []BatchIssueUpdate) (BatchUpdateResult, error)

BatchEditIssues updates multiple issues in a single GraphQL call. This is much faster than calling EditIssue for each issue individually. Note: This only handles title, body, milestone, labels, and assignees. State changes, relationships, issue types, and projects must be handled separately.

func (*Client) CloseIssue

func (c *Client) CloseIssue(ctx context.Context, number string, reason string) error

func (*Client) CreateComment

func (c *Client) CreateComment(ctx context.Context, issueNumber string, body string) error

CreateComment posts a comment on an issue.

func (*Client) CreateIssue

func (c *Client) CreateIssue(ctx context.Context, issue issue.Issue) (string, error)

func (*Client) CreateLabel

func (c *Client) CreateLabel(ctx context.Context, name, color string) error

CreateLabel creates a new label with the given name and color. Color should be a 6-character hex string without the # prefix.

func (*Client) CreateMilestone

func (c *Client) CreateMilestone(ctx context.Context, title string) error

CreateMilestone creates a new milestone with the given title.

func (*Client) EditIssue

func (c *Client) EditIssue(ctx context.Context, number string, change IssueChange) error

func (*Client) EnrichWithRelationships

func (c *Client) EnrichWithRelationships(ctx context.Context, iss *issue.Issue) error

EnrichWithRelationships fetches parent and blocking relationships for an issue via GraphQL and updates the issue in place.

func (*Client) EnrichWithRelationshipsBatch

func (c *Client) EnrichWithRelationshipsBatch(ctx context.Context, issues []issue.Issue) error

EnrichWithRelationshipsBatch fetches parent and blocking relationships for multiple issues in a single API call and updates each issue in place.

func (*Client) GetIssue

func (c *Client) GetIssue(ctx context.Context, number string) (issue.Issue, error)

func (*Client) GetIssueNodeID

func (c *Client) GetIssueNodeID(ctx context.Context, number string) (string, error)

GetIssueNodeID fetches the GraphQL node ID for an issue.

func (*Client) GetIssueRelationships

func (c *Client) GetIssueRelationships(ctx context.Context, number string) (IssueRelationships, string, error)

GetIssueRelationships fetches parent and blocking relationships for an issue via GraphQL.

func (*Client) GetIssueRelationshipsBatch

func (c *Client) GetIssueRelationshipsBatch(ctx context.Context, numbers []string) (map[string]IssueRelationships, error)

GetIssueRelationshipsBatch fetches parent and blocking relationships for multiple issues in a single GraphQL call. Returns a map of issue number -> relationships.

func (*Client) GetIssuesBatch

func (c *Client) GetIssuesBatch(ctx context.Context, numbers []string) (map[string]issue.Issue, error)

GetIssuesBatch fetches multiple issues in a single GraphQL call. Returns a map of issue number -> issue. Issues that don't exist are not included.

func (*Client) HasProjectScope

func (c *Client) HasProjectScope(ctx context.Context) (bool, error)

HasProjectScope checks if the current GitHub token has the 'project' scope.

func (*Client) ListIssueTypes

func (c *Client) ListIssueTypes(ctx context.Context) ([]IssueType, error)

ListIssueTypes fetches all issue types from the repository's organization. Issue types are an organization-level feature, so this queries the org that owns the repo. Returns an empty list (not an error) if issue types are not available.

func (*Client) ListIssues

func (c *Client) ListIssues(ctx context.Context, state string, labels []string) ([]issue.Issue, error)

func (*Client) ListIssuesWithRelationships

func (c *Client) ListIssuesWithRelationships(ctx context.Context, opts ListIssuesOptions) (ListIssuesResult, error)

ListIssuesWithRelationships fetches issues with their relationships and label colors using GraphQL with pagination. This is much faster than separate calls.

func (*Client) ListLabels

func (c *Client) ListLabels(ctx context.Context) ([]Label, error)

ListLabels fetches all labels from the repository with their colors. Uses the GitHub API with pagination to fetch all labels (gh label list is limited to 1000).

func (*Client) ListMilestones

func (c *Client) ListMilestones(ctx context.Context) ([]Milestone, error)

ListMilestones fetches all milestones from the repository.

func (*Client) ListProjects

func (c *Client) ListProjects(ctx context.Context) ([]Project, error)

ListProjects fetches all projects accessible from the repository. This includes both organization projects and user projects. Returns an empty list (not an error) if projects are not available or scope is missing.

func (*Client) RemoveBlockedBy

func (c *Client) RemoveBlockedBy(ctx context.Context, issueNumber string, blockingNumber string) error

RemoveBlockedBy removes a blocking relationship (issueNumber is no longer blocked by blockingNumber).

func (*Client) RemoveFromProject

func (c *Client) RemoveFromProject(ctx context.Context, issueNumber string, projectID string) error

RemoveFromProject removes an issue from a project. Returns nil if successful, or an error (including scope errors).

func (*Client) ReopenIssue

func (c *Client) ReopenIssue(ctx context.Context, number string) error

func (*Client) SetIssueType

func (c *Client) SetIssueType(ctx context.Context, issueNumber string, issueTypeID string) error

SetIssueType sets or clears the issue type for an issue. If issueTypeID is empty, the issue type is cleared.

func (*Client) SetParent

func (c *Client) SetParent(ctx context.Context, issueNumber string, parentNumber string) error

SetParent sets or removes the parent of an issue. If parentNumber is empty, the parent relationship is removed.

func (*Client) SetProgress

func (c *Client) SetProgress(fn func(ProgressEvent))

func (*Client) SyncProjects

func (c *Client) SyncProjects(ctx context.Context, issueNumber string, localProjects []string, knownProjects map[string]string) error

SyncProjects syncs the project memberships for an issue. It compares the desired state (from local issue) with the current remote state and adds/removes project memberships as needed. Returns nil on success. Scope errors are logged but don't cause failure.

func (*Client) SyncRelationships

func (c *Client) SyncRelationships(ctx context.Context, issueNumber string, local issue.Issue) error

SyncRelationships syncs the parent and blocking relationships for an issue. It compares the desired state (from local issue) with the current remote state and makes the necessary mutations.

type ExecRunner

type ExecRunner struct{}

func (ExecRunner) Run

func (ExecRunner) Run(ctx context.Context, name string, args ...string) (string, error)

type IssueChange

type IssueChange struct {
	Title           *string
	Body            *string
	Milestone       *string
	IssueType       *string
	AddProjects     []string
	RemoveProjects  []string
	AddLabels       []string
	RemoveLabels    []string
	AddAssignees    []string
	RemoveAssignees []string
	State           *string
	StateReason     *string
	StateTransition *string
	StateWasOpen    bool
	StateWasClosed  bool
	StateIsOpen     bool
	StateIsClosed   bool
}

IssueChange captures the edits we need to apply to an issue.

type IssueRelationships

type IssueRelationships struct {
	Parent    *issue.IssueRef
	BlockedBy []issue.IssueRef
	Blocks    []issue.IssueRef
	IssueType string
	Projects  []string
}

IssueRelationships holds the parent, blocking, issue type, and project data for an issue.

type IssueType

type IssueType struct {
	ID          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

IssueType represents a GitHub issue type (org-level).

type Label

type Label struct {
	Name  string
	Color string // Hex color without #
}

Label represents a GitHub label with its color.

type ListIssuesOptions

type ListIssuesOptions struct {
	State  string    // "open", "closed", or "all"
	Labels []string  // Filter by labels
	Since  time.Time // Only fetch issues updated after this time (zero means no filter)
}

ListIssuesOptions configures the ListIssuesWithRelationships query.

type ListIssuesResult

type ListIssuesResult struct {
	Issues      []issue.Issue
	LabelColors map[string]string
}

ListIssuesResult contains the result of ListIssuesWithRelationships

type Milestone

type Milestone struct {
	Title       string  `json:"title"`
	Description string  `json:"description"`
	DueOn       *string `json:"due_on"` // ISO 8601 format
	State       string  `json:"state"`  // open or closed
}

Milestone represents a GitHub milestone.

type ProgressEvent

type ProgressEvent struct {
	Stage      ProgressStage
	Page       int
	Issues     int
	PageIssues int
	Total      int
}

type ProgressStage

type ProgressStage string
const (
	ProgressListIssuesPageStart ProgressStage = "list_issues_page_start"
	ProgressListIssuesPageDone  ProgressStage = "list_issues_page_done"
)

type Project

type Project struct {
	ID    string `json:"id"`
	Title string `json:"title"`
}

Project represents a GitHub Project V2.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

Jump to

Keyboard shortcuts

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