Skip to content

Commit

Permalink
when offbording don't remove webhook from gitlab if other component is
Browse files Browse the repository at this point in the history
using same repository as well

KONFLUX-5944

Signed-off-by: Robert Cerven <[email protected]>
  • Loading branch information
rcerven committed Dec 10, 2024
1 parent c93dae1 commit 8e31abb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion controllers/component_build_controller_pac.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/konflux-ci/build-service/pkg/boerrors"
Expand Down Expand Up @@ -535,7 +536,26 @@ func (r *ComponentBuildReconciler) UnconfigureRepositoryForPaC(ctx context.Conte

isAppUsed := IsPaCApplicationConfigured(gitProvider, pacConfig)
if !isAppUsed {
if webhookTargetUrl != "" {
componentList := &appstudiov1alpha1.ComponentList{}
if err := r.Client.List(ctx, componentList, &client.ListOptions{Namespace: component.Namespace}); err != nil {
log.Error(err, "failed to list components")
return "", "", "", err
}
gitUrl := strings.TrimSuffix(strings.TrimSuffix(component.Spec.Source.GitSource.URL, ".git"), "/")

sameRepoUsed := false
for _, comp := range componentList.Items {
if comp.Name == component.Name {
continue
}
componentUrl := strings.TrimSuffix(strings.TrimSuffix(comp.Spec.Source.GitSource.URL, ".git"), "/")
if componentUrl == gitUrl {
sameRepoUsed = true
break
}
}

if webhookTargetUrl != "" && !sameRepoUsed {
err = gitClient.DeletePaCWebhook(repoUrl, webhookTargetUrl)
if err != nil {
// Just log the error and continue with merge request creation
Expand Down

0 comments on commit 8e31abb

Please sign in to comment.