Skip to content

Commit 50efb50

Browse files
support given for cloning linked ci pipelines via workflow cloning API (#2944)
1 parent 49f4244 commit 50efb50

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

api/appbean/AppDetail.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,16 @@ type CiPipelineDetails struct {
8686
PreBuildStage *bean.PipelineStageDto `json:"preBuildStage,omitempty"`
8787
PostBuildStage *bean.PipelineStageDto `json:"postBuildStage,omitempty"`
8888
IsExternal bool `json:"isExternal"` // true for linked and external
89+
ParentCiPipeline int `json:"parentCiPipeline,omitempty"`
90+
ParentAppId int `json:"parentAppId,omitempty"`
91+
LinkedCount int `json:"linkedCount,omitempty"`
8992
}
9093

9194
type CiPipelineMaterialConfig struct {
92-
Type pipelineConfig.SourceType `json:"type,omitempty" validate:"oneof=SOURCE_TYPE_BRANCH_FIXED WEBHOOK"`
93-
Value string `json:"value,omitempty" `
94-
CheckoutPath string `json:"checkoutPath"`
95+
Type pipelineConfig.SourceType `json:"type,omitempty" validate:"oneof=SOURCE_TYPE_BRANCH_FIXED WEBHOOK"`
96+
Value string `json:"value,omitempty" `
97+
CheckoutPath string `json:"checkoutPath"`
98+
GitMaterialId int `json:"gitMaterialId"`
9599
}
96100

97101
type BuildScript struct {

api/restHandler/CoreAppRestHandler.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ func (handler CoreAppRestHandlerImpl) buildCiPipelineResp(appId int, ciPipeline
680680
DockerBuildArgs: ciPipeline.DockerArgs,
681681
VulnerabilityScanEnabled: ciPipeline.ScanEnabled,
682682
IsExternal: ciPipeline.IsExternal,
683+
ParentCiPipeline: ciPipeline.ParentCiPipeline,
684+
ParentAppId: ciPipeline.ParentAppId,
685+
LinkedCount: ciPipeline.LinkedCount,
683686
}
684687

685688
//build ciPipelineMaterial resp
@@ -691,9 +694,10 @@ func (handler CoreAppRestHandlerImpl) buildCiPipelineResp(appId int, ciPipeline
691694
return nil, err
692695
}
693696
ciPipelineMaterialConfig := &appBean.CiPipelineMaterialConfig{
694-
Type: ciMaterial.Source.Type,
695-
Value: ciMaterial.Source.Value,
696-
CheckoutPath: gitMaterial.CheckoutPath,
697+
Type: ciMaterial.Source.Type,
698+
Value: ciMaterial.Source.Value,
699+
CheckoutPath: gitMaterial.CheckoutPath,
700+
GitMaterialId: gitMaterial.Id,
697701
}
698702
ciPipelineMaterialsConfig = append(ciPipelineMaterialsConfig, ciPipelineMaterialConfig)
699703
}
@@ -1534,7 +1538,7 @@ func (handler CoreAppRestHandlerImpl) createWorkflowInDb(workflowName string, ap
15341538
func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32, workflowId int, ciPipelineData *appBean.CiPipelineDetails) (int, error) {
15351539

15361540
// if ci pipeline is of external type, then throw error as we are not supporting it as of now
1537-
if ciPipelineData.IsExternal {
1541+
if ciPipelineData.ParentCiPipeline == 0 && ciPipelineData.ParentAppId == 0 && ciPipelineData.IsExternal {
15381542
err := errors.New("external ci pipeline creation is not supported yet")
15391543
handler.logger.Error("external ci pipeline creation is not supported yet")
15401544
return 0, err
@@ -1543,8 +1547,15 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
15431547
// build ci pipeline materials starts
15441548
var ciMaterialsRequest []*bean.CiMaterial
15451549
for _, ciMaterial := range ciPipelineData.CiPipelineMaterialsConfig {
1546-
//finding gitMaterial by appId and checkoutPath
1547-
gitMaterial, err := handler.materialRepository.FindByAppIdAndCheckoutPath(appId, ciMaterial.CheckoutPath)
1550+
var gitMaterial *pipelineConfig.GitMaterial
1551+
var err error
1552+
if ciPipelineData.ParentCiPipeline == 0 && ciPipelineData.ParentAppId == 0 {
1553+
//finding gitMaterial by appId and checkoutPath
1554+
gitMaterial, err = handler.materialRepository.FindByAppIdAndCheckoutPath(appId, ciMaterial.CheckoutPath)
1555+
} else {
1556+
//if linkedci find git material by it's id
1557+
gitMaterial, err = handler.materialRepository.FindById(ciMaterial.GitMaterialId)
1558+
}
15481559
if err != nil {
15491560
handler.logger.Errorw("service err, FindByAppIdAndCheckoutPath in CreateWorkflows", "err", err, "appId", appId)
15501561
return 0, err
@@ -1587,6 +1598,9 @@ func (handler CoreAppRestHandlerImpl) createCiPipeline(appId int, userId int32,
15871598
CiMaterial: ciMaterialsRequest,
15881599
PreBuildStage: ciPipelineData.PreBuildStage,
15891600
PostBuildStage: ciPipelineData.PostBuildStage,
1601+
ParentCiPipeline: ciPipelineData.ParentCiPipeline,
1602+
ParentAppId: ciPipelineData.ParentAppId,
1603+
LinkedCount: ciPipelineData.LinkedCount,
15901604
},
15911605
}
15921606

0 commit comments

Comments
 (0)