gitwatch

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package gitwatch clones a remote git repo into memory and watches it for changes, triggering a callback whenever the watched branch advances.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Watcher

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

Watcher holds a live in-memory clone of a git repo and keeps it up to date.

func New

func New(cfg *config.Config, onChange func(commit string)) *Watcher

New creates a Watcher that registers metrics into the default Prometheus registry.

func NewWithRegistry

func NewWithRegistry(cfg *config.Config, onChange func(commit string), reg prometheus.Registerer) *Watcher

NewWithRegistry creates a Watcher that registers metrics into reg. Use this in tests to avoid duplicate-registration panics.

func (*Watcher) Clone

func (w *Watcher) Clone(ctx context.Context) error

Clone performs the initial clone into memory. Must be called before Run.

func (*Watcher) FileAtParentOf

func (w *Watcher) FileAtParentOf(commit, path string) (content string, ok bool)

FileAtParentOf returns the content of path as it was at the first parent of the named commit. ok is false when the repo is not cloned, the commit is unknown or has no parent (the root commit), or the file did not exist at the parent. Keying off an explicit commit — rather than the repo's current HEAD — keeps the answer consistent with the HCL snapshot being evaluated even if a concurrent pull has advanced HEAD. It is used to decide whether a change at that commit (such as adding the managed meta tag) is new relative to the previous commit.

func (*Watcher) LastCommit

func (w *Watcher) LastCommit() string

LastCommit returns just the last commit hash.

func (*Watcher) ReadHCLFiles

func (w *Watcher) ReadHCLFiles() (map[string]string, error)

ReadHCLFiles returns a map of repo-relative path → file content for every .hcl file under the configured HCLDir.

func (*Watcher) Ready

func (w *Watcher) Ready() bool

Ready reports whether the initial clone has completed successfully. Before Clone returns, Status and ReadHCLFiles return zero/nil values.

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context)

Run polls for updates on the configured interval and also reacts to Trigger calls. It optionally re-clones on a slow cadence to reclaim memory. All git operations it drives (pull, reclone) run from this single goroutine, so they are serialised with each other and never overlap. Blocks until ctx is cancelled.

func (*Watcher) Status

func (w *Watcher) Status() (lastCommit string, lastUpdate time.Time)

Status returns the last seen commit hash and the time it was seen.

func (*Watcher) Trigger

func (w *Watcher) Trigger()

Trigger schedules an immediate fetch, e.g. when a webhook fires. Non-blocking: if a trigger is already pending it is coalesced.

func (*Watcher) TriggerStale

func (w *Watcher) TriggerStale()

TriggerStale schedules an immediate fetch because the repo has exceeded the configured maximum staleness. Increments the staleness counter and delegates to Trigger.

Jump to

Keyboard shortcuts

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