-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalRepositoryFinderImpl.go
76 lines (60 loc) · 1.56 KB
/
LocalRepositoryFinderImpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package implservice
import (
"context"
"fmt"
"github.com/bitwormhole/gitlib/git/store"
"github.com/bitwormhole/starter/markup"
"github.com/bitwormhole/wpm/server/service"
"github.com/bitwormhole/wpm/server/web/dto"
)
// LocalRepositoryFinderImpl ...
type LocalRepositoryFinderImpl struct {
markup.Component `id:"LocalRepositoryFinder"`
GitLibAgent store.LibAgent `inject:"#git-lib-agent"`
}
func (inst *LocalRepositoryFinderImpl) _Impl() service.LocalRepositoryFinder {
return inst
}
// Search ...
func (inst *LocalRepositoryFinderImpl) Search(ctx context.Context, path string, depthLimit int) ([]*dto.LocalRepository, error) {
lib, err := inst.GitLibAgent.GetLib()
if err != nil {
return nil, err
}
pwd := lib.FS().NewPath(path)
src, err := lib.RepositoryFinder().Find(pwd)
if err != nil {
return nil, err
}
dst := make([]*dto.LocalRepository, 0)
for _, it1 := range src {
it2 := &dto.LocalRepository{
Path: it1.GetPath(),
}
dst = append(dst, it2)
}
return dst, nil
}
// Locate ...
func (inst *LocalRepositoryFinderImpl) Locate(ctx context.Context, path string) (*dto.LocalRepository, error) {
lib, err := inst.GitLibAgent.GetLib()
if err != nil {
return nil, err
}
pwd := lib.FS().NewPath(path)
layout, err := lib.RepositoryLocator().Locate(pwd)
if err != nil {
return nil, err
}
targetPath := layout.DotGit()
if targetPath == nil {
targetPath = layout.Repository()
}
if targetPath == nil {
return nil, fmt.Errorf("repo path not found")
}
result := &dto.LocalRepository{
Path: targetPath.GetPath(),
}
return result, nil
}