MCPcopy Create free account
hub / github.com/apache/devlake / PrepareTaskData

Method PrepareTaskData

backend/plugins/sonarqube/impl/impl.go:114–157  ·  view source on GitHub ↗
(taskCtx plugin.TaskContext, options map[string]interface{})

Source from the content-addressed store, hash-verified

112}
113
114func (p Sonarqube) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) {
115 logger := taskCtx.GetLogger()
116 op, err := tasks.DecodeAndValidateTaskOptions(options)
117 if err != nil {
118 return nil, err
119 }
120 connectionHelper := helper.NewConnectionHelper(
121 taskCtx,
122 nil,
123 p.Name(),
124 )
125 connection := &models.SonarqubeConnection{}
126 err = connectionHelper.FirstById(connection, op.ConnectionId)
127 if err != nil {
128 return nil, errors.Default.Wrap(err, "unable to get Sonarqube connection by the given connection ID")
129 }
130
131 apiClient, err := tasks.CreateApiClient(taskCtx, connection)
132 if err != nil {
133 return nil, errors.Default.Wrap(err, "unable to get Sonarqube API client instance")
134 }
135 taskData := &tasks.SonarqubeTaskData{
136 Options: op,
137 ApiClient: apiClient,
138 TaskStartTime: time.Now(),
139 IsCloud: connection.IsCloud(),
140 }
141 // even we have project in _tool_sonaqube_projects, we still need to collect project to update LastAnalysisDate
142 var apiProject *models.SonarqubeApiProject
143 apiProject, err = api.GetApiProject(op.ProjectKey, apiClient)
144 if err != nil {
145 return nil, err
146 }
147 logger.Debug(fmt.Sprintf("Current project: %s", apiProject.ProjectKey))
148 scope := apiProject.ConvertApiScope()
149 scope.ConnectionId = op.ConnectionId
150 err = taskCtx.GetDal().CreateOrUpdate(&scope)
151 if err != nil {
152 return nil, err
153 }
154 taskData.LastAnalysisDate = scope.LastAnalysisDate.ToNullableTime()
155
156 return taskData, nil
157}
158
159// RootPkgPath information lost when compiled as plugin(.so)
160func (p Sonarqube) RootPkgPath() string {

Callers

nothing calls this directly

Calls 10

NameMethod · 0.95
IsCloudMethod · 0.95
ConvertApiScopeMethod · 0.95
FirstByIdMethod · 0.80
WrapMethod · 0.80
GetLoggerMethod · 0.65
DebugMethod · 0.65
CreateOrUpdateMethod · 0.65
GetDalMethod · 0.65
ToNullableTimeMethod · 0.45

Tested by

no test coverage detected