MCPcopy Index your code
hub / github.com/apache/devlake / validateBlueprintAndMakePlan

Function validateBlueprintAndMakePlan

backend/server/services/blueprint.go:133–179  ·  view source on GitHub ↗
(blueprint *models.Blueprint)

Source from the content-addressed store, hash-verified

131}
132
133func validateBlueprintAndMakePlan(blueprint *models.Blueprint) errors.Error {
134 // validation
135 err := vld.Struct(blueprint)
136 if err != nil {
137 return errors.BadInput.WrapRaw(err)
138 }
139
140 // checking if the project exist
141 if blueprint.ProjectName != "" {
142 _, err := GetProject(blueprint.ProjectName)
143 if err != nil {
144 return errors.Default.Wrap(err, fmt.Sprintf("invalid projectName: [%s] for the blueprint [%s]", blueprint.ProjectName, blueprint.Name))
145 }
146
147 bp, err := GetBlueprintByProjectName(blueprint.ProjectName)
148 if err != nil {
149 return err
150 }
151 if bp != nil {
152 if bp.ID != blueprint.ID {
153 return errors.Default.New(fmt.Sprintf("Each project can only be used by one blueprint. The currently selected projectName: [%s] has been used by blueprint: [id:%d] [name:%s] and cannot be reused.", bp.ProjectName, bp.ID, bp.Name))
154 }
155 }
156 }
157
158 if strings.ToLower(blueprint.CronConfig) == "manual" {
159 blueprint.IsManual = true
160 }
161 if !blueprint.IsManual {
162 _, err = cron.ParseStandard(blueprint.CronConfig)
163 if err != nil {
164 return errors.Default.Wrap(err, "invalid cronConfig")
165 }
166 }
167 if blueprint.Mode == models.BLUEPRINT_MODE_ADVANCED {
168 if len(blueprint.Plan) == 0 {
169 return errors.BadInput.New("invalid plan")
170 }
171 } else if blueprint.Mode == models.BLUEPRINT_MODE_NORMAL {
172 var e errors.Error
173 blueprint.Plan, e = MakePlanForBlueprint(blueprint, &blueprint.SyncPolicy)
174 if e != nil {
175 return e
176 }
177 }
178 return nil
179}
180
181func saveBlueprint(blueprint *models.Blueprint) (*models.Blueprint, errors.Error) {
182 // validation

Callers 1

saveBlueprintFunction · 0.85

Calls 6

MakePlanForBlueprintFunction · 0.85
WrapRawMethod · 0.80
WrapMethod · 0.80
GetProjectFunction · 0.70
NewMethod · 0.65

Tested by

no test coverage detected