issuelib

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package issuelib provides the core library for git-issue.

Index

Constants

View Source
const (
	ColorGreen = "\033[32m"
	ColorGray  = "\033[90m"
	ColorReset = "\033[0m"
)

ANSI color codes

Variables

This section is empty.

Functions

func ClosedRefForID

func ClosedRefForID(id int64) string

ClosedRefForID returns the ref path for a closed issue.

func Contains

func Contains(slice []string, item string) bool

Contains checks if a string slice contains a value.

func EditInEditor added in v0.0.19

func EditInEditor(initialContent string) (string, error)

EditInEditor opens the user's preferred editor with initial content and returns the edited content. Returns error if editor exits non-zero or if the content is empty/unchanged.

func FormatID

func FormatID(id int64) string

FormatID formats an issue ID as a 6-digit zero-padded string.

func FormatOneLiner

func FormatOneLiner(issue *Issue) string

FormatOneLiner formats an issue as a one-line summary.

func IDFromRef added in v0.0.18

func IDFromRef(ref string) (int64, error)

IDFromRef extracts the issue ID from a ref path.

func IsClosedRef

func IsClosedRef(ref string) bool

IsClosedRef returns true if the ref is for a closed issue.

func ParseID

func ParseID(s string) (int64, error)

ParseID parses an issue ID string to int64.

func RefForID

func RefForID(id int64) string

RefForID returns the ref path for an open issue.

func StatusColor

func StatusColor(status string) string

StatusColor returns the ANSI color code for a status.

func StatusFromRef

func StatusFromRef(ref string) string

StatusFromRef determines the status based on the ref path.

Types

type GitStore

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

GitStore implements Store using git refs and objects.

func NewGitStore

func NewGitStore() *GitStore

NewGitStore creates a new GitStore.

func NewGitStoreWithOutput

func NewGitStoreWithOutput(out io.Writer) *GitStore

NewGitStoreWithOutput creates a GitStore with custom output.

func (*GitStore) AddNote

func (s *GitStore) AddNote(commit, content string) error

AddNote adds a git note to a commit.

func (*GitStore) Create

func (s *GitStore) Create(title, description string) (*Issue, error)

Create creates a new issue.

func (*GitStore) Fetch

func (s *GitStore) Fetch(remote string, refspecs []string) error

Fetch fetches refs from a remote.

func (*GitStore) FindRef

func (s *GitStore) FindRef(id int64) (string, error)

FindRef finds the ref for an issue ID.

func (*GitStore) Get

func (s *GitStore) Get(id int64) (*Issue, string, error)

Get retrieves an issue by ID.

func (*GitStore) GetByRef

func (s *GitStore) GetByRef(ref string) (*Issue, string, error)

GetByRef retrieves an issue by ref.

func (*GitStore) GetCommitInfo

func (s *GitStore) GetCommitInfo(sha string) (string, error)

GetCommitInfo returns the short commit info.

func (*GitStore) GetNextID

func (s *GitStore) GetNextID() (int64, error)

GetNextID allocates the next issue ID. It uses the higher of: (stored counter + 1) or (max existing ID + 1) to ensure IDs are never reused even if the counter is corrupted.

func (*GitStore) GetNotes

func (s *GitStore) GetNotes(commit string) (string, error)

GetNotes returns the git notes for a commit.

func (*GitStore) GetRefCommit added in v0.0.18

func (s *GitStore) GetRefCommit(ref string) (string, error)

GetRefCommit returns the commit SHA for a ref.

func (*GitStore) GetTree

func (s *GitStore) GetTree(ref string) (map[string]string, error)

GetTree reads the tree for a ref and returns entries.

func (*GitStore) List

func (s *GitStore) List(includeAll bool) ([]*Issue, error)

List returns all issues.

func (*GitStore) ListDir

func (s *GitStore) ListDir(ref, path string) (map[string]string, error)

ListDir lists directory contents at a path within a ref.

func (*GitStore) ListRefs

func (s *GitStore) ListRefs(includeAll bool) ([]string, error)

ListRefs returns all issue refs.

func (*GitStore) MoveRef

func (s *GitStore) MoveRef(from, to string) error

MoveRef moves an issue from one ref to another.

func (*GitStore) Out

func (s *GitStore) Out() io.Writer

func (*GitStore) Push

func (s *GitStore) Push(remote string, refspecs []string) error

Push pushes refs to a remote.

func (*GitStore) ReadFile

func (s *GitStore) ReadFile(ref, path string) ([]byte, error)

ReadFile reads a file from an issue's tree.

func (*GitStore) ReplaceTree added in v0.0.18

func (s *GitStore) ReplaceTree(ref, message string, files map[string][]byte) error

ReplaceTree replaces the entire tree with new files and creates a commit.

func (*GitStore) Update

func (s *GitStore) Update(issue *Issue, message string, extraFiles map[string]string) error

Update updates an issue's metadata.

func (*GitStore) VerifyCommit

func (s *GitStore) VerifyCommit(commit string) (string, error)

VerifyCommit verifies a commit exists.

func (*GitStore) VerifyRemote

func (s *GitStore) VerifyRemote(remote string) error

VerifyRemote checks if a remote exists.

type Issue

type Issue struct {
	ID            int64     `tony:"field=id"`
	Status        string    `tony:"field=status"`
	Created       time.Time `tony:"field=created"`
	Updated       time.Time `tony:"field=updated"`
	Commits       []string  `tony:"field=commits"`
	Branches      []string  `tony:"field=branches"`
	ClosedBy      *string   `tony:"field=closed_by, optional"`
	RelatedIssues []string  `tony:"field=related_issues"`
	Blocks        []string  `tony:"field=blocks"`
	BlockedBy     []string  `tony:"field=blocked_by"`
	Duplicates    []string  `tony:"field=duplicates"`
	Labels        []string  `tony:"field=labels"`

	// Derived fields (not serialized in meta.tony)
	Ref   string `tony:"-"` // The git ref (e.g., "refs/issues/000001")
	Title string `tony:"-"` // From description.md first line
}

func (*Issue) FromTony

func (s *Issue) FromTony(data []byte, opts ...gomap.UnmapOption) error

FromTony parses Tony format bytes and populates Issue.

func (*Issue) FromTonyIR

func (s *Issue) FromTonyIR(node *ir.Node, opts ...gomap.UnmapOption) error

FromTonyIR populates Issue from a Tony IR node.

func (*Issue) ToTony

func (s *Issue) ToTony(opts ...gomap.MapOption) ([]byte, error)

ToTony converts Issue to Tony format bytes.

func (*Issue) ToTonyIR

func (s *Issue) ToTonyIR(opts ...gomap.MapOption) (*ir.Node, error)

ToTonyIR converts Issue to a Tony IR node.

type Store

type Store interface {
	// GetNextID allocates and returns the next issue ID.
	GetNextID() (int64, error)

	// Create creates a new issue with the given title and description.
	// Returns the created issue with ID populated.
	Create(title, description string) (*Issue, error)

	// Get retrieves an issue by ID, searching both open and closed refs.
	// Returns the issue, description content, and any error.
	Get(id int64) (*Issue, string, error)

	// GetByRef retrieves an issue by its git ref.
	// Returns the issue, description content, and any error.
	GetByRef(ref string) (*Issue, string, error)

	// FindRef finds the ref for an issue ID, checking both open and closed.
	// Returns the ref path or error if not found.
	FindRef(id int64) (string, error)

	// Update updates an issue's metadata and optionally additional files.
	// The issue.Ref must be set. The message is used for the commit.
	Update(issue *Issue, message string, extraFiles map[string]string) error

	// List returns all issues, optionally including closed ones.
	List(includeAll bool) ([]*Issue, error)

	// ListRefs returns all issue refs, optionally including closed ones.
	ListRefs(includeAll bool) ([]string, error)

	// MoveRef moves an issue from one ref to another (e.g., close issue).
	MoveRef(from, to string) error

	// ReadFile reads a file from an issue's tree.
	ReadFile(ref, path string) ([]byte, error)

	// ListDir lists directory contents at a path within a ref.
	// Returns a map of name -> "type:hash" (e.g., "blob:abc123" or "tree:def456").
	ListDir(ref, path string) (map[string]string, error)

	// GetRefCommit returns the commit SHA for a ref.
	GetRefCommit(ref string) (string, error)

	// GetCommitInfo returns the short commit info for a SHA.
	GetCommitInfo(sha string) (string, error)

	// VerifyCommit verifies a commit exists and returns its full SHA.
	VerifyCommit(commit string) (string, error)

	// AddNote adds a git note to a commit.
	AddNote(commit, content string) error

	// GetNotes returns the git notes for a commit.
	GetNotes(commit string) (string, error)

	// Push pushes refs to a remote.
	Push(remote string, refspecs []string) error

	// Fetch fetches refs from a remote.
	Fetch(remote string, refspecs []string) error

	// VerifyRemote checks if a remote exists.
	VerifyRemote(remote string) error

	// Out returns the output writer for this store.
	Out() io.Writer
}

Store defines the interface for issue storage operations.

Jump to

Keyboard shortcuts

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