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 ¶
- type Watcher
- func (w *Watcher) Clone(ctx context.Context) error
- func (w *Watcher) FileAtParentOf(commit, path string) (content string, ok bool)
- func (w *Watcher) LastCommit() string
- func (w *Watcher) ReadHCLFiles() (map[string]string, error)
- func (w *Watcher) Ready() bool
- func (w *Watcher) Run(ctx context.Context)
- func (w *Watcher) Status() (lastCommit string, lastUpdate time.Time)
- func (w *Watcher) Trigger()
- func (w *Watcher) TriggerStale()
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 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) FileAtParentOf ¶
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 ¶
LastCommit returns just the last commit hash.
func (*Watcher) ReadHCLFiles ¶
ReadHCLFiles returns a map of repo-relative path → file content for every .hcl file under the configured HCLDir.
func (*Watcher) Ready ¶
Ready reports whether the initial clone has completed successfully. Before Clone returns, Status and ReadHCLFiles return zero/nil values.
func (*Watcher) Run ¶
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) 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.