sync

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sync provides repository synchronization functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GistsDir added in v1.1.1

func GistsDir(target, login string) string

GistsDir returns where a user's gists live under target. It sits next to <login>/, not in it, so a repo named "gists" can't clash with it.

func IsRepoNotFound added in v1.1.1

func IsRepoNotFound(err error) bool

IsRepoNotFound reports whether a git error means the remote repo does not exist

func WikiPath added in v1.1.1

func WikiPath(target string, repo *gh.Repository) string

WikiPath returns where a repo's wiki lives under target

func WikiURL added in v1.1.1

func WikiURL(repo *gh.Repository) string

WikiURL returns the clone URL of a repo's wiki

Types

type Account added in v1.1.1

type Account struct {
	// Login is the user whose repos were listed
	Login string
	// Orgs are the orgs the token's account belongs to
	Orgs []string
	// Repos of the user and of every org that could be listed
	Repos []*gh.Repository
	// Failed holds orgs whose repos could not be listed, keyed by org name
	Failed map[string]error
}

Account is everything one token's account owns: its own repos plus its orgs' repos

type GitRetryConfig added in v1.0.19

type GitRetryConfig struct {
	// MaxAttempts is the total number of attempts (initial + retries)
	MaxAttempts int
	// InitialDelay is the delay before the first retry
	InitialDelay time.Duration
	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration
	// Multiplier is the exponential backoff multiplier
	Multiplier float64
}

GitRetryConfig configures retry behavior for git operations

func DefaultGitRetryConfig added in v1.0.19

func DefaultGitRetryConfig() *GitRetryConfig

DefaultGitRetryConfig returns sensible defaults for retrying git operations. Designed for transient failures like file locking (e.g., Dropbox on Windows).

type Options

type Options struct {
	// Target directory for synced repositories
	Target string

	// Include patterns for repository names (glob-style)
	Include []string

	// Exclude patterns for repository names (glob-style)
	Exclude []string

	// IncludePrivate includes private repositories
	IncludePrivate bool

	// DryRun simulates the sync without making changes
	DryRun bool

	// Verbose enables verbose output
	Verbose bool

	// OnProgress is called to report sync progress (optional)
	OnProgress ProgressCallback

	// SkipArchiveDetection skips the detectArchived() call which walks the entire
	// target directory. This is useful when syncing single repos (e.g., TUI worker)
	// where archive detection should be done once at the end, not per-repo.
	SkipArchiveDetection bool

	// Submodules checks out submodules (recursively) after each clone or fetch
	Submodules bool

	// Wikis clones or fetches each repo's wiki into <owner>/<repo>.wiki
	Wikis bool

	// LFSAll downloads the LFS objects of every ref after each clone or fetch,
	// not just those of the checked-out branch
	LFSAll bool

	// PullRefs fetches every pull request head into refs/pull/<n>/head after each sync,
	// so commits of fork and deleted branches are kept too
	PullRefs bool

	// UpdateWorkTree fast-forwards the checked-out default branch to origin after each
	// sync (switching to it when GitHub's default changed), so submodules and LFS files
	// of the latest commit get checked out. Local changes are never touched.
	UpdateWorkTree bool
}

Options configures the sync operation

type ProgressCallback

type ProgressCallback func(repoName string, status ProgressStatus, message string)

ProgressCallback is called to report sync progress repoName is the full repository name (owner/repo) status is the current status message provides additional context (e.g., error message)

type ProgressStatus

type ProgressStatus int

ProgressStatus represents the status of a sync operation

const (
	// ProgressPending indicates the repo is queued for sync
	ProgressPending ProgressStatus = iota
	// ProgressInProgress indicates the repo is currently being synced
	ProgressInProgress
	// ProgressCloned indicates the repo was cloned
	ProgressCloned
	// ProgressUpdated indicates the repo was updated
	ProgressUpdated
	// ProgressUpToDate indicates the repo is already up-to-date (fast check)
	ProgressUpToDate
	// ProgressSkipped indicates the repo was skipped
	ProgressSkipped
	// ProgressFailed indicates the repo sync failed
	ProgressFailed
)

type Result

type Result struct {
	// Cloned repositories
	Cloned []string

	// Updated repositories (pulled)
	Updated []string

	// UpToDate repositories (already current, no pull needed)
	UpToDate []string

	// Skipped repositories (filtered out)
	Skipped []string

	// Failed repositories with errors
	Failed map[string]error

	// Archived repositories (exist locally but not on remote - preserved for backup)
	Archived []string

	// Warnings are non-fatal problems (e.g. a submodule that failed to check out)
	Warnings []string

	// Wikis that were cloned or fetched
	Wikis []string

	// Gists that were cloned or fetched
	Gists []string
}

Result represents the result of a sync operation

func NewResult

func NewResult() *Result

NewResult creates a new sync result

type Syncer

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

Syncer handles repository synchronization

func New

func New(ghClient github.Client, g *git.Git, opts *Options) *Syncer

New creates a new Syncer

func (*Syncer) ListAccount added in v1.1.1

func (s *Syncer) ListAccount(ctx context.Context, username string) (*Account, error)

ListAccount returns the repos of a user plus every org the token's account belongs to. An empty username means the token's own account. An org whose repos can't be listed lands in Failed; the rest still come back.

func (*Syncer) Matches added in v1.1.1

func (s *Syncer) Matches(repo *gh.Repository) bool

Matches reports whether a repo passes the include/exclude filters

func (*Syncer) SyncGists added in v1.1.1

func (s *Syncer) SyncGists(ctx context.Context, result *Result) error

SyncGists clones or fetches every gist of the token's account (secret ones too) into <target>/<login>.gists/<id>, with the gist's API data in <id>.json. Results go into result; the error is only for when the gists can't be listed.

func (*Syncer) SyncOrgRepos

func (s *Syncer) SyncOrgRepos(ctx context.Context, org string) (*Result, error)

SyncOrgRepos syncs all repositories for an organization

func (*Syncer) SyncRepo

func (s *Syncer) SyncRepo(ctx context.Context, owner, repo string) (*Result, error)

SyncRepo syncs a single repository

func (*Syncer) SyncRepoWithData

func (s *Syncer) SyncRepoWithData(ctx context.Context, repo *gh.Repository) (*Result, error)

SyncRepoWithData syncs a single repository using pre-fetched data. This avoids redundant API calls when the repository data is already available.

func (*Syncer) SyncRepos added in v1.1.1

func (s *Syncer) SyncRepos(ctx context.Context, repos []*gh.Repository) (*Result, error)

SyncRepos syncs the given repositories, with archive detection over all of them

func (*Syncer) SyncSelectedRepos added in v1.1.1

func (s *Syncer) SyncSelectedRepos(ctx context.Context, fullNames []string) (*Result, error)

SyncSelectedRepos syncs only the given "owner/repo" names

func (*Syncer) SyncUserRepos

func (s *Syncer) SyncUserRepos(ctx context.Context, username string) (*Result, error)

SyncUserRepos syncs all repositories for a user

Jump to

Keyboard shortcuts

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