From f2dd88d2e316e77169124a95c3f67f746918e5eb Mon Sep 17 00:00:00 2001 From: Enver Bisevac Date: Tue, 28 Nov 2023 13:08:01 +0000 Subject: [PATCH] repo new uid can be passed as param field (#827) --- git/repo.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/git/repo.go b/git/repo.go index d02f2e17d..a8247bdc9 100644 --- a/git/repo.go +++ b/git/repo.go @@ -62,6 +62,7 @@ var ( type CreateRepositoryParams struct { // Create operation is different from all (from user side), as UID doesn't exist yet. // Only take actor and envars as input and create WriteParams manually + RepoUID string Actor Identity EnvVars map[string]string @@ -132,15 +133,18 @@ func (s *Service) CreateRepository( log := log.Ctx(ctx) - uid, err := newRepositoryUID() - if err != nil { - return nil, fmt.Errorf("failed to create new uid: %w", err) + if params.RepoUID == "" { + uid, err := NewRepositoryUID() + if err != nil { + return nil, fmt.Errorf("failed to create new uid: %w", err) + } + params.RepoUID = uid } log.Info(). - Msgf("Create new git repository with uid '%s' and default branch '%s'", uid, params.DefaultBranch) + Msgf("Create new git repository with uid '%s' and default branch '%s'", params.RepoUID, params.DefaultBranch) writeParams := WriteParams{ - RepoUID: uid, + RepoUID: params.RepoUID, Actor: params.Actor, EnvVars: params.EnvVars, } @@ -163,7 +167,7 @@ func (s *Service) CreateRepository( authorDate = *params.AuthorDate } - err = s.createRepositoryInternal( + err := s.createRepositoryInternal( ctx, &writeParams, params.DefaultBranch, @@ -178,11 +182,11 @@ func (s *Service) CreateRepository( } return &CreateRepositoryOutput{ - UID: uid, + UID: params.RepoUID, }, nil } -func newRepositoryUID() (string, error) { +func NewRepositoryUID() (string, error) { return gonanoid.Generate(repoGitUIDAlphabet, repoGitUIDLength) }