(taskCtx plugin.TaskContext, op *tasks.GithubOptions, apiClient *helper.ApiClient, )
| 276 | } |
| 277 | |
| 278 | func EnrichOptions(taskCtx plugin.TaskContext, |
| 279 | op *tasks.GithubOptions, |
| 280 | apiClient *helper.ApiClient, |
| 281 | ) errors.Error { |
| 282 | var githubRepo models.GithubRepo |
| 283 | // validate the op and set name=owner/repo if this is from advanced mode or bpV100 |
| 284 | err := tasks.ValidateTaskOptions(op) |
| 285 | if err != nil { |
| 286 | return err |
| 287 | } |
| 288 | logger := taskCtx.GetLogger() |
| 289 | // for advanced mode or others which we only have name, for bp v200, we have githubId |
| 290 | err = taskCtx.GetDal().First(&githubRepo, dal.Where( |
| 291 | "connection_id = ? AND( full_name = ? OR github_id = ?)", |
| 292 | op.ConnectionId, op.Name, op.GithubId)) |
| 293 | if err == nil { |
| 294 | op.Name = githubRepo.FullName |
| 295 | op.GithubId = githubRepo.GithubId |
| 296 | if op.ScopeConfigId == 0 { |
| 297 | op.ScopeConfigId = githubRepo.ScopeConfigId |
| 298 | } |
| 299 | } else { |
| 300 | if taskCtx.GetDal().IsErrorNotFound(err) && op.Name != "" { |
| 301 | var repo *tasks.GithubApiRepo |
| 302 | repo, err = api.MemorizedGetApiRepo(repo, op, apiClient) |
| 303 | if err != nil { |
| 304 | return err |
| 305 | } |
| 306 | logger.Debug(fmt.Sprintf("Current repo: %s", repo.FullName)) |
| 307 | scope := convertApiRepoToScope(repo, op.ConnectionId) |
| 308 | err = taskCtx.GetDal().CreateIfNotExist(scope) |
| 309 | if err != nil { |
| 310 | return err |
| 311 | } |
| 312 | op.GithubId = repo.GithubId |
| 313 | } else { |
| 314 | return errors.Default.Wrap(err, fmt.Sprintf("fail to find repo %s", op.Name)) |
| 315 | } |
| 316 | } |
| 317 | // Set GithubScopeConfig if it's nil, this has lower priority |
| 318 | if op.ScopeConfig == nil && op.ScopeConfigId != 0 { |
| 319 | var scopeConfig models.GithubScopeConfig |
| 320 | db := taskCtx.GetDal() |
| 321 | err = db.First(&scopeConfig, dal.Where("id = ?", githubRepo.ScopeConfigId)) |
| 322 | if err != nil && !db.IsErrorNotFound(err) { |
| 323 | return errors.BadInput.Wrap(err, "fail to get scopeConfig") |
| 324 | } |
| 325 | op.ScopeConfig = &scopeConfig |
| 326 | } |
| 327 | if op.ScopeConfig == nil && op.ScopeConfigId == 0 { |
| 328 | op.ScopeConfig = new(models.GithubScopeConfig) |
| 329 | } |
| 330 | return err |
| 331 | } |
| 332 | |
| 333 | func convertApiRepoToScope(repo *tasks.GithubApiRepo, connectionId uint64) *models.GithubRepo { |
| 334 | var scope models.GithubRepo |
no test coverage detected