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

Method PrepareTaskData

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

Source from the content-addressed store, hash-verified

169}
170
171func (p Zentao) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) {
172 op, err := tasks.DecodeAndValidateTaskOptions(options)
173 if err != nil {
174 return nil, errors.Default.Wrap(err, "could not decode Zentao options")
175 }
176 connectionHelper := helper.NewConnectionHelper(
177 taskCtx,
178 nil,
179 p.Name(),
180 )
181 connection := &models.ZentaoConnection{}
182 err = connectionHelper.FirstById(connection, op.ConnectionId)
183 if err != nil {
184 return nil, errors.Default.Wrap(err, "unable to get Zentao connection by the given connection ID: %v")
185 }
186
187 apiClient, err := tasks.NewZentaoApiClient(taskCtx, connection)
188 if err != nil {
189 return nil, errors.Default.Wrap(err, "unable to get Zentao API client instance: %v")
190 }
191
192 if op.ScopeConfig == nil && op.ScopeConfigId != 0 {
193 err = taskCtx.GetDal().First(&op.ScopeConfig, dal.Where("id = ?", op.ScopeConfigId))
194 if err != nil && taskCtx.GetDal().IsErrorNotFound(err) {
195 return nil, errors.BadInput.Wrap(err, "fail to load scope config from database")
196 }
197 }
198
199 data := &tasks.ZentaoTaskData{
200 Options: op,
201 ApiClient: apiClient,
202 Stories: map[int64]struct{}{},
203 Tasks: map[int64]struct{}{},
204 Bugs: map[int64]struct{}{},
205 AccountCache: tasks.NewAccountCache(taskCtx.GetDal(), op.ConnectionId),
206 }
207
208 if connection.DbUrl != "" {
209 if connection.DbLoggingLevel == "" {
210 connection.DbLoggingLevel = taskCtx.GetConfig("DB_LOGGING_LEVEL")
211 }
212
213 if connection.DbIdleConns == 0 {
214 connection.DbIdleConns = taskCtx.GetConfigReader().GetInt("DB_IDLE_CONNS")
215 }
216
217 if connection.DbMaxConns == 0 {
218 connection.DbMaxConns = taskCtx.GetConfigReader().GetInt("DB_MAX_CONNS")
219 }
220
221 v := viper.New()
222 v.Set("DB_URL", connection.DbUrl)
223 v.Set("DB_LOGGING_LEVEL", connection.DbLoggingLevel)
224 v.Set("DB_IDLE_CONNS", connection.DbIdleConns)
225 v.Set("DbMaxConns", connection.DbMaxConns)
226
227 rgorm, err := runner.NewGormDb(v, taskCtx.GetLogger())
228 if err != nil {

Callers

nothing calls this directly

Calls 11

NameMethod · 0.95
WrapMethod · 0.80
FirstByIdMethod · 0.80
GetIntMethod · 0.80
FirstMethod · 0.65
GetDalMethod · 0.65
IsErrorNotFoundMethod · 0.65
GetConfigMethod · 0.65
GetConfigReaderMethod · 0.65
NewMethod · 0.65
GetLoggerMethod · 0.65

Tested by

no test coverage detected