Categorygithub.com/Southclaws/gitwatch
modulepackage
1.5.1
Repository: https://github.com/southclaws/gitwatch.git
Documentation: pkg.go.dev

# README

gitwatch

Periodically polls a set of targets for changes, if there are any an event is emitted on a channel.

Usage

session, err := gitwatch.New(
    ctx,
    []Repository{
        {URL: "https://github.com/repo/a"},
        {URL: "https://github.com/repo/b"},
    },
    time.Second,
    "./gitwatch-cache/",
    true,
)

go func() {
    for {
        select {
        case event := <-session.Events:
            fmt.Println("git event:", event)
        case err := <-session.Errors:
            fmt.Println("git error:", err)
        }
    }
}()

// blocks until failure
err = session.Run()
if err != nil {
    // process was terminated somehow, handle error
}

By design, once the watcher is up and running (post initial clone phase), errors will not cause it to stop. Instead, errors are passed down the Errors channel for the dependent package to handle. The error returned by Run will either be context.Cancelled or any git errors raised during the initial cloning of all targets.

There also exists a channel called InitialDone which is only ever pushed to once, immediately after all initial targets have been cloned. It's a buffered channel of size 1 so there's no explicit need to ever read from it but it can be useful for sequencing things properly.

You can set the branch and directory name of target repositories. See the docstring for Repository for details.

# Packages

No description provided by the author

# Functions

GetEventFromRepo reads a locally cloned git repository and returns an event based on the most recent commit.
GetRepoDirectory the directory name for a repository.
New constructs a new git watch session on the given repositories The `auth` parameter is the default authentication method.

# Structs

Event represents an update detected on one of the watched repositories.
Repository represents a Git repository address and branch name.
Session represents a git watch session configuration.