likyh commented on code in PR #3959:
URL: 
https://github.com/apache/incubator-devlake/pull/3959#discussion_r1050646485


##########
plugins/jenkins/impl/impl.go:
##########
@@ -230,3 +203,93 @@ func (plugin Jenkins) Close(taskCtx core.TaskContext) 
errors.Error {
        data.ApiClient.Release()
        return nil
 }
+
+func EnrichOptions(taskCtx core.TaskContext,
+       op *tasks.JenkinsOptions,
+       apiClient *helper.ApiAsyncClient) errors.Error {
+       jenkinsJob := &models.JenkinsJob{}
+       // If this is from BpV200, we should set JobFullName to scopeId
+       if op.JobFullName == "" {
+               op.JobFullName = op.ScopeId
+       }
+       // validate the op and set name=owner/repo if this is from advanced 
mode or bpV100
+       op, err := tasks.ValidateTaskOptions(op)
+       if err != nil {
+               return err
+       }
+       log := taskCtx.GetLogger()
+
+       // We only set op.JenkinsTransformationRule when it's nil and we have 
op.TransformationRuleId != 0
+       if op.JenkinsTransformationRule == nil && op.TransformationRuleId != 0 {
+               var transformationRule models.JenkinsTransformationRule
+               err = taskCtx.GetDal().First(&transformationRule, dal.Where("id 
= ?", op.TransformationRuleId))
+               if err != nil {
+                       return errors.BadInput.Wrap(err, "fail to get 
transformationRule")
+               }
+               op.JenkinsTransformationRule = &transformationRule
+       }
+
+       if op.JenkinsTransformationRule == nil && op.TransformationRuleId == 0 {
+               op.JenkinsTransformationRule = 
new(models.JenkinsTransformationRule)
+       }
+
+       // for advanced mode or others which we only have name, for bp v200, we 
have githubId
+       err = taskCtx.GetDal().First(jenkinsJob,
+               dal.Where(`connection_id = ? and full_name = ?`,
+                       op.ConnectionId, op.JobFullName))
+       if err == nil {
+               op.Name = jenkinsJob.Name
+               op.JobPath = jenkinsJob.Path
+               if op.TransformationRuleId == 0 {
+                       op.TransformationRuleId = 
jenkinsJob.TransformationRuleId
+               }
+       } else {
+               if taskCtx.GetDal().IsErrorNotFound(err) && op.JobFullName != 
"" {
+                       //
+                       pathSplit := strings.Split(op.JobFullName, "/")
+                       lastOne := len(pathSplit)
+                       path := ""
+                       name := ""
+                       for i, split := range pathSplit {

Review Comment:
   'job/' + strings.Join('job/', pathSplit) ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to