(taskCtx plugin.TaskContext, op *tasks.BitbucketServerOptions, apiClient *helper.ApiClient)
| 217 | } |
| 218 | |
| 219 | func EnrichOptions(taskCtx plugin.TaskContext, |
| 220 | op *tasks.BitbucketServerOptions, |
| 221 | apiClient *helper.ApiClient) errors.Error { |
| 222 | var repo models.BitbucketServerRepo |
| 223 | // validate the op and set name=owner/repo if this is from advanced mode or bpV100 |
| 224 | err := tasks.ValidateTaskOptions(op) |
| 225 | if err != nil { |
| 226 | return err |
| 227 | } |
| 228 | logger := taskCtx.GetLogger() |
| 229 | err = taskCtx.GetDal().First(&repo, dal.Where( |
| 230 | "connection_id = ? AND bitbucket_id = ?", |
| 231 | op.ConnectionId, op.FullName)) |
| 232 | if err == nil { |
| 233 | if op.ScopeConfigId == 0 { |
| 234 | op.ScopeConfigId = repo.ScopeConfigId |
| 235 | } |
| 236 | } else { |
| 237 | if taskCtx.GetDal().IsErrorNotFound(err) && op.FullName != "" { |
| 238 | var repo *models.BitbucketServerApiRepo |
| 239 | repo, err = tasks.GetApiRepo(op, apiClient) |
| 240 | if err != nil { |
| 241 | return err |
| 242 | } |
| 243 | logger.Debug(fmt.Sprintf("Current repo: %s", repo.Slug)) |
| 244 | scope := repo.ConvertApiScope().(*models.BitbucketServerRepo) |
| 245 | scope.ConnectionId = op.ConnectionId |
| 246 | err = taskCtx.GetDal().CreateIfNotExist(scope) |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | } else { |
| 251 | return errors.Default.Wrap(err, fmt.Sprintf("fail to find repo %s", op.FullName)) |
| 252 | } |
| 253 | } |
| 254 | // Set scope config if it's nil, this has lower priority |
| 255 | if op.BitbucketServerScopeConfig == nil && op.ScopeConfigId != 0 { |
| 256 | var scopeConfig models.BitbucketServerScopeConfig |
| 257 | db := taskCtx.GetDal() |
| 258 | err = db.First(&scopeConfig, dal.Where("id = ?", repo.ScopeConfigId)) |
| 259 | if err != nil && !db.IsErrorNotFound(err) { |
| 260 | return errors.BadInput.Wrap(err, "fail to get scopeConfig") |
| 261 | } |
| 262 | op.BitbucketServerScopeConfig = &scopeConfig |
| 263 | } |
| 264 | if op.BitbucketServerScopeConfig == nil && op.ScopeConfigId == 0 { |
| 265 | op.BitbucketServerScopeConfig = new(models.BitbucketServerScopeConfig) |
| 266 | } |
| 267 | return err |
| 268 | } |
no test coverage detected