gitops

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 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

Index

Constants

View Source
const TokenUser = "x-access-token"

TokenUser is the HTTPS user name sent with a token when no --git-user / GIT_USER is set; GitHub accepts any name together with a token.

Variables

View Source
var ErrNoGitToken = fmt.Errorf("git credentials required: pass --git-token, set GIT_TOKEN or GITHUB_TOKEN, or log in with `gh auth login` (--git-user/GIT_USER is optional)")

ErrNoGitToken says how to give claims a token for push and clone.

Functions

func AddLabelsToPR

func AddLabelsToPR(prNumber int, labels []string, repoPath string) error

AddLabelsToPR adds labels to an existing PR of the checkout's repository.

func CheckGitHubAuth added in v0.24.0

func CheckGitHubAuth(token string) error

CheckGitHubAuth fails early, before a push, when there is no token to open the PR with.

func HTTPSURL added in v0.26.0

func HTTPSURL(url string) string

HTTPSURL turns an SSH remote into its HTTPS form (git@github.com:o/r.git -> https://github.com/o/r.git). claims authenticates with a token over HTTPS only (go-git has no access to the SSH agent here), so SSH remotes are pushed to and cloned from over HTTPS (claims#114). Other URLs are returned unchanged.

func IsHTTPURL added in v0.26.0

func IsHTTPURL(url string) bool

IsHTTPURL reports whether url is an http(s) remote.

func IsSSHURL added in v0.26.0

func IsSSHURL(url string) bool

IsSSHURL reports whether url is an SSH remote (git@host:o/r, ssh://...).

func ProbeRemote added in v0.26.0

func ProbeRemote(ctx context.Context, url, user, token string) error

ProbeRemote lists the refs of url with token (git ls-remote): a cheap check that the remote is there and accepts the token, before anything is written.

func ResolveCredentials

func ResolveCredentials(user, token string) (string, string, error)

ResolveCredentials gets git credentials from flags or environment

func ResolveCredentialsOptional

func ResolveCredentialsOptional(user, token string) (string, string)

ResolveCredentialsOptional gets git credentials if available, but doesn't error if missing This is useful for local commits that don't require push

Types

type Config

type Config struct {
	RepoPath     string
	RepoURL      string // For clone-based workflow
	Branch       string
	CreateBranch bool
	Remote       string
	User         string
	Token        string
	CommitMsg    string
}

Config holds git-related configuration

type GitOps

type GitOps struct {
	RepoPath string
	// contains filtered or unexported fields
}

GitOps handles git operations for the claims CLI

func Clone

func Clone(url, user, token string) (*GitOps, string, error)

Clone clones a repository to a temp directory

func New

func New(repoPath string, user, token string) (*GitOps, error)

New creates a GitOps instance for an existing repo

func (*GitOps) AddFiles

func (g *GitOps) AddFiles(files []string) error

AddFiles stages files for commit

func (*GitOps) AddWithRemoved added in v0.6.0

func (g *GitOps) AddWithRemoved(added, removed []string) error

AddWithRemoved stages both additions and removals

func (*GitOps) BranchExists added in v0.26.0

func (g *GitOps) BranchExists(name string) bool

BranchExists reports whether the local branch name exists.

func (*GitOps) CheckoutBranch

func (g *GitOps) CheckoutBranch(name string) error

CheckoutBranch checks out an existing branch

func (*GitOps) Cleanup

func (g *GitOps) Cleanup() error

Cleanup removes the repository directory (for clone-based workflows)

func (*GitOps) Commit

func (g *GitOps) Commit(message, authorName, authorEmail string) error

Commit creates a commit with the staged changes

func (*GitOps) CreateBranch

func (g *GitOps) CreateBranch(name string) error

CreateBranch creates and checks out a new branch

func (*GitOps) GetCurrentBranch

func (g *GitOps) GetCurrentBranch() (string, error)

GetCurrentBranch returns the name of the current branch

func (*GitOps) GetRemoteURL added in v0.6.0

func (g *GitOps) GetRemoteURL(remoteName string) (string, error)

GetRemoteURL returns the URL of the given remote (e.g. "origin")

func (*GitOps) GetRepo

func (g *GitOps) GetRepo() *git.Repository

GetRepo returns the underlying git repository

func (*GitOps) HasToken added in v0.26.0

func (g *GitOps) HasToken() bool

HasToken reports whether g pushes with a token.

func (*GitOps) Push

func (g *GitOps) Push(remote, branch string) error

Push pushes a specific branch to remote

func (*GitOps) RemoveFiles added in v0.6.0

func (g *GitOps) RemoveFiles(files []string) error

RemoveFiles stages file removals in the worktree

type PRConfig

type PRConfig struct {
	Title       string
	Description string
	Labels      []string
	BaseBranch  string
	HeadBranch  string // "" = the checkout's current branch
	Token       string // "" = ghclient.Token's order (GIT_TOKEN, GITHUB_TOKEN, gh)
}

PRConfig holds pull request configuration

type PRResult

type PRResult struct {
	Number int
	URL    string
}

PRResult holds the result of PR creation

func CreatePR

func CreatePR(config PRConfig, repoPath string) (*PRResult, error)

CreatePR opens a pull request in the GitHub repository of the checkout at repoPath (its origin remote) through the GitHub API, then adds the labels. When only the labels fail, the PR is returned together with the error.

Jump to

Keyboard shortcuts

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