@@ -19,6 +19,7 @@ package util
1919
2020import (
2121 "fmt"
22+ appStoreBean "github.com/devtron-labs/devtron/pkg/appStore/bean"
2223 "github.com/devtron-labs/devtron/util"
2324 "io/ioutil"
2425 "math/rand"
@@ -43,7 +44,7 @@ type ChartWorkingDir string
4344type ChartTemplateService interface {
4445 CreateChart (chartMetaData * chart.Metadata , refChartLocation string , templateName string ) (* ChartValues , * ChartGitAttribute , error )
4546 GetChartVersion (location string ) (string , error )
46- CreateChartProxy (chartMetaData * chart.Metadata , refChartLocation string , templateName string , version string , envName string , appName string ) (string , * ChartGitAttribute , error )
47+ CreateChartProxy (chartMetaData * chart.Metadata , refChartLocation string , templateName string , version string , envName string , installAppVersionRequest * appStoreBean. InstallAppVersionDTO ) (string , * ChartGitAttribute , error )
4748 GitPull (clonedDir string , repoUrl string , appStoreName string ) error
4849 GetGitOpsRepoName (appName string ) string
4950 GetGitOpsRepoNameFromUrl (gitRepoUrl string ) string
@@ -322,7 +323,7 @@ func (impl ChartTemplateServiceImpl) getDir() string {
322323 return strconv .FormatInt (r1 , 10 )
323324}
324325
325- func (impl ChartTemplateServiceImpl ) CreateChartProxy (chartMetaData * chart.Metadata , refChartLocation string , templateName string , version string , envName string , appName string ) (string , * ChartGitAttribute , error ) {
326+ func (impl ChartTemplateServiceImpl ) CreateChartProxy (chartMetaData * chart.Metadata , refChartLocation string , templateName string , version string , envName string , installAppVersionRequest * appStoreBean. InstallAppVersionDTO ) (string , * ChartGitAttribute , error ) {
326327 chartMetaData .ApiVersion = "v2" // ensure always v2
327328 dir := impl .getDir ()
328329 chartDir := filepath .Join (string (impl .chartWorkingDir ), dir )
@@ -345,7 +346,7 @@ func (impl ChartTemplateServiceImpl) CreateChartProxy(chartMetaData *chart.Metad
345346 return "" , nil , err
346347 }
347348
348- chartGitAttr , err := impl .createAndPushToGitChartProxy (chartMetaData .Name , templateName , version , chartDir , envName , appName )
349+ chartGitAttr , err := impl .createAndPushToGitChartProxy (chartMetaData .Name , templateName , version , chartDir , envName , installAppVersionRequest )
349350 if err != nil {
350351 impl .logger .Errorw ("error in pushing chart to git " , "path" , archivePath , "err" , err )
351352 return "" , nil , err
@@ -362,11 +363,14 @@ func (impl ChartTemplateServiceImpl) CreateChartProxy(chartMetaData *chart.Metad
362363 return valuesYaml , chartGitAttr , nil
363364}
364365
365- func (impl ChartTemplateServiceImpl ) createAndPushToGitChartProxy (appStoreName , baseTemplateName , version , tmpChartLocation string , envName string , appName string ) (chartGitAttribute * ChartGitAttribute , err error ) {
366+ func (impl ChartTemplateServiceImpl ) createAndPushToGitChartProxy (appStoreName , baseTemplateName , version , tmpChartLocation string , envName string , installAppVersionRequest * appStoreBean. InstallAppVersionDTO ) (chartGitAttribute * ChartGitAttribute , err error ) {
366367 //baseTemplateName replace whitespace
367368 space := regexp .MustCompile (`\s+` )
368369 appStoreName = space .ReplaceAllString (appStoreName , "-" )
369- gitOpsRepoName := impl .GetGitOpsRepoName (appStoreName )
370+ if len (installAppVersionRequest .GitOpsRepoName ) == 0 {
371+ gitOpsRepoName := impl .GetGitOpsRepoName (appStoreName )
372+ installAppVersionRequest .GitOpsRepoName = gitOpsRepoName
373+ }
370374 gitOpsConfigBitbucket , err := impl .gitFactory .gitOpsRepository .GetGitOpsConfigByProvider (BITBUCKET_PROVIDER )
371375 if err != nil {
372376 if err == pg .ErrNoRows {
@@ -377,14 +381,14 @@ func (impl ChartTemplateServiceImpl) createAndPushToGitChartProxy(appStoreName,
377381 return nil , err
378382 }
379383 }
380- repoUrl , _ , detailedError := impl .gitFactory .Client .CreateRepository (gitOpsRepoName , "helm chart for " + gitOpsRepoName , gitOpsConfigBitbucket .BitBucketWorkspaceId , gitOpsConfigBitbucket .BitBucketProjectKey )
384+ repoUrl , _ , detailedError := impl .gitFactory .Client .CreateRepository (installAppVersionRequest . GitOpsRepoName , "helm chart for " + installAppVersionRequest . GitOpsRepoName , gitOpsConfigBitbucket .BitBucketWorkspaceId , gitOpsConfigBitbucket .BitBucketProjectKey )
381385 for _ , err := range detailedError .StageErrorMap {
382386 if err != nil {
383- impl .logger .Errorw ("error in creating git project" , "name" , gitOpsRepoName , "err" , err )
387+ impl .logger .Errorw ("error in creating git project" , "name" , installAppVersionRequest . GitOpsRepoName , "err" , err )
384388 return nil , err
385389 }
386390 }
387- chartDir := fmt .Sprintf ("%s-%s" , appName , impl .getDir ())
391+ chartDir := fmt .Sprintf ("%s-%s" , installAppVersionRequest . AppName , impl .getDir ())
388392 clonedDir := impl .gitFactory .gitService .GetCloneDirectory (chartDir )
389393 if _ , err := os .Stat (clonedDir ); os .IsNotExist (err ) {
390394 clonedDir , err = impl .gitFactory .gitService .Clone (repoUrl , chartDir )
@@ -399,7 +403,7 @@ func (impl ChartTemplateServiceImpl) createAndPushToGitChartProxy(appStoreName,
399403 }
400404 }
401405
402- acdAppName := fmt .Sprintf ("%s-%s" , appName , envName )
406+ acdAppName := fmt .Sprintf ("%s-%s" , installAppVersionRequest . AppName , envName )
403407 dir := filepath .Join (clonedDir , acdAppName )
404408 err = os .MkdirAll (dir , os .ModePerm )
405409 if err != nil {
0 commit comments