state

package
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 7 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 persistence for sync profiles and history

Index

Constants

View Source
const (
	// StateFileName is the name of the state file
	StateFileName = "state.yaml"
	// ConfigDirName is the name of the config directory
	ConfigDirName = ".githubby"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedRepo

type CachedRepo struct {
	FullName   string    `yaml:"full_name"`
	Private    bool      `yaml:"private"`
	Language   string    `yaml:"language,omitempty"`
	Stars      int       `yaml:"stars"`
	LastSynced time.Time `yaml:"last_synced,omitempty"`
}

CachedRepo represents cached repository metadata

type RepoSyncResult

type RepoSyncResult struct {
	FullName string    `yaml:"full_name"`
	Status   string    `yaml:"status"` // "cloned", "updated", "skipped", "failed"
	SyncedAt time.Time `yaml:"synced_at"`
	Error    string    `yaml:"error,omitempty"`
}

RepoSyncResult represents the result of syncing a single repository

type State

type State struct {
	Version            int            `yaml:"version"`
	OnboardingComplete bool           `yaml:"onboarding_complete,omitempty"`
	DefaultTargetDir   string         `yaml:"default_target_dir,omitempty"`
	DefaultUsername    string         `yaml:"default_username,omitempty"`
	Profiles           []*SyncProfile `yaml:"profiles"`
	SyncHistory        []*SyncRecord  `yaml:"sync_history"`
	RepoCache          []*CachedRepo  `yaml:"repo_cache,omitempty"`
}

State represents the persisted application state

func NewState

func NewState() *State

NewState creates a new empty state

func (*State) AddProfile

func (s *State) AddProfile(profile *SyncProfile)

AddProfile adds a sync profile to the state

func (*State) AddSyncRecord

func (s *State) AddSyncRecord(record *SyncRecord)

AddSyncRecord adds a sync record to history

func (*State) DeleteProfile

func (s *State) DeleteProfile(id string) bool

DeleteProfile removes a profile by ID and its associated sync history

func (*State) GetCachedRepo

func (s *State) GetCachedRepo(fullName string) *CachedRepo

GetCachedRepo returns a cached repo by full name

func (*State) GetLatestSyncForProfile

func (s *State) GetLatestSyncForProfile(profileID string) *SyncRecord

GetLatestSyncForProfile returns the most recent sync record for a profile

func (*State) GetProfile

func (s *State) GetProfile(id string) *SyncProfile

GetProfile returns a profile by ID

func (*State) GetProfileByName

func (s *State) GetProfileByName(name string) *SyncProfile

GetProfileByName returns a profile by name

func (*State) GetSyncStats

func (s *State) GetSyncStats() SyncStats

GetSyncStats returns aggregate statistics from all sync history

func (*State) UpdateProfile

func (s *State) UpdateProfile(profile *SyncProfile) bool

UpdateProfile updates an existing profile

func (*State) UpdateRepoCache

func (s *State) UpdateRepoCache(repo *CachedRepo)

UpdateRepoCache updates or adds a repo to the cache

type Storage

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

Storage handles state persistence

func NewStorage

func NewStorage() (*Storage, error)

NewStorage creates a new storage instance with the default path

func NewStorageWithPath

func NewStorageWithPath(filePath string) *Storage

NewStorageWithPath creates a new storage instance with a custom path

func (*Storage) AddProfile

func (s *Storage) AddProfile(profile *SyncProfile) error

AddProfile adds a profile and saves

func (*Storage) AddSyncRecord

func (s *Storage) AddSyncRecord(record *SyncRecord) error

AddSyncRecord adds a sync record and saves

func (*Storage) DeleteProfile

func (s *Storage) DeleteProfile(id string) error

DeleteProfile deletes a profile and saves

func (*Storage) GetCachedRepo

func (s *Storage) GetCachedRepo(fullName string) *CachedRepo

GetCachedRepo returns a cached repo by full name

func (*Storage) GetDefaultTargetDir

func (s *Storage) GetDefaultTargetDir() string

GetDefaultTargetDir returns the default target directory for syncing

func (*Storage) GetDefaultUsername

func (s *Storage) GetDefaultUsername() string

GetDefaultUsername returns the default GitHub username

func (*Storage) GetLatestSyncForProfile

func (s *Storage) GetLatestSyncForProfile(profileID string) *SyncRecord

GetLatestSyncForProfile returns the most recent sync for a profile

func (*Storage) GetProfile

func (s *Storage) GetProfile(id string) *SyncProfile

GetProfile returns a profile by ID

func (*Storage) GetProfileByName added in v1.0.12

func (s *Storage) GetProfileByName(name string) *SyncProfile

GetProfileByName returns a profile by name

func (*Storage) GetProfiles

func (s *Storage) GetProfiles() []*SyncProfile

GetProfiles returns all profiles

func (*Storage) GetRecentSyncHistory

func (s *Storage) GetRecentSyncHistory(n int) []*SyncRecord

GetRecentSyncHistory returns the most recent N sync records

func (*Storage) GetSyncHistory

func (s *Storage) GetSyncHistory() []*SyncRecord

GetSyncHistory returns all sync records

func (*Storage) GetSyncStats

func (s *Storage) GetSyncStats() SyncStats

GetSyncStats returns aggregate sync statistics

func (*Storage) IsOnboardingComplete

func (s *Storage) IsOnboardingComplete() bool

IsOnboardingComplete returns whether onboarding has been completed

func (*Storage) Load

func (s *Storage) Load() error

Load reads the state from disk

func (*Storage) Save

func (s *Storage) Save() error

Save writes the state to disk atomically

func (*Storage) SetDefaults

func (s *Storage) SetDefaults(targetDir, username string) error

SetDefaults sets the default target directory and username

func (*Storage) SetOnboardingComplete

func (s *Storage) SetOnboardingComplete(complete bool) error

SetOnboardingComplete marks onboarding as complete and saves

func (*Storage) State

func (s *Storage) State() *State

State returns the current state (read-only copy)

func (*Storage) UpdateProfile

func (s *Storage) UpdateProfile(profile *SyncProfile) error

UpdateProfile updates a profile and saves

func (*Storage) UpdateProfileLastSync

func (s *Storage) UpdateProfileLastSync(profileID string) error

UpdateProfileLastSync updates the last sync time for a profile

func (*Storage) UpdateRepoCache

func (s *Storage) UpdateRepoCache(repo *CachedRepo) error

UpdateRepoCache updates the repo cache and saves

type SyncProfile

type SyncProfile struct {
	ID             string    `yaml:"id"`
	Name           string    `yaml:"name"`
	Type           string    `yaml:"type"`   // "user" or "org"
	Source         string    `yaml:"source"` // username or org name
	TargetDir      string    `yaml:"target_dir"`
	IncludePrivate bool      `yaml:"include_private"`
	SyncAllRepos   bool      `yaml:"sync_all_repos,omitempty"` // true = fetch all from API, false = use SelectedRepos
	SelectedRepos  []string  `yaml:"selected_repos,omitempty"` // specific repos (only used when SyncAllRepos is false)
	IncludeFilter  []string  `yaml:"include_filter,omitempty"` // glob patterns
	ExcludeFilter  []string  `yaml:"exclude_filter,omitempty"` // glob patterns
	CreatedAt      time.Time `yaml:"created_at"`
	LastSyncAt     time.Time `yaml:"last_sync_at,omitempty"`
}

SyncProfile represents a saved sync configuration

func NewProfile

func NewProfile(name, profileType, source, targetDir string, includePrivate bool) *SyncProfile

NewProfile creates a new sync profile with a generated ID

type SyncRecord

type SyncRecord struct {
	ProfileID   string            `yaml:"profile_id"`
	ProfileName string            `yaml:"profile_name"`
	StartedAt   time.Time         `yaml:"started_at"`
	CompletedAt time.Time         `yaml:"completed_at"`
	TotalRepos  int               `yaml:"total_repos"`
	Cloned      int               `yaml:"cloned"`
	Updated     int               `yaml:"updated"`
	Skipped     int               `yaml:"skipped"`
	Failed      int               `yaml:"failed"`
	Archived    int               `yaml:"archived"` // repos that exist locally but not on remote (preserved)
	Results     []*RepoSyncResult `yaml:"results,omitempty"`
}

SyncRecord represents a completed sync operation

func NewSyncRecord

func NewSyncRecord(profileID, profileName string) *SyncRecord

NewSyncRecord creates a new sync record

func (*SyncRecord) AddResult

func (r *SyncRecord) AddResult(fullName, status, errorMsg string)

AddResult adds a repository sync result to the record

func (*SyncRecord) Complete

func (r *SyncRecord) Complete()

Complete marks a sync record as completed and updates statistics

type SyncStats

type SyncStats struct {
	TotalSyncs    int
	TotalCloned   int
	TotalUpdated  int
	TotalSkipped  int
	TotalFailed   int
	TotalArchived int
	LastSync      time.Time
}

SyncStats provides aggregate sync statistics

func (SyncStats) TotalReposSynced

func (ss SyncStats) TotalReposSynced() int

TotalReposSynced returns the total number of repos successfully synced

Jump to

Keyboard shortcuts

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