MCPcopy
hub / github.com/apache/devlake / importCSV

Method importCSV

backend/plugins/customize/service/service.go:237–265  ·  view source on GitHub ↗

importCSV extract records from csv file, and save them to DB using recordHandler the rawDataParams is used to identify the data source, the recordHandler is used to handle the record, it should return an error if the record is invalid the `created_at` and `updated_at` will be set to the current time

(file io.ReadCloser, rawDataParams string, recordHandler func(map[string]interface{}) errors.Error)

Source from the content-addressed store, hash-verified

235// the recordHandler is used to handle the record, it should return an error if the record is invalid
236// the `created_at` and `updated_at` will be set to the current time
237func (s *Service) importCSV(file io.ReadCloser, rawDataParams string, recordHandler func(map[string]interface{}) errors.Error) errors.Error {
238 iterator, err := pluginhelper.NewCsvFileIteratorFromFile(file)
239 if err != nil {
240 return err
241 }
242 var hasNext bool
243 var line int
244 now := time.Now()
245 for {
246 line++
247 if hasNext, err = iterator.HasNextWithError(); !hasNext {
248 return errors.BadInput.Wrap(err, fmt.Sprintf("error on processing the line:%d", line))
249 } else {
250 record := iterator.Fetch()
251 record["_raw_data_params"] = rawDataParams
252 for k, v := range record {
253 if v.(string) == "NULL" {
254 record[k] = nil
255 }
256 }
257 record["created_at"] = now
258 record["updated_at"] = now
259 err = recordHandler(record)
260 if err != nil {
261 return errors.BadInput.Wrap(err, fmt.Sprintf("error on processing the line:%d", line))
262 }
263 }
264 }
265}
266
267// createOrUpdateAccount creates or updates an account based on the provided name.
268// It returns the account ID and an error if any occurred.

Callers 9

ImportIssueMethod · 0.95
ImportIssueCommitMethod · 0.95
ImportIssueRepoCommitMethod · 0.95
ImportQaApisMethod · 0.95
ImportQaTestCasesMethod · 0.95
ImportSprintMethod · 0.95
ImportIssueChangelogMethod · 0.95
ImportIssueWorklogMethod · 0.95

Calls 3

HasNextWithErrorMethod · 0.80
WrapMethod · 0.80
FetchMethod · 0.65

Tested by

no test coverage detected