ghissue

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ghissue wraps the gh CLI to create GitHub issues.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps the gh CLI. The zero value is not usable; use NewClient.

func NewClient

func NewClient() *Client

NewClient returns a Client backed by the real os/exec runner.

func NewClientWithRunner

func NewClientWithRunner(r CommandRunner, lookPath LookPathFunc) *Client

NewClientWithRunner returns a Client using the given runner and lookup function. Both must be non-nil. Used by tests.

func (*Client) Open

func (c *Client) Open(ctx context.Context, draft *Draft, repo string) (string, error)

Open invokes `gh issue create` to create a GitHub issue in repo.

repo must be in "owner/name" form. On success returns the URL of the new issue (the first http(s) line gh prints to stdout). Errors are returned as *CodedError so callers can branch on output.ErrorCode without string matching.

Error mapping:

  • gh not on PATH → ErrGhNotInstalled
  • exit code 4 → ErrGhNotAuthenticated (gh's auth-failure code)
  • any other non-zero → ErrIssueCreateFailed

type CodedError

type CodedError struct {
	Code    output.ErrorCode
	Message string
}

CodedError carries an output.ErrorCode alongside a human message so the CLI layer can map errors back into the JSON envelope without re-parsing.

func (*CodedError) Error

func (e *CodedError) Error() string

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args []string, stdin []byte) (stdout, stderr []byte, exitCode int, err error)
}

CommandRunner abstracts process execution so tests can inject fakes instead of spawning a real `gh` binary. stdin is piped to the child process; the returned stdout/stderr are the full captured streams. exitCode is the process exit status (0 on success); err is non-nil only for spawn/setup failures (a non-zero exit is reported via exitCode, not err).

type Draft

type Draft struct {
	Title     string   `json:"title"`
	Body      string   `json:"body"`
	Labels    []string `json:"labels,omitempty"`
	Assignees []string `json:"assignees,omitempty"`
}

Draft is the in-memory representation of a GitHub issue draft to be created via `gh issue create`. It is normally loaded from a JSON file written by a caller (a skill, an automation, or a human via editor).

Labels and Assignees are optional; when empty they are omitted from the `gh` invocation.

func LoadDraft

func LoadDraft(path string) (*Draft, error)

LoadDraft reads a JSON file from disk and decodes it into a Draft.

The file must contain a JSON object with at minimum a non-empty "title" field. An empty title is rejected because `gh issue create` would fail later with a less obvious error.

type LookPathFunc

type LookPathFunc func(file string) (string, error)

LookPathFunc resolves an executable on PATH. Override in tests.

Jump to

Keyboard shortcuts

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