(taskCtx plugin.SubTaskContext)
| 39 | } |
| 40 | |
| 41 | func ConvertPlanVcs(taskCtx plugin.SubTaskContext) errors.Error { |
| 42 | db := taskCtx.GetDal() |
| 43 | logger := taskCtx.GetLogger() |
| 44 | rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PLAN_BUILD_TABLE) |
| 45 | cursor, err := db.Cursor( |
| 46 | dal.From(&models.BambooPlanBuildVcsRevision{}), |
| 47 | dal.Join(`left join _tool_bamboo_plan_builds on _tool_bamboo_plan_builds.plan_build_key = _tool_bamboo_plan_build_commits.plan_build_key`), |
| 48 | dal.Where("_tool_bamboo_plan_build_commits.connection_id = ? and _tool_bamboo_plan_builds.plan_key = ?", data.Options.ConnectionId, data.Options.PlanKey)) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | defer cursor.Close() |
| 53 | |
| 54 | planBuildIdGen := didgen.NewDomainIdGenerator(&models.BambooPlanBuild{}) |
| 55 | repoMap := data.Options.GetRepoIdMap() |
| 56 | converter, err := api.NewDataConverter(api.DataConverterArgs{ |
| 57 | InputRowType: reflect.TypeOf(models.BambooPlanBuildVcsRevision{}), |
| 58 | Input: cursor, |
| 59 | RawDataSubTaskArgs: *rawDataSubTaskArgs, |
| 60 | Convert: func(inputRow interface{}) ([]interface{}, errors.Error) { |
| 61 | line := inputRow.(*models.BambooPlanBuildVcsRevision) |
| 62 | domainPlanVcs := &devops.CiCDPipelineCommit{ |
| 63 | PipelineId: planBuildIdGen.Generate(data.Options.ConnectionId, line.PlanBuildKey), |
| 64 | CommitSha: line.VcsRevisionKey, |
| 65 | DisplayTitle: line.DisplayTitle, |
| 66 | Url: line.Url, |
| 67 | } |
| 68 | domainPlanVcs.RepoId = repoMap[line.RepositoryId] |
| 69 | fakeRepoUrl, err := generateFakeRepoUrl(data.ApiClient.GetEndpoint(), line.RepositoryId) |
| 70 | if err != nil { |
| 71 | logger.Warn(err, "generate fake repo url, endpoint: %s, repo id: %d", data.ApiClient.GetEndpoint(), line.RepositoryId) |
| 72 | } else { |
| 73 | domainPlanVcs.RepoUrl = fakeRepoUrl |
| 74 | } |
| 75 | return []interface{}{ |
| 76 | domainPlanVcs, |
| 77 | }, nil |
| 78 | }, |
| 79 | }) |
| 80 | |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | return converter.Execute() |
| 86 | } |
nothing calls this directly
no test coverage detected