(ctx context.Context, m *types.Model, s types.SyncVersion, sc multisync.Client)
| 293 | |
| 294 | } |
| 295 | func (c *MultiSyncComponent) createLocalModel(ctx context.Context, m *types.Model, s types.SyncVersion, sc multisync.Client) error { |
| 296 | namespace, name, _ := strings.Cut(m.Path, "/") |
| 297 | //add prefix to avoid namespace conflict |
| 298 | namespace = common.AddPrefixBySourceID(s.SourceID, namespace) |
| 299 | |
| 300 | //use namespace as the user login name |
| 301 | userName := namespace |
| 302 | var user database.User |
| 303 | user, err := c.getUser(ctx, userName) |
| 304 | if err != nil { |
| 305 | if err != sql.ErrNoRows { |
| 306 | return fmt.Errorf("fail to get user, userName:%s, error: %w", userName, err) |
| 307 | } |
| 308 | } |
| 309 | //user not exists, create new one |
| 310 | if user.ID == 0 { |
| 311 | //create as user instead of org, no matter if the namespace is org or user |
| 312 | user, err = c.createUser(ctx, types.CreateUserRequest{ |
| 313 | Name: m.User.Nickname, |
| 314 | Username: userName, |
| 315 | Email: common.AddPrefixBySourceID(s.SourceID, m.User.Email), |
| 316 | }) |
| 317 | if err != nil { |
| 318 | return fmt.Errorf("fail to create user for namespace, namespace:%s, error: %w", namespace, err) |
| 319 | } |
| 320 | } |
| 321 | //create new database repo |
| 322 | dbRepo := database.Repository{ |
| 323 | UserID: user.ID, |
| 324 | //new path with prefixed namespace |
| 325 | Path: path.Join(namespace, name), |
| 326 | GitPath: fmt.Sprintf("%ss_%s/%s", types.ModelRepo, namespace, name), |
| 327 | Name: name, |
| 328 | Nickname: m.Nickname, |
| 329 | Description: m.Description, |
| 330 | Private: m.Private, |
| 331 | Readme: m.Readme, |
| 332 | // License: req.License, |
| 333 | // DefaultBranch: gitRepo.DefaultBranch, |
| 334 | RepositoryType: types.ModelRepo, |
| 335 | Source: types.OpenCSGSource, |
| 336 | SyncStatus: types.SyncStatusPending, |
| 337 | // HTTPCloneURL: gitRepo.HttpCloneURL, |
| 338 | // SSHCloneURL: gitRepo.SshCloneURL, |
| 339 | } |
| 340 | newDBRepo, err := c.repo.UpdateOrCreateRepo(ctx, dbRepo) |
| 341 | if err != nil { |
| 342 | return fmt.Errorf("fail to create database repo, error: %w", err) |
| 343 | } |
| 344 | |
| 345 | if len(m.Tags) > 0 { |
| 346 | var repoTags []database.RepositoryTag |
| 347 | for _, tag := range m.Tags { |
| 348 | dbTag := database.Tag{ |
| 349 | Name: tag.Name, |
| 350 | Category: tag.Category, |
| 351 | Group: tag.Group, |
| 352 | BuiltIn: tag.BuiltIn, |
no test coverage detected