state

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state provides a GitHub API-based implementation of GitStateManager.

Package state manages persistent state using a dedicated Git branch. It uses the GitHub API to read/write files without local checkout.

Index

Constants

View Source
const (
	// DefaultStateBranch is the name of the orphan branch used for state.
	DefaultStateBranch = "simili-state"

	// PendingDir is the directory for pending actions.
	PendingDir = "pending"
)

Variables

This section is empty.

Functions

func MarshalAction

func MarshalAction(action *PendingAction) ([]byte, error)

MarshalAction serializes a pending action to JSON.

Types

type ActionType

type ActionType string

ActionType defines the type of pending action.

const (
	ActionTransfer ActionType = "transfer"
	ActionClose    ActionType = "close"
)

type GitHubStateManager

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

GitHubStateManager implements GitStateManager using the GitHub API. It reads/writes files to a dedicated orphan branch without local checkout.

func NewGitHubStateManager

func NewGitHubStateManager(token, org, repo string) *GitHubStateManager

NewGitHubStateManager creates a new GitHub-based state manager.

func (*GitHubStateManager) DeletePendingAction

func (m *GitHubStateManager) DeletePendingAction(ctx context.Context, org, repo string, issueNumber int) error

DeletePendingAction removes a pending action.

func (*GitHubStateManager) GetPendingAction

func (m *GitHubStateManager) GetPendingAction(ctx context.Context, org, repo string, issueNumber int) (*PendingAction, error)

GetPendingAction retrieves a pending action for an issue.

func (*GitHubStateManager) ListPendingActions

func (m *GitHubStateManager) ListPendingActions(ctx context.Context, actionType ActionType) ([]*PendingAction, error)

ListPendingActions lists all pending actions of a given type.

func (*GitHubStateManager) SetPendingAction

func (m *GitHubStateManager) SetPendingAction(ctx context.Context, action *PendingAction) error

SetPendingAction stores a pending action.

func (*GitHubStateManager) WithBranch

func (m *GitHubStateManager) WithBranch(branch string) *GitHubStateManager

WithBranch sets a custom state branch name.

type GitStateManager

type GitStateManager interface {
	// GetPendingAction retrieves a pending action for an issue.
	// Returns nil, nil if no action exists.
	GetPendingAction(ctx context.Context, org, repo string, issueNumber int) (*PendingAction, error)

	// SetPendingAction stores a pending action for an issue.
	SetPendingAction(ctx context.Context, action *PendingAction) error

	// DeletePendingAction removes a pending action for an issue.
	DeletePendingAction(ctx context.Context, org, repo string, issueNumber int) error

	// ListPendingActions lists all pending actions (optionally filtered by type).
	ListPendingActions(ctx context.Context, actionType ActionType) ([]*PendingAction, error)
}

GitStateManager defines the interface for state operations. This allows for different implementations (GitHub API, local git, etc.).

type PendingAction

type PendingAction struct {
	Type        ActionType        `json:"type"`
	Org         string            `json:"org"`
	Repo        string            `json:"repo"`
	IssueNumber int               `json:"issue_number"`
	Target      string            `json:"target"` // target repo for transfer, or original issue URL for close
	ScheduledAt time.Time         `json:"scheduled_at"`
	ExpiresAt   time.Time         `json:"expires_at"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

PendingAction represents a scheduled action stored in the state branch.

func UnmarshalAction

func UnmarshalAction(data []byte) (*PendingAction, error)

UnmarshalAction deserializes a pending action from JSON.

func (*PendingAction) IsExpired

func (a *PendingAction) IsExpired() bool

IsExpired checks if the action has expired.

Jump to

Keyboard shortcuts

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