diff --git a/api/v1beta1/git.go b/api/v1beta1/git.go index 5d4eb69..0924bb7 100644 --- a/api/v1beta1/git.go +++ b/api/v1beta1/git.go @@ -95,4 +95,10 @@ type PushSpec struct { // https://git-scm.com/book/en/v2/Git-Internals-The-Refspec // +optional Refspec string `json:"refspec,omitempty"` + + // Options specifies the push options that are sent to the Git + // server when performing a push operation. For details, see: + // https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt + // +optional + Options map[string]string `json:"options,omitempty"` } diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 5757cdb..c5bc7b4 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -105,7 +105,7 @@ func (in *GitSpec) DeepCopyInto(out *GitSpec) { if in.Push != nil { in, out := &in.Push, &out.Push *out = new(PushSpec) - **out = **in + (*in).DeepCopyInto(*out) } } @@ -239,6 +239,13 @@ func (in *ImageUpdateAutomationStatus) DeepCopy() *ImageUpdateAutomationStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PushSpec) DeepCopyInto(out *PushSpec) { *out = *in + if in.Options != nil { + in, out := &in.Options, &out.Options + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PushSpec. diff --git a/config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml b/config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml index d27da14..464bc0d 100644 --- a/config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml +++ b/config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml @@ -135,6 +135,13 @@ spec: to the branch named. The branch is created using `.spec.checkout.branch` as the starting point, if it doesn't already exist. type: string + options: + additionalProperties: + type: string + description: 'Options specifies the push options that are + sent to the Git server when performing a push operation. + For details, see: https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt' + type: object refspec: description: 'Refspec specifies the Git Refspec to use for a push operation. If both Branch and Refspec are provided, diff --git a/docs/api/v1beta1/image-automation.md b/docs/api/v1beta1/image-automation.md index 6c5ebfa..21fdedc 100644 --- a/docs/api/v1beta1/image-automation.md +++ b/docs/api/v1beta1/image-automation.md @@ -660,6 +660,20 @@ For more details about Git Refspecs, see: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec

+ + +options
+ +map[string]string + + + +(Optional) +

Options specifies the push options that are sent to the Git +server when performing a push operation. For details, see: +https://git-scm.com/docs/git-push#Documentation/git-push.txt—push-optionltoptiongt

+ + diff --git a/docs/spec/v1beta1/imageupdateautomations.md b/docs/spec/v1beta1/imageupdateautomations.md index d6382be..78604a7 100644 --- a/docs/spec/v1beta1/imageupdateautomations.md +++ b/docs/spec/v1beta1/imageupdateautomations.md @@ -419,6 +419,11 @@ type PushSpec struct { // https://git-scm.com/book/en/v2/Git-Internals-The-Refspec // +optional Refspec string `json:"refspec,omitempty"` + + // Options specifies the push options that are sent to the Git + // server when performing a push operation. For details, see: + // https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt + Options map[string]string `json:"options,omitempty"` } ``` @@ -477,8 +482,23 @@ spec: refspec: refs/heads/main:refs/heads/auto ``` -#### Gerrit +To specify the [push options](https://git-scm.com/docs/git-push#Documentation/git-push.txt---push-optionltoptiongt) +to be sent to the upstream Git server, use `.push.options`. These options can be +used to perform operations as a result of the push. For example, using the below +push options will open a GitLab Merge Request to the `release` branch +automatically with the commit the controller pushed to the `dev` branch: +```yaml +spec: + git: + push: + branch: dev + options: + merge_request.create: "" + merge_request.target: release +``` + +#### Gerrit [Gerrit](https://www.gerritcodereview.com/) operates differently from a standard Git server. Rather than sending individual commits to a branch, diff --git a/internal/controller/imageupdateautomation_controller.go b/internal/controller/imageupdateautomation_controller.go index 872663a..deddd41 100644 --- a/internal/controller/imageupdateautomation_controller.go +++ b/internal/controller/imageupdateautomation_controller.go @@ -416,11 +416,14 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr pushToBranch = true } + var pushConfig repository.PushConfig + if gitSpec.Push != nil { + pushConfig.Options = gitSpec.Push.Options + } if pushToBranch { // If the force push feature flag is true and we are pushing to a // different branch than the one we checked out to, then force push // these changes. - var pushConfig repository.PushConfig forcePush := r.features[features.GitForcePushBranch] if forcePush && switchBranch { pushConfig.Force = true @@ -434,9 +437,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr } if pushWithRefspec { - pushConfig := repository.PushConfig{ - Refspecs: []string{gitSpec.Push.Refspec}, - } + pushConfig.Refspecs = []string{gitSpec.Push.Refspec} if err := gitClient.Push(pushCtx, pushConfig); err != nil { return failWithError(err) }