mirror of https://github.com/harness/drone.git
feat: [CODE-3309]: move shared repo root dir to the same parent dir as the repos (#3517)
* removed the not-exist error check for MkdirAll * move shared repo root dir to the same parent dir as the repostry-new-ui
parent
b347c0f347
commit
164fa4153d
|
@ -264,7 +264,7 @@ func (s *Service) Merge(ctx context.Context, params *MergeParams) (MergeOutput,
|
|||
var mergeCommitSHA sha.SHA
|
||||
var conflicts []string
|
||||
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.tmpDir, repoPath, func(s *sharedrepo.SharedRepo) error {
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.sharedRepoRoot, repoPath, func(s *sharedrepo.SharedRepo) error {
|
||||
mergeCommitSHA, conflicts, err = mergeFunc(
|
||||
ctx,
|
||||
s,
|
||||
|
|
|
@ -151,7 +151,7 @@ func (s *Service) CommitFiles(ctx context.Context, params *CommitFilesParams) (C
|
|||
|
||||
// run the actions in a shared repo
|
||||
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.tmpDir, repoPath, func(r *sharedrepo.SharedRepo) error {
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.sharedRepoRoot, repoPath, func(r *sharedrepo.SharedRepo) error {
|
||||
var parentCommits []sha.SHA
|
||||
var oldTreeSHA sha.SHA
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ func (s *Service) ScanSecrets(ctx context.Context, params *ScanSecretsParams) (*
|
|||
repoPath := getFullPathForRepo(s.reposRoot, params.RepoUID)
|
||||
|
||||
var findings []ScanSecretsFinding
|
||||
err := sharedrepo.Run(ctx, nil, s.tmpDir, repoPath, func(sharedRepo *sharedrepo.SharedRepo) error {
|
||||
err := sharedrepo.Run(ctx, nil, s.sharedRepoRoot, repoPath, func(sharedRepo *sharedrepo.SharedRepo) error {
|
||||
fsGitleaksIgnorePath, err := s.setupGitleaksIgnoreInSharedRepo(
|
||||
ctx,
|
||||
sharedRepo,
|
||||
|
|
|
@ -15,11 +15,10 @@
|
|||
package git
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git/api"
|
||||
"github.com/harness/gitness/git/hook"
|
||||
"github.com/harness/gitness/git/storage"
|
||||
|
@ -28,12 +27,13 @@ import (
|
|||
|
||||
const (
|
||||
repoSubdirName = "repos"
|
||||
repoSharedRepoSubdirName = "shared_temp"
|
||||
ReposGraveyardSubdirName = "cleanup"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
reposRoot string
|
||||
tmpDir string
|
||||
sharedRepoRoot string
|
||||
git *api.Git
|
||||
hookClientFactory hook.ClientFactory
|
||||
store storage.Store
|
||||
|
@ -48,24 +48,26 @@ func New(
|
|||
storage storage.Store,
|
||||
) (*Service, error) {
|
||||
// Create repos folder
|
||||
reposRoot := filepath.Join(config.Root, repoSubdirName)
|
||||
if _, err := os.Stat(reposRoot); errors.Is(err, os.ErrNotExist) {
|
||||
if err = os.MkdirAll(reposRoot, fileMode700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reposRoot, err := createSubdir(config.Root, repoSubdirName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// create a temp dir for deleted repositories
|
||||
// this dir should get cleaned up peridocally if it's not empty
|
||||
reposGraveyard := filepath.Join(config.Root, ReposGraveyardSubdirName)
|
||||
if _, errdir := os.Stat(reposGraveyard); errors.Is(errdir, fs.ErrNotExist) {
|
||||
if errdir = os.MkdirAll(reposGraveyard, fileMode700); errdir != nil {
|
||||
return nil, errdir
|
||||
}
|
||||
reposGraveyard, err := createSubdir(config.Root, ReposGraveyardSubdirName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sharedRepoDir, err := createSubdir(config.Root, repoSharedRepoSubdirName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Service{
|
||||
reposRoot: reposRoot,
|
||||
tmpDir: config.TmpDir,
|
||||
sharedRepoRoot: sharedRepoDir,
|
||||
reposGraveyard: reposGraveyard,
|
||||
git: adapter,
|
||||
hookClientFactory: hookClientFactory,
|
||||
|
@ -73,3 +75,14 @@ func New(
|
|||
gitHookPath: config.HookPath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func createSubdir(root, subdir string) (string, error) {
|
||||
subdirPath := filepath.Join(root, subdir)
|
||||
|
||||
err := os.MkdirAll(subdirPath, fileMode700)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create directory, path=%s: %w", subdirPath, err)
|
||||
}
|
||||
|
||||
return subdirPath, nil
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ func (s *Service) CreateCommitTag(ctx context.Context, params *CreateCommitTagPa
|
|||
|
||||
// create the tag
|
||||
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.tmpDir, repoPath, func(r *sharedrepo.SharedRepo) error {
|
||||
err = sharedrepo.Run(ctx, refUpdater, s.sharedRepoRoot, repoPath, func(r *sharedrepo.SharedRepo) error {
|
||||
if err := s.git.CreateTag(ctx, r.Directory(), tagName, targetCommit.SHA, createTagRequest); err != nil {
|
||||
return fmt.Errorf("failed to create tag '%s': %w", tagName, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue