ghsync

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 12 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 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 {
	// AuthenticatedUser returns the login the gh CLI is authenticated as
	// (`gh api user`). It's used to default the sync target when
	// GITRAKZ_GH_USER is unset — track yourself without configuring anything.
	AuthenticatedUser(ctx context.Context) (string, error)

	// 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

func NewCommanderGHClient(cmd commander.Commander) GHClient

NewCommanderGHClient returns a GHClient backed by the gh CLI, invoked through cmd. Production callers pass commander.New(); tests pass a commander.NewMock().

type RepoRef

type RepoRef struct {
	Owner string
	Repo  string
}

RepoRef identifies a single GitHub repository by owner and name.

type SyncResult

type SyncResult struct {
	ReposScanned   int
	EventsUpserted int
	Errors         []string
}

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. An empty user means "the gh CLI's authenticated login", resolved on the first Sync via GHClient.AuthenticatedUser.

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.

Jump to

Keyboard shortcuts

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