Skip to content

Commit f0fb924

Browse files
chore: read service/material (#6101)
* refactoring git material * constants move
1 parent c0f82e9 commit f0fb924

39 files changed

+327
-212
lines changed

Wire.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ func InitializeApp() (*App, error) {
339339

340340
pipeline.NewCiCdPipelineOrchestrator,
341341
wire.Bind(new(pipeline.CiCdPipelineOrchestrator), new(*pipeline.CiCdPipelineOrchestratorImpl)),
342-
pipelineConfig.NewMaterialRepositoryImpl,
343-
wire.Bind(new(pipelineConfig.MaterialRepository), new(*pipelineConfig.MaterialRepositoryImpl)),
344342

345343
// scoped variables start
346344
variables.NewScopedVariableServiceImpl,

api/appbean/AppDetail.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package appbean
1818

1919
import (
20+
"github.com/devtron-labs/devtron/internal/sql/constants"
2021
"github.com/devtron-labs/devtron/internal/sql/models"
2122
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
2223
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
@@ -111,10 +112,10 @@ type CiPipelineDetails struct {
111112
}
112113

113114
type CiPipelineMaterialConfig struct {
114-
Type pipelineConfig.SourceType `json:"type,omitempty" validate:"oneof=SOURCE_TYPE_BRANCH_FIXED SOURCE_TYPE_BRANCH_REGEX SOURCE_TYPE_TAG_ANY WEBHOOK"`
115-
Value string `json:"value,omitempty" `
116-
CheckoutPath string `json:"checkoutPath"`
117-
GitMaterialId int `json:"gitMaterialId"`
115+
Type constants.SourceType `json:"type,omitempty" validate:"oneof=SOURCE_TYPE_BRANCH_FIXED SOURCE_TYPE_BRANCH_REGEX SOURCE_TYPE_TAG_ANY WEBHOOK"`
116+
Value string `json:"value,omitempty" `
117+
CheckoutPath string `json:"checkoutPath"`
118+
GitMaterialId int `json:"gitMaterialId"`
118119
}
119120

120121
type BuildScript struct {

api/restHandler/BulkUpdateRestHandler.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23+
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
2324
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider"
2425
"net/http"
2526
"strconv"
@@ -82,7 +83,7 @@ type BulkUpdateRestHandlerImpl struct {
8283
dockerRegistryConfig pipeline.DockerRegistryConfig
8384
cdHandelr pipeline.CdHandler
8485
appCloneService appClone.AppCloneService
85-
materialRepository pipelineConfig.MaterialRepository
86+
materialRepository repository.MaterialRepository
8687
policyService security2.PolicyService
8788
scanResultRepository security.ImageScanResultRepository
8889
argoUserService argo.ArgoUserService
@@ -105,7 +106,7 @@ func NewBulkUpdateRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, logg
105106
cdHandelr pipeline.CdHandler,
106107
appCloneService appClone.AppCloneService,
107108
appWorkflowService appWorkflow.AppWorkflowService,
108-
materialRepository pipelineConfig.MaterialRepository, policyService security2.PolicyService,
109+
materialRepository repository.MaterialRepository, policyService security2.PolicyService,
109110
scanResultRepository security.ImageScanResultRepository,
110111
argoUserService argo.ArgoUserService) *BulkUpdateRestHandlerImpl {
111112
return &BulkUpdateRestHandlerImpl{

api/restHandler/CoreAppRestHandler.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
app2 "github.com/devtron-labs/devtron/api/restHandler/app/pipeline/configure"
2525
"github.com/devtron-labs/devtron/internal/sql/constants"
2626
appWorkflowBean "github.com/devtron-labs/devtron/pkg/appWorkflow/bean"
27+
read2 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read"
28+
repository3 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/repository"
2729
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider"
2830
"github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
2931
pipelineBean "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
@@ -91,7 +93,7 @@ type CoreAppRestHandlerImpl struct {
9193
appListingService app.AppListingService
9294
propertiesConfigService pipeline.PropertiesConfigService
9395
appWorkflowService appWorkflow.AppWorkflowService
94-
materialRepository pipelineConfig.MaterialRepository
96+
gitMaterialReadService read2.GitMaterialReadService
9597
appWorkflowRepository appWorkflow2.AppWorkflowRepository
9698
environmentRepository repository2.EnvironmentRepository
9799
configMapRepository chartConfig.ConfigMapRepository
@@ -106,11 +108,11 @@ func NewCoreAppRestHandlerImpl(logger *zap.SugaredLogger, userAuthService user.U
106108
enforcer casbin.Enforcer, appCrudOperationService app.AppCrudOperationService, pipelineBuilder pipeline.PipelineBuilder, gitRegistryService gitProvider.GitRegistryConfig,
107109
chartService chart.ChartService, configMapService pipeline.ConfigMapService, appListingService app.AppListingService,
108110
propertiesConfigService pipeline.PropertiesConfigService, appWorkflowService appWorkflow.AppWorkflowService,
109-
materialRepository pipelineConfig.MaterialRepository,
110111
appWorkflowRepository appWorkflow2.AppWorkflowRepository, environmentRepository repository2.EnvironmentRepository, configMapRepository chartConfig.ConfigMapRepository,
111112
chartRepo chartRepoRepository.ChartRepository, teamService team.TeamService,
112113
argoUserService argo.ArgoUserService, pipelineStageService pipeline.PipelineStageService, ciPipelineRepository pipelineConfig.CiPipelineRepository,
113-
gitProviderReadService read.GitProviderReadService) *CoreAppRestHandlerImpl {
114+
gitProviderReadService read.GitProviderReadService,
115+
gitMaterialReadService read2.GitMaterialReadService) *CoreAppRestHandlerImpl {
114116
handler := &CoreAppRestHandlerImpl{
115117
logger: logger,
116118
userAuthService: userAuthService,
@@ -126,7 +128,7 @@ func NewCoreAppRestHandlerImpl(logger *zap.SugaredLogger, userAuthService user.U
126128
appListingService: appListingService,
127129
propertiesConfigService: propertiesConfigService,
128130
appWorkflowService: appWorkflowService,
129-
materialRepository: materialRepository,
131+
gitMaterialReadService: gitMaterialReadService,
130132
appWorkflowRepository: appWorkflowRepository,
131133
environmentRepository: environmentRepository,
132134
configMapRepository: configMapRepository,
@@ -514,7 +516,7 @@ func (handler CoreAppRestHandlerImpl) buildDockerConfig(appId int) (*appBean.Doc
514516
}
515517

516518
//getting gitMaterialUrl by id
517-
gitMaterial, err := handler.materialRepository.FindById(ciConfig.CiBuildConfig.GitMaterialId)
519+
gitMaterial, err := handler.gitMaterialReadService.FindById(ciConfig.CiBuildConfig.GitMaterialId)
518520
if err != nil {
519521
handler.logger.Errorw("error in fetching materialUrl by ID in GetAppAllDetail", "err", err, "gitMaterialId", ciConfig.CiBuildConfig.GitMaterialId)
520522
return nil, err, http.StatusInternalServerError
@@ -730,7 +732,7 @@ func (handler CoreAppRestHandlerImpl) buildCiPipelineResp(appId int, ciPipeline
730732
//build ciPipelineMaterial resp
731733
var ciPipelineMaterialsConfig []*appBean.CiPipelineMaterialConfig
732734
for _, ciMaterial := range ciPipeline.CiMaterial {
733-
gitMaterial, err := handler.materialRepository.FindById(ciMaterial.GitMaterialId)
735+
gitMaterial, err := handler.gitMaterialReadService.FindById(ciMaterial.GitMaterialId)
734736
if err != nil {
735737
handler.logger.Errorw("service err, GitMaterialById in GetAppAllDetail", "err", err, "appId", appId)
736738
return nil, err
@@ -1346,7 +1348,7 @@ func (handler CoreAppRestHandlerImpl) createDockerConfig(appId int, dockerConfig
13461348
}
13471349

13481350
//finding gitMaterial by appId and checkoutPath
1349-
gitMaterial, err := handler.materialRepository.FindByAppIdAndCheckoutPath(appId, dockerConfig.CheckoutPath)
1351+
gitMaterial, err := handler.gitMaterialReadService.FindByAppIdAndCheckoutPath(appId, dockerConfig.CheckoutPath)
13501352
if err != nil {
13511353
handler.logger.Errorw("service err, FindByAppIdAndCheckoutPath in CreateDockerConfig", "err", err, "appId", appId)
13521354
return err, http.StatusInternalServerError
@@ -1633,14 +1635,14 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
16331635
// build ci pipeline materials starts
16341636
var ciMaterialsRequest []*bean.CiMaterial
16351637
for _, ciMaterial := range ciPipelineData.CiPipelineMaterialsConfig {
1636-
var gitMaterial *pipelineConfig.GitMaterial
1638+
var gitMaterial *repository3.GitMaterial
16371639
var err error
16381640
if ciPipelineData.ParentCiPipeline == 0 && ciPipelineData.ParentAppId == 0 {
16391641
//finding gitMaterial by appId and checkoutPath
1640-
gitMaterial, err = handler.materialRepository.FindByAppIdAndCheckoutPath(appId, ciMaterial.CheckoutPath)
1642+
gitMaterial, err = handler.gitMaterialReadService.FindByAppIdAndCheckoutPath(appId, ciMaterial.CheckoutPath)
16411643
} else {
16421644
//if linked CI find git material by it's parentAppId and Id
1643-
gitMaterial, err = handler.materialRepository.FindByAppIdAndGitMaterialId(ciPipelineData.ParentAppId, ciMaterial.GitMaterialId)
1645+
gitMaterial, err = handler.gitMaterialReadService.FindByAppIdAndGitMaterialId(ciPipelineData.ParentAppId, ciMaterial.GitMaterialId)
16441646
}
16451647
if err != nil {
16461648
handler.logger.Errorw("service err, FindByAppIdAndCheckoutPath in CreateWorkflows", "err", err, "appId", appId)
@@ -2172,7 +2174,7 @@ func (handler CoreAppRestHandlerImpl) ValidateAppWorkflowRequest(createAppWorkfl
21722174
ciMaterialCheckoutPaths := make([]string, 0)
21732175
for _, ciPipelineMaterialConfig := range workflow.CiPipeline.CiPipelineMaterialsConfig {
21742176
// value for webhook type CiPipelineMaterial should be a valid json string
2175-
if ciPipelineMaterialConfig.Type == pipelineConfig.SOURCE_TYPE_WEBHOOK {
2177+
if ciPipelineMaterialConfig.Type == constants.SOURCE_TYPE_WEBHOOK {
21762178
var jsonValueMap map[string]interface{}
21772179
err := json.Unmarshal([]byte(ciPipelineMaterialConfig.Value), &jsonValueMap)
21782180
if err != nil {

api/restHandler/app/pipeline/configure/BuildPipelineRestHandler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"encoding/json"
2222
"errors"
2323
"fmt"
24-
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
2524
"github.com/devtron-labs/devtron/internal/sql/constants"
25+
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
2626
bean2 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2727
"golang.org/x/exp/maps"
2828
"io"
@@ -340,7 +340,7 @@ func (handler *PipelineConfigRestHandlerImpl) PatchCiMaterialSourceWithAppIdAndE
340340
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
341341
return
342342
}
343-
if !(patchRequest.Source.Type == pipelineConfig.SOURCE_TYPE_BRANCH_FIXED || patchRequest.Source.Type == pipelineConfig.SOURCE_TYPE_BRANCH_REGEX) {
343+
if !(patchRequest.Source.Type == constants.SOURCE_TYPE_BRANCH_FIXED || patchRequest.Source.Type == constants.SOURCE_TYPE_BRANCH_REGEX) {
344344
handler.Logger.Errorw("Unsupported source type, PatchCiMaterialSource", "err", err, "PatchCiMaterialSource", patchRequest)
345345
common.WriteJsonResp(w, err, "source.type not supported", http.StatusBadRequest)
346346
return
@@ -875,7 +875,7 @@ func (handler *PipelineConfigRestHandlerImpl) RefreshMaterials(w http.ResponseWr
875875
return
876876
}
877877
handler.Logger.Infow("request payload, RefreshMaterials", "gitMaterialId", gitMaterialId)
878-
material, err := handler.materialRepository.FindById(gitMaterialId)
878+
material, err := handler.gitMaterialReadService.FindById(gitMaterialId)
879879
if err != nil {
880880
handler.Logger.Errorw("service err, RefreshMaterials", "err", err, "gitMaterialId", gitMaterialId)
881881
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)

api/restHandler/app/pipeline/configure/PipelineConfigRestHandler.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging"
2525
imageTaggingRead "github.com/devtron-labs/devtron/pkg/build/artifacts/imageTagging/read"
26+
read2 "github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read"
2627
gitProviderRead "github.com/devtron-labs/devtron/pkg/build/git/gitProvider/read"
2728
bean3 "github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2829
"github.com/devtron-labs/devtron/pkg/chart/gitOpsConfig"
@@ -120,7 +121,7 @@ type PipelineConfigRestHandlerImpl struct {
120121
dockerRegistryConfig pipeline.DockerRegistryConfig
121122
cdHandler pipeline.CdHandler
122123
appCloneService appClone.AppCloneService
123-
materialRepository pipelineConfig.MaterialRepository
124+
gitMaterialReadService read2.GitMaterialReadService
124125
policyService security2.PolicyService
125126
scanResultRepository security.ImageScanResultRepository
126127
gitProviderReadService gitProviderRead.GitProviderReadService
@@ -154,7 +155,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger
154155
appCloneService appClone.AppCloneService,
155156
deploymentTemplateService generateManifest.DeploymentTemplateService,
156157
appWorkflowService appWorkflow.AppWorkflowService,
157-
materialRepository pipelineConfig.MaterialRepository, policyService security2.PolicyService,
158+
gitMaterialReadService read2.GitMaterialReadService, policyService security2.PolicyService,
158159
scanResultRepository security.ImageScanResultRepository,
159160
argoUserService argo.ArgoUserService, ciPipelineMaterialRepository pipelineConfig.CiPipelineMaterialRepository,
160161
imageTaggingReadService imageTaggingRead.ImageTaggingReadService,
@@ -189,7 +190,7 @@ func NewPipelineRestHandlerImpl(pipelineBuilder pipeline.PipelineBuilder, Logger
189190
cdHandler: cdHandler,
190191
appCloneService: appCloneService,
191192
appWorkflowService: appWorkflowService,
192-
materialRepository: materialRepository,
193+
gitMaterialReadService: gitMaterialReadService,
193194
policyService: policyService,
194195
scanResultRepository: scanResultRepository,
195196
argoUserService: argoUserService,

client/telemetry/TelemetryEventClientExtended.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
cloudProviderIdentifier "github.com/devtron-labs/common-lib/cloud-provider-identifier"
2222
client "github.com/devtron-labs/devtron/api/helm-app/gRPC"
23+
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial/read"
2324
repository3 "github.com/devtron-labs/devtron/pkg/build/git/gitProvider/repository"
2425
"github.com/devtron-labs/devtron/pkg/build/pipeline/bean"
2526
ciConfig "github.com/devtron-labs/devtron/pkg/build/pipeline/read"
@@ -60,7 +61,7 @@ type TelemetryEventClientImplExtended struct {
6061
appRepository app.AppRepository
6162
ciWorkflowRepository pipelineConfig.CiWorkflowRepository
6263
cdWorkflowRepository pipelineConfig.CdWorkflowRepository
63-
materialRepository pipelineConfig.MaterialRepository
64+
gitMaterialReadService read.GitMaterialReadService
6465
ciTemplateRepository pipelineConfig.CiTemplateRepository
6566
chartRepository chartRepoRepository.ChartRepository
6667
ciBuildConfigService pipeline.CiBuildConfigService
@@ -77,7 +78,7 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
7778
ssoLoginService sso.SSOLoginService, appRepository app.AppRepository,
7879
ciWorkflowRepository pipelineConfig.CiWorkflowRepository, cdWorkflowRepository pipelineConfig.CdWorkflowRepository,
7980
dockerArtifactStoreRepository dockerRegistryRepository.DockerArtifactStoreRepository,
80-
materialRepository pipelineConfig.MaterialRepository, ciTemplateRepository pipelineConfig.CiTemplateRepository,
81+
gitMaterialReadService read.GitMaterialReadService, ciTemplateRepository pipelineConfig.CiTemplateRepository,
8182
chartRepository chartRepoRepository.ChartRepository, userAuditService user2.UserAuditService,
8283
ciBuildConfigService pipeline.CiBuildConfigService, moduleRepository moduleRepo.ModuleRepository, serverDataStore *serverDataStore.ServerDataStore,
8384
helmAppClient client.HelmAppClient, InstalledAppRepository repository2.InstalledAppRepository, userAttributesRepository repository.UserAttributesRepository,
@@ -97,7 +98,7 @@ func NewTelemetryEventClientImplExtended(logger *zap.SugaredLogger, client *http
9798
appRepository: appRepository,
9899
cdWorkflowRepository: cdWorkflowRepository,
99100
ciWorkflowRepository: ciWorkflowRepository,
100-
materialRepository: materialRepository,
101+
gitMaterialReadService: gitMaterialReadService,
101102
ciTemplateRepository: ciTemplateRepository,
102103
chartRepository: chartRepository,
103104
ciBuildConfigService: ciBuildConfigService,
@@ -303,7 +304,7 @@ func (impl *TelemetryEventClientImplExtended) SendSummaryEvent(eventType string)
303304

304305
payload.AppCount = len(appIds)
305306
if len(appIds) < AppsCount {
306-
payload.AppsWithGitRepoConfigured, err = impl.materialRepository.FindNumberOfAppsWithGitRepo(appIds)
307+
payload.AppsWithGitRepoConfigured, err = impl.gitMaterialReadService.FindNumberOfAppsWithGitRepo(appIds)
307308
if err != nil {
308309
impl.logger.Errorw("exception caught inside telemetry summary event,while retrieving AppsWithGitRepoConfigured", "err", err)
309310
}

cmd/external-app/wire.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import (
7070
"github.com/devtron-labs/devtron/pkg/appStore/installedApp/service/FullMode/deployment"
7171
"github.com/devtron-labs/devtron/pkg/argoRepositoryCreds"
7272
"github.com/devtron-labs/devtron/pkg/attributes"
73+
"github.com/devtron-labs/devtron/pkg/build/git/gitMaterial"
7374
delete2 "github.com/devtron-labs/devtron/pkg/delete"
7475
"github.com/devtron-labs/devtron/pkg/deployment/common"
7576
"github.com/devtron-labs/devtron/pkg/deployment/gitOps"
@@ -125,11 +126,10 @@ func InitializeApp() (*App, error) {
125126
util2.GetACDAuthConfig,
126127
telemetry.NewPosthogClient,
127128
delete2.NewDeleteServiceImpl,
129+
gitMaterial.GitMaterialWireSet,
128130

129131
sql.NewTransactionUtilImpl,
130132

131-
pipelineConfig.NewMaterialRepositoryImpl,
132-
wire.Bind(new(pipelineConfig.MaterialRepository), new(*pipelineConfig.MaterialRepositoryImpl)),
133133
// appStatus
134134
appStatus.NewAppStatusRepositoryImpl,
135135
wire.Bind(new(appStatus.AppStatusRepository), new(*appStatus.AppStatusRepositoryImpl)),

cmd/external-app/wire_gen.go

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/sql/constants/SourceType.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package constants
2+
3+
type SourceType string
4+
5+
const (
6+
SOURCE_TYPE_BRANCH_FIXED SourceType = "SOURCE_TYPE_BRANCH_FIXED"
7+
SOURCE_TYPE_BRANCH_REGEX SourceType = "SOURCE_TYPE_BRANCH_REGEX"
8+
SOURCE_TYPE_TAG_ANY SourceType = "SOURCE_TYPE_TAG_ANY"
9+
SOURCE_TYPE_WEBHOOK SourceType = "WEBHOOK"
10+
)

0 commit comments

Comments
 (0)