|
1 | 1 | //go:build e2e |
2 | 2 |
|
3 | | -package e2e |
| 3 | +package e2e_test |
4 | 4 |
|
5 | 5 | import ( |
6 | 6 | "bytes" |
7 | 7 | "context" |
8 | 8 | "encoding/json" |
9 | 9 | "fmt" |
| 10 | + "io" |
| 11 | + "log" |
| 12 | + "strings" |
| 13 | + "testing" |
| 14 | + "time" |
| 15 | + |
10 | 16 | "github.com/fluxcd/go-git-providers/gitprovider" |
11 | 17 | "github.com/fluxcd/helm-controller/api/v2beta1" |
12 | 18 | "github.com/fluxcd/pkg/runtime/logger" |
13 | 19 | "github.com/go-logr/logr" |
14 | | - "github.com/google/go-github/v47/github" |
| 20 | + "github.com/google/go-github/v49/github" |
15 | 21 | "github.com/hashicorp/go-uuid" |
16 | 22 | . "github.com/onsi/gomega" |
17 | 23 | "github.com/weaveworks/pipeline-controller/api/v1alpha1" |
18 | 24 | "github.com/weaveworks/pipeline-controller/internal/testingutils" |
19 | 25 | "github.com/weaveworks/pipeline-controller/pkg/conditions" |
20 | 26 | "github.com/weaveworks/pipeline-controller/server/strategy/pullrequest" |
21 | 27 | gitlab2 "github.com/xanzy/go-gitlab" |
22 | | - "io" |
23 | 28 | corev1 "k8s.io/api/core/v1" |
24 | 29 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
25 | 30 | "k8s.io/apimachinery/pkg/types" |
26 | 31 | "k8s.io/client-go/kubernetes" |
27 | | - "log" |
28 | 32 | "sigs.k8s.io/controller-runtime/pkg/client" |
29 | | - "strings" |
30 | | - "testing" |
31 | | - "time" |
32 | 33 | ) |
33 | 34 |
|
34 | 35 | const ( |
@@ -120,7 +121,7 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel |
120 | 121 | return fmt.Errorf("cannot delete branch for pipeline without promotion") |
121 | 122 | } |
122 | 123 |
|
123 | | - pullRequestPromotion := promotion.PullRequest |
| 124 | + pullRequestPromotion := promotion.Strategy.PullRequest |
124 | 125 | if pullRequestPromotion == nil { |
125 | 126 | return fmt.Errorf("cannot delete branch for pipelines without pullRequest") |
126 | 127 | } |
@@ -154,30 +155,29 @@ func deleteGitBranchByName(ctx context.Context, g *WithT, c client.Client, pipel |
154 | 155 | } |
155 | 156 | //TODO it should not be needed - gitlab ggp issue |
156 | 157 | userRepoRef.Domain = gitProviderClient.SupportedDomain() |
157 | | - userRepo, err := gitProviderClient.UserRepositories().Get(ctx, *userRepoRef) |
158 | | - if err != nil { |
159 | | - return fmt.Errorf("could not get repository: %w", err) |
160 | | - } |
161 | | - clientRaw := gitProviderClient.Raw() |
162 | 158 | //TODO contribute me to ggp |
163 | 159 | switch pullRequestPromotion.Type { |
164 | 160 | case v1alpha1.Github: |
165 | 161 | //cannot delete github branch so renaming |
166 | | - gClient := clientRaw.(*github.Client) |
| 162 | + clientRaw := gitProviderClient.RawClient().(gitprovider.Client).Raw().(*github.Client) |
167 | 163 | generatedUuid, err := uuid.GenerateUUID() |
168 | 164 | if err != nil { |
169 | 165 | return fmt.Errorf("could not generate uuid: %w", err) |
170 | 166 | } |
171 | 167 | owner := userRepoRef.UserLogin |
172 | 168 | repo := userRepoRef.RepositoryName |
173 | | - _, _, err = gClient.Repositories.RenameBranch(ctx, owner, repo, branchName, fmt.Sprintf("%s-%s", branchName, generatedUuid)) |
| 169 | + _, _, err = clientRaw.Repositories.RenameBranch(ctx, owner, repo, branchName, fmt.Sprintf("%s-%s", branchName, generatedUuid)) |
174 | 170 | if err != nil { |
175 | 171 | return fmt.Errorf("could not rename branch: %w", err) |
176 | 172 | } |
177 | 173 | case v1alpha1.Gitlab: |
178 | | - gitlabProject := userRepo.APIObject().(*gitlab2.Project) |
179 | | - gClient := clientRaw.(*gitlab2.Client) |
180 | | - _, err := gClient.Branches.DeleteBranch(gitlabProject.ID, branchName, nil) |
| 174 | + clientRaw := gitProviderClient.RawClient().(gitprovider.Client).Raw().(*gitlab2.Client) |
| 175 | + glRepo, err := gitProviderClient.RawClient().(gitprovider.Client).UserRepositories().Get(ctx, *userRepoRef) |
| 176 | + if err != nil { |
| 177 | + return fmt.Errorf("could not delete branch: %w", err) |
| 178 | + } |
| 179 | + gitlabProject := glRepo.APIObject().(*gitlab2.Project) |
| 180 | + _, err = clientRaw.Branches.DeleteBranch(gitlabProject.ID, branchName, nil) |
181 | 181 | if err != nil { |
182 | 182 | return fmt.Errorf("could not delete gitlab branch: %w", err) |
183 | 183 | } |
|
0 commit comments