Documentation
¶
Overview ¶
Package state provides persistence for sync profiles and history
Index ¶
- Constants
- type CachedRepo
- type RepoSyncResult
- type State
- func (s *State) AddProfile(profile *SyncProfile)
- func (s *State) AddSyncRecord(record *SyncRecord)
- func (s *State) DeleteProfile(id string) bool
- func (s *State) GetCachedRepo(fullName string) *CachedRepo
- func (s *State) GetLatestSyncForProfile(profileID string) *SyncRecord
- func (s *State) GetProfile(id string) *SyncProfile
- func (s *State) GetProfileByName(name string) *SyncProfile
- func (s *State) GetSyncStats() SyncStats
- func (s *State) UpdateProfile(profile *SyncProfile) bool
- func (s *State) UpdateRepoCache(repo *CachedRepo)
- type Storage
- func (s *Storage) AddProfile(profile *SyncProfile) error
- func (s *Storage) AddSyncRecord(record *SyncRecord) error
- func (s *Storage) DeleteProfile(id string) error
- func (s *Storage) GetCachedRepo(fullName string) *CachedRepo
- func (s *Storage) GetDefaultTargetDir() string
- func (s *Storage) GetDefaultUsername() string
- func (s *Storage) GetLatestSyncForProfile(profileID string) *SyncRecord
- func (s *Storage) GetProfile(id string) *SyncProfile
- func (s *Storage) GetProfiles() []*SyncProfile
- func (s *Storage) GetRecentSyncHistory(n int) []*SyncRecord
- func (s *Storage) GetSyncHistory() []*SyncRecord
- func (s *Storage) GetSyncStats() SyncStats
- func (s *Storage) IsOnboardingComplete() bool
- func (s *Storage) Load() error
- func (s *Storage) Save() error
- func (s *Storage) SetDefaults(targetDir, username string) error
- func (s *Storage) SetOnboardingComplete(complete bool) error
- func (s *Storage) State() *State
- func (s *Storage) UpdateProfile(profile *SyncProfile) error
- func (s *Storage) UpdateProfileLastSync(profileID string) error
- func (s *Storage) UpdateRepoCache(repo *CachedRepo) error
- type SyncProfile
- type SyncRecord
- type SyncStats
Constants ¶
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 (*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 ¶
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 ¶
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 ¶
NewStorage creates a new storage instance with the default path
func NewStorageWithPath ¶
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 ¶
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 ¶
GetDefaultTargetDir returns the default target directory for syncing
func (*Storage) GetDefaultUsername ¶
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) 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 ¶
GetSyncStats returns aggregate sync statistics
func (*Storage) IsOnboardingComplete ¶
IsOnboardingComplete returns whether onboarding has been completed
func (*Storage) SetDefaults ¶
SetDefaults sets the default target directory and username
func (*Storage) SetOnboardingComplete ¶
SetOnboardingComplete marks onboarding as complete and saves
func (*Storage) UpdateProfile ¶
func (s *Storage) UpdateProfile(profile *SyncProfile) error
UpdateProfile updates a profile and saves
func (*Storage) UpdateProfileLastSync ¶
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 ¶
TotalReposSynced returns the total number of repos successfully synced