gitclient

package
v1.15.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Overview

Package gitclient provides a simple Git client for updating files in remote repositories using in-memory operations.

It uses go-git and go-billy's memfs to perform all git operations (clone, update, commit, push) without writing to disk. This is useful for ephemeral or serverless environments, or when you want to avoid filesystem side effects.

Example usage:

func main() {
    client := &GitClient{
        RepoURL: "https://github.com/youruser/yourrepo.git",
        Branch:  "main",
        Token:   "<your-git-token>",
    }
    err := client.UpdateFile("path/to/file.txt", "new file content", "Update file.txt via automation")
    if err != nil {
        panic(err)
    }
    fmt.Println("File updated and pushed successfully!")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitClient

type GitClient struct {
	RepoURL string
	Branch  string
	Token   string
	Author  object.Signature
	Depth   int
}

func NewGitClient

func NewGitClient(repoURL, token string, opts ...GitConnectionOption) *GitClient

func (*GitClient) CheckConnection added in v1.4.10

func (c *GitClient) CheckConnection() error

CheckConnection attempts to clone the repository to verify access and authentication. Returns nil if successful, or an error if the connection/auth fails.

func (*GitClient) CheckHealth added in v1.4.10

func (c *GitClient) CheckHealth(_ context.Context) []rorhealth.Check

CheckHealth checks the health of the git connection and returns a health check

func (*GitClient) CheckeHealthWithoutContext added in v1.7.0

func (c *GitClient) CheckeHealthWithoutContext() []rorhealth.Check

func (*GitClient) GetFile added in v1.4.10

func (c *GitClient) GetFile(filePath string) ([]byte, error)

GetFile clones the repo into an in-memory filesystem and returns the contents of the specified file as []byte. If the file does not exist, it returns nil and no error.

func (GitClient) UploadFile added in v1.4.10

func (c GitClient) UploadFile(filePath string, newContent []byte, commitMsg string, opts ...GitUploadOption) error

UpdateFile clones the repo into an in-memory filesystem, updates a file, commits, and pushes the change. No files are written to disk; all operations are performed in memory using go-billy/memfs.

Arguments:

filePath:   Path to the file to update (relative to repo root)
newContent: New content to write to the file
commitMsg:  Commit message for the change

Returns an error if any git operation fails.

type GitConnectionOption added in v1.4.15

type GitConnectionOption interface {
	// contains filtered or unexported methods
}

func OptionAuthor added in v1.4.15

func OptionAuthor(name, email string) GitConnectionOption

func OptionBranch added in v1.4.15

func OptionBranch(branch string) GitConnectionOption

type GitUploadOption added in v1.4.15

type GitUploadOption interface {
	GitConnectionOption
	// contains filtered or unexported methods
}

func OptionDepth added in v1.4.15

func OptionDepth(depth int) GitUploadOption

Jump to

Keyboard shortcuts

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