MCPcopy
hub / github.com/apache/devlake / EnrichOptions

Function EnrichOptions

backend/plugins/bitbucket/impl/impl.go:258–307  ·  view source on GitHub ↗
(taskCtx plugin.TaskContext,
	op *tasks.BitbucketOptions,
	apiClient *helper.ApiClient)

Source from the content-addressed store, hash-verified

256}
257
258func EnrichOptions(taskCtx plugin.TaskContext,
259 op *tasks.BitbucketOptions,
260 apiClient *helper.ApiClient) errors.Error {
261 var repo models.BitbucketRepo
262 // validate the op and set name=owner/repo if this is from advanced mode or bpV100
263 err := tasks.ValidateTaskOptions(op)
264 if err != nil {
265 return err
266 }
267 logger := taskCtx.GetLogger()
268 err = taskCtx.GetDal().First(&repo, dal.Where(
269 "connection_id = ? AND bitbucket_id = ?",
270 op.ConnectionId, op.FullName))
271 if err == nil {
272 if op.ScopeConfigId == 0 {
273 op.ScopeConfigId = repo.ScopeConfigId
274 }
275 } else {
276 if taskCtx.GetDal().IsErrorNotFound(err) && op.FullName != "" {
277 var repo *models.BitbucketApiRepo
278 repo, err = tasks.GetApiRepo(op, apiClient)
279 if err != nil {
280 return err
281 }
282 logger.Debug(fmt.Sprintf("Current repo: %s", repo.FullName))
283 scope := repo.ConvertApiScope()
284 scope.ConnectionId = op.ConnectionId
285 err = taskCtx.GetDal().CreateIfNotExist(scope)
286 if err != nil {
287 return err
288 }
289 } else {
290 return errors.Default.Wrap(err, fmt.Sprintf("fail to find repo %s", op.FullName))
291 }
292 }
293 // Set GithubScopeConfig if it's nil, this has lower priority
294 if op.BitbucketScopeConfig == nil && op.ScopeConfigId != 0 {
295 var scopeConfig models.BitbucketScopeConfig
296 db := taskCtx.GetDal()
297 err = db.First(&scopeConfig, dal.Where("id = ?", repo.ScopeConfigId))
298 if err != nil && !db.IsErrorNotFound(err) {
299 return errors.BadInput.Wrap(err, "fail to get scopeConfig")
300 }
301 op.BitbucketScopeConfig = &scopeConfig
302 }
303 if op.BitbucketScopeConfig == nil && op.ScopeConfigId == 0 {
304 op.BitbucketScopeConfig = new(models.BitbucketScopeConfig)
305 }
306 return err
307}

Callers 1

PrepareTaskDataMethod · 0.70

Calls 8

ConvertApiScopeMethod · 0.95
WrapMethod · 0.80
GetLoggerMethod · 0.65
FirstMethod · 0.65
GetDalMethod · 0.65
IsErrorNotFoundMethod · 0.65
DebugMethod · 0.65
CreateIfNotExistMethod · 0.65

Tested by

no test coverage detected