git

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package git provides operations for managing Git repositories.

The EnvironmentOperations struct provides methods for interacting with a particular clone of a repository. It ensures there is a separate clone for each environment to avoid concurrency issues.

When implementing operations that do not require an environment-specific clone, create a static function that accepts the GitOperationsProvider and the GitRepository as parameters. This avoids the need to manage state to avoid concurrency issues. See LsRemote for an example of such a function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LsRemote added in v0.8.0

func LsRemote(ctx context.Context, gap scms.GitOperationsProvider, gitRepo *v1alpha1.GitRepository, branches ...string) (map[string]string, error)

Types

type BranchShas

type BranchShas struct {
	Dry      string
	Hydrated string
}

type EnvironmentOperations added in v0.8.0

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

func NewEnvironmentOperations added in v0.8.0

func NewEnvironmentOperations(ctx context.Context, k8sClient client.Client, gap scms.GitOperationsProvider, repoRef v1alpha1.ObjectReference, obj v1.Object, activeBranch string) (*EnvironmentOperations, error)

NewEnvironmentOperations creates a new EnvironmentOperations instance. The activeBranch parameter is used to differentiate between different environments that might use the same GitRepository and avoid conflicts between concurrent operations.

func (*EnvironmentOperations) CloneRepo added in v0.8.0

func (g *EnvironmentOperations) CloneRepo(ctx context.Context) error

CloneRepo clones the gitRepo to a temporary directory if needed does nothing if the repo is already cloned.

func (*EnvironmentOperations) GetBranchShas added in v0.8.0

func (g *EnvironmentOperations) GetBranchShas(ctx context.Context, branch string) (BranchShas, error)

func (*EnvironmentOperations) GetShaAuthor added in v0.8.0

func (g *EnvironmentOperations) GetShaAuthor(ctx context.Context, sha string) (string, error)

func (*EnvironmentOperations) GetShaBody added in v0.8.0

func (g *EnvironmentOperations) GetShaBody(ctx context.Context, sha string) (string, error)

GetShaBody retrieves the body of a commit given its SHA.

func (*EnvironmentOperations) GetShaMetadataFromFile added in v0.8.0

func (g *EnvironmentOperations) GetShaMetadataFromFile(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)

func (*EnvironmentOperations) GetShaMetadataFromGit added in v0.8.0

func (g *EnvironmentOperations) GetShaMetadataFromGit(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)

func (*EnvironmentOperations) GetShaSubject added in v0.8.0

func (g *EnvironmentOperations) GetShaSubject(ctx context.Context, sha string) (string, error)

func (*EnvironmentOperations) GetShaTime added in v0.8.0

func (g *EnvironmentOperations) GetShaTime(ctx context.Context, sha string) (v1.Time, error)

func (*EnvironmentOperations) HasConflict added in v0.8.0

func (g *EnvironmentOperations) HasConflict(ctx context.Context, proposedBranch, activeBranch string) (bool, error)

HasConflict checks if there is a merge conflict between the proposed branch and the active branch. It assumes that origin/<branch> is currently fetched and updated in the local repository. This should happen via GetBranchShas function earlier in the reconcile.

func (*EnvironmentOperations) IsPullRequestRequired added in v0.8.0

func (g *EnvironmentOperations) IsPullRequestRequired(ctx context.Context, environmentNextBranch, environmentBranch string) (bool, error)

IsPullRequestRequired will compare the environment branch with the next environment branch and return true if a PR is required. The PR is required if the diff between the two branches contain edits to yaml files.

func (*EnvironmentOperations) MergeWithOursStrategy added in v0.8.0

func (g *EnvironmentOperations) MergeWithOursStrategy(ctx context.Context, proposedBranch, activeBranch string) error

func (*EnvironmentOperations) PromoteEnvironmentWithMerge added in v0.8.0

func (g *EnvironmentOperations) PromoteEnvironmentWithMerge(ctx context.Context, environmentBranch, environmentNextBranch string) error

type HydratorMetadata added in v0.6.0

type HydratorMetadata struct {
	// RepoURL is the URL of the repository where the commit is located.
	RepoURL string `json:"repoURL,omitempty"`
	// DrySha is the SHA of the commit that was used as the dry source for hydration.
	DrySha string `json:"drySha,omitempty"`
	// Author is the author of the dry commit that was used to hydrate the branch.
	Author string `json:"author,omitempty"`
	// Date is the date of the dry commit that was used to hydrate the branch.
	Date v1.Time `json:"date,omitempty"`
	// Subject is the subject line of the dry commit that was used to hydrate the branch.
	Subject string `json:"subject,omitempty"`
	// Body is the body of the dry commit that was used to hydrate the branch without the subject.
	Body string `json:"body,omitempty"`
	// References are the references to other commits, that went into the hydration of the branch.
	References []v1alpha1.RevisionReference `json:"references,omitempty"`
}

HydratorMetadata contains metadata about the commit that is used to hydrate a branch. It is used to store

Jump to

Keyboard shortcuts

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