Documentation
¶
Overview ¶
Package ghsync pulls a GitHub user's activity into gitrakz's local store, incrementally. It is built by dependency inversion: GHClient and EventStore are ordinary interfaces defined in this package, so Syncer is unit-testable without a real gh CLI or a real database. Production wiring supplies a commander-backed GHClient (see commander_client.go) and internal/pkg/db.DB, which already satisfies EventStore.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventStore ¶
type EventStore interface {
UpsertEvents(ctx context.Context, evs []types.Event) error
GetSyncState(ctx context.Context, owner, repo string) (int64, error)
UpsertSyncState(ctx context.Context, owner, repo string, ts int64) error
}
EventStore persists synced events and tracks per-repo sync progress. internal/pkg/db.DB already satisfies this interface in production — ghsync never imports db, so it stays unit-testable without a real database; the engine/handlers wire the real one in.
type GHClient ¶
type GHClient interface {
// DiscoverRepos returns every repo the authenticated gh token can see
// for user.
DiscoverRepos(ctx context.Context, user string) ([]RepoRef, error)
// ListEvents returns user's activity in r at or after since (a unix
// timestamp; 0 means "from the beginning").
ListEvents(
ctx context.Context,
r RepoRef,
user string,
since int64,
) ([]types.Event, error)
}
GHClient discovers repos for a user and lists that user's activity in each. The production implementation shells out to the gh CLI via commander (see commanderGHClient); tests supply a mock.
func NewCommanderGHClient ¶
NewCommanderGHClient returns a GHClient backed by the gh CLI, invoked through cmd. Production callers pass commander.New(); tests pass a commander.NewMock().
type SyncResult ¶
SyncResult summarizes one Sync run.
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer pulls a GitHub user's activity from a GHClient into an EventStore, incrementally.
func NewSyncer ¶
func NewSyncer(gh GHClient, store EventStore, user string) *Syncer
NewSyncer returns a Syncer that syncs user's activity from gh into store.
func (*Syncer) Sync ¶
func (s *Syncer) Sync(ctx context.Context) (SyncResult, error)
Sync runs two passes: discover every repo for the configured user, then pull + persist each repo's events since its last recorded sync.
A single repo failing (a network blip, an SSO-locked org, a rate limit) is recorded in Errors and does NOT abort the rest of the sync — per-owner fail-soft, so one bad repo never takes down every other owner's sync.