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 ¶
- func LsRemote(ctx context.Context, gap scms.GitOperationsProvider, ...) (map[string]string, error)
- type BranchShas
- type EnvironmentOperations
- func (g *EnvironmentOperations) CloneRepo(ctx context.Context) error
- func (g *EnvironmentOperations) GetBranchShas(ctx context.Context, branch string) (BranchShas, error)
- func (g *EnvironmentOperations) GetShaAuthor(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaBody(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaMetadataFromFile(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
- func (g *EnvironmentOperations) GetShaMetadataFromGit(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
- func (g *EnvironmentOperations) GetShaSubject(ctx context.Context, sha string) (string, error)
- func (g *EnvironmentOperations) GetShaTime(ctx context.Context, sha string) (v1.Time, error)
- func (g *EnvironmentOperations) HasConflict(ctx context.Context, proposedBranch, activeBranch string) (bool, error)
- func (g *EnvironmentOperations) IsPullRequestRequired(ctx context.Context, environmentNextBranch, environmentBranch string) (bool, error)
- func (g *EnvironmentOperations) MergeWithOursStrategy(ctx context.Context, proposedBranch, activeBranch string) error
- func (g *EnvironmentOperations) PromoteEnvironmentWithMerge(ctx context.Context, environmentBranch, environmentNextBranch string) error
- type HydratorMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BranchShas ¶
type BranchShas struct { // Dry is the SHA of the commit that was used as the dry source for hydration. Dry string // Hydrated is the SHA of the commit on the hydrated branch. Hydrated string }
BranchShas holds the hydrated and dry commit SHAs for a branch.
type EnvironmentOperations ¶ added in v0.8.0
type EnvironmentOperations struct {
// contains filtered or unexported fields
}
EnvironmentOperations provides methods for interacting with a specific clone of a Git repository for an environment.
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)
GetBranchShas checks out the given branch, pulls the latest changes, and returns the hydrated and dry SHAs.
func (*EnvironmentOperations) GetShaAuthor ¶ added in v0.8.0
GetShaAuthor retrieves the author of a commit given its SHA.
func (*EnvironmentOperations) GetShaBody ¶ added in v0.8.0
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)
GetShaMetadataFromFile retrieves commit metadata from the hydrator.metadata file for a given SHA.
func (*EnvironmentOperations) GetShaMetadataFromGit ¶ added in v0.8.0
func (g *EnvironmentOperations) GetShaMetadataFromGit(ctx context.Context, sha string) (v1alpha1.CommitShaState, error)
GetShaMetadataFromGit retrieves commit metadata by running git commands for a given SHA.
func (*EnvironmentOperations) GetShaSubject ¶ added in v0.8.0
GetShaSubject retrieves the subject of a commit given its SHA.
func (*EnvironmentOperations) GetShaTime ¶ added in v0.8.0
GetShaTime retrieves the commit time of a commit given its SHA.
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
MergeWithOursStrategy merges the proposed branch into the active branch using the "ours" strategy.
func (*EnvironmentOperations) PromoteEnvironmentWithMerge ¶ added in v0.8.0
func (g *EnvironmentOperations) PromoteEnvironmentWithMerge(ctx context.Context, environmentBranch, environmentNextBranch string) error
PromoteEnvironmentWithMerge merges the next environment branch into the current environment branch and pushes the result.
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.