(taskCtx plugin.TaskContext, op *tasks.JenkinsOptions, apiClient *helper.ApiAsyncClient)
| 234 | } |
| 235 | |
| 236 | func EnrichOptions(taskCtx plugin.TaskContext, |
| 237 | op *tasks.JenkinsOptions, |
| 238 | apiClient *helper.ApiAsyncClient) errors.Error { |
| 239 | jenkinsJob := &models.JenkinsJob{} |
| 240 | if op.JobFullName == "" { |
| 241 | op.JobFullName = op.FullName |
| 242 | } |
| 243 | // validate the op and set name=owner/repo if this is from advanced mode or bpV100 |
| 244 | op, err := tasks.ValidateTaskOptions(op) |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | log := taskCtx.GetLogger() |
| 249 | |
| 250 | // for advanced mode or others which we only have name, for bp v200, we have ScopeConfigId |
| 251 | err = taskCtx.GetDal().First(jenkinsJob, |
| 252 | dal.Where(`connection_id = ? and full_name = ?`, |
| 253 | op.ConnectionId, op.JobFullName)) |
| 254 | if err == nil { |
| 255 | if op.ScopeConfigId == 0 { |
| 256 | op.ScopeConfigId = jenkinsJob.ScopeConfigId |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | err = api.GetJob(apiClient, op.JobPath, op.JobName, op.JobFullName, 100, func(job *models.Job, isPath bool) errors.Error { |
| 261 | log.Debug(fmt.Sprintf("Current job: %s", job.FullName)) |
| 262 | op.JobPath = job.Path |
| 263 | op.URL = job.URL |
| 264 | op.Class = job.Class |
| 265 | jenkinsJob := job.ToJenkinsJob() |
| 266 | |
| 267 | jenkinsJob.ConnectionId = op.ConnectionId |
| 268 | jenkinsJob.ScopeConfigId = op.ScopeConfigId |
| 269 | |
| 270 | err = taskCtx.GetDal().CreateIfNotExist(jenkinsJob) |
| 271 | return err |
| 272 | }) |
| 273 | if err != nil { |
| 274 | return err |
| 275 | } |
| 276 | |
| 277 | if !strings.HasSuffix(op.JobPath, "/") { |
| 278 | op.JobPath = fmt.Sprintf("%s/", op.JobPath) |
| 279 | } |
| 280 | // We only set op.JenkinsScopeConfig when it's nil and we have op.ScopeConfigId != 0 |
| 281 | if op.ScopeConfig.DeploymentPattern == "" && op.ScopeConfig.ProductionPattern == "" && op.ScopeConfigId != 0 { |
| 282 | var scopeConfig models.JenkinsScopeConfig |
| 283 | err = taskCtx.GetDal().First(&scopeConfig, dal.Where("id = ?", op.ScopeConfigId)) |
| 284 | if err != nil { |
| 285 | return errors.BadInput.Wrap(err, "fail to get scopeConfig") |
| 286 | } |
| 287 | op.ScopeConfig = &scopeConfig |
| 288 | } |
| 289 | |
| 290 | if op.ScopeConfig.DeploymentPattern == "" && op.ScopeConfig.ProductionPattern == "" && op.ScopeConfigId == 0 { |
| 291 | op.ScopeConfig = new(models.JenkinsScopeConfig) |
| 292 | } |
| 293 |
no test coverage detected