MCPcopy Index your code
hub / github.com/apache/devlake / ConvertPlanVcs

Function ConvertPlanVcs

backend/plugins/bamboo/tasks/plan_commit_convertor.go:41–86  ·  view source on GitHub ↗
(taskCtx plugin.SubTaskContext)

Source from the content-addressed store, hash-verified

39}
40
41func 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}

Callers

nothing calls this directly

Calls 12

GenerateMethod · 0.95
ExecuteMethod · 0.95
generateFakeRepoUrlFunction · 0.85
GetRepoIdMapMethod · 0.80
CreateRawDataSubTaskArgsFunction · 0.70
GetDalMethod · 0.65
GetLoggerMethod · 0.65
CursorMethod · 0.65
FromMethod · 0.65
CloseMethod · 0.65
GetEndpointMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected