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

Function EnrichOptions

backend/plugins/jenkins/impl/impl.go:236–295  ·  view source on GitHub ↗
(taskCtx plugin.TaskContext,
	op *tasks.JenkinsOptions,
	apiClient *helper.ApiAsyncClient)

Source from the content-addressed store, hash-verified

234}
235
236func 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

Callers 1

PrepareTaskDataMethod · 0.70

Calls 7

ToJenkinsJobMethod · 0.80
WrapMethod · 0.80
GetLoggerMethod · 0.65
FirstMethod · 0.65
GetDalMethod · 0.65
DebugMethod · 0.65
CreateIfNotExistMethod · 0.65

Tested by

no test coverage detected