narrowizard commented on code in PR #8401: URL: https://github.com/apache/incubator-devlake/pull/8401#discussion_r2057183599
########## backend/plugins/customize/service/service.go: ########## @@ -262,22 +263,53 @@ func (s *Service) importCSV(file io.ReadCloser, rawDataParams string, recordHand } } +// createOrUpdateAccount creates or updates an account based on the provided name. +// It returns the account ID and an error if any occurred. +func (s *Service) createOrUpdateAccount(accountName string, rawDataParams string) (string, errors.Error) { + if accountName == "" { + return "", nil // Return empty ID if name is empty, no error needed here. + } + now := time.Now() + accountId := fmt.Sprintf("csv:CsvAccount:0:%s", accountName) + account := &crossdomain.Account{ + DomainEntity: domainlayer.DomainEntity{ + Id: accountId, + NoPKModel: common.NoPKModel{ + RawDataOrigin: common.RawDataOrigin{ + RawDataParams: rawDataParams, + }, + }, + }, + FullName: accountName, + UserName: accountName, + CreatedDate: &now, + } + err := s.dal.CreateOrUpdate(account) + if err != nil { + return "", errors.Default.Wrap(err, fmt.Sprintf("failed to create or update account for %s", accountName)) + } + return accountId, nil +} + // issueHandlerFactory returns a handler that save record into `issues`, `board_issues` and `issue_labels` table func (s *Service) issueHandlerFactory(boardId string, incremental bool) func(record map[string]interface{}) errors.Error { return func(record map[string]interface{}) errors.Error { var err errors.Error var id string - if record["id"] == nil { + idValue, ok := record["id"] Review Comment: Fixed. has extracted to `getStringField` function and added test case to it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@devlake.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org