Skip to content

Commit 910cde6

Browse files
zmotsoMykolaMarusenko
authored andcommitted
refactor: Project onboarding workflow (#231)
- Refactored `put_project.go` to improve code maintainability - Extracted error handling into reusable `handleError` helper method - Consolidated git provider initialization throughout the code - Simplified push operation to use single call with multiple refspecs - Improved error messages with more context - Rewrote tests in `put_project_test.go` with better coverage - Split tests into separate files for third-party Git providers and Gerrit - Added comprehensive test cases for success and error scenarios - Reduced test complexity and improved maintainability - Enhanced GitServer API documentation - Added detailed description for `nameSshKeySecret` field - Documented required and optional secret keys for each Git provider - Move Git package from v2 to main pkg directory - Updated import paths across the codebase - Removed deprecated package files
1 parent a368e92 commit 910cde6

32 files changed

+3292
-4589
lines changed

.mockery.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ packages:
2121
interfaces:
2222
Client:
2323
github.com/epam/edp-codebase-operator/v2/pkg/git:
24-
interfaces:
25-
Git:
26-
Command:
27-
github.com/epam/edp-codebase-operator/v2/pkg/git/v2:
2824
interfaces:
2925
Git:
3026
github.com/epam/edp-codebase-operator/v2/pkg/gitprovider:

api/v1/git_server_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ type GitServerSpec struct {
2424

2525
SshPort int32 `json:"sshPort"`
2626

27+
// NameSshKeySecret is the name of the Kubernetes secret containing Git repository credentials.
28+
// Required keys:
29+
// - token: Git provider access token (required)
30+
// Optional keys:
31+
// - id_rsa: SSH private key for Git operations over SSH
32+
// - secretString: Webhook secret for validating webhook requests
33+
// - username: Git username to override the default GitUser
34+
// For Gerrit provider, only id_rsa key is required and used.
35+
// +kubebuilder:example:=my-git-credentials
36+
// +required
2737
NameSshKeySecret string `json:"nameSshKeySecret"`
2838

2939
// GitProvider is a git provider type. It can be gerrit, github or gitlab. Default value is gerrit.

config/crd/bases/v2.edp.epam.com_gitservers.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ spec:
7474
format: int32
7575
type: integer
7676
nameSshKeySecret:
77+
description: |-
78+
NameSshKeySecret is the name of the Kubernetes secret containing Git repository credentials.
79+
Required keys:
80+
- token: Git provider access token (required)
81+
Optional keys:
82+
- id_rsa: SSH private key for Git operations over SSH
83+
- secretString: Webhook secret for validating webhook requests
84+
- username: Git username to override the default GitUser
85+
For Gerrit provider, only id_rsa key is required and used.
86+
example: my-git-credentials
7787
type: string
7888
skipWebhookSSLVerification:
7989
description: SkipWebhookSSLVerification is a flag to skip webhook

controllers/codebase/service/chain/checkout_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
1111
codebaseutil "github.com/epam/edp-codebase-operator/v2/pkg/codebase"
12-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
12+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
1313
)
1414

1515
func CheckoutBranch(

controllers/codebase/service/chain/checkout_branch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1515

1616
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
17-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
18-
gitServerMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/v2/mocks"
17+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
18+
gitServerMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/mocks"
1919
"github.com/epam/edp-codebase-operator/v2/pkg/util"
2020
)
2121

controllers/codebase/service/chain/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sigs.k8s.io/controller-runtime/pkg/client"
1212

1313
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
14-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
14+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
1515
"github.com/epam/edp-codebase-operator/v2/pkg/util"
1616
)
1717

controllers/codebase/service/chain/common_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1717

1818
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
19-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
20-
gitMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/v2/mocks"
19+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
20+
gitMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/mocks"
2121
"github.com/epam/edp-codebase-operator/v2/pkg/util"
2222
)
2323

controllers/codebase/service/chain/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/epam/edp-codebase-operator/v2/controllers/codebase/service/chain/handler"
1111
"github.com/epam/edp-codebase-operator/v2/pkg/gerrit"
12-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
12+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
1313
gitlabci "github.com/epam/edp-codebase-operator/v2/pkg/gitlab"
1414
"github.com/epam/edp-codebase-operator/v2/pkg/gitprovider"
1515
)

controllers/codebase/service/chain/put_deploy_configs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
1111
"github.com/epam/edp-codebase-operator/v2/controllers/codebase/service/template"
12-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
12+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
1313
"github.com/epam/edp-codebase-operator/v2/pkg/util"
1414
)
1515

controllers/codebase/service/chain/put_deploy_configs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1414

1515
codebaseApi "github.com/epam/edp-codebase-operator/v2/api/v1"
16-
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git/v2"
17-
gitServerMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/v2/mocks"
16+
gitproviderv2 "github.com/epam/edp-codebase-operator/v2/pkg/git"
17+
gitServerMocks "github.com/epam/edp-codebase-operator/v2/pkg/git/mocks"
1818
"github.com/epam/edp-codebase-operator/v2/pkg/platform"
1919
"github.com/epam/edp-codebase-operator/v2/pkg/util"
2020
)

0 commit comments

Comments
 (0)