mirror of
https://github.com/harness/drone.git
synced 2025-05-21 11:29:52 +08:00
repo new uid can be passed as param field (#827)
This commit is contained in:
parent
1d06026d05
commit
f2dd88d2e3
20
git/repo.go
20
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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user