Skip to content
This repository was archived by the owner on Jun 1, 2022. It is now read-only.

Commit 97e7e24

Browse files
Merge pull request #77 from lighttiger2505/add-virtual-gitlab-domain-feature
virtual gitlab domain feature
2 parents bfa7d23 + d77d0d0 commit 97e7e24

File tree

2 files changed

+101
-3
lines changed

2 files changed

+101
-3
lines changed

internal/gitutil/gitutil.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (c *RemoteCollecter) collectTargetByLocalRepository(pInfo *GitLabProjectInf
119119
return nil, err
120120
}
121121

122-
gitlabRemotes := filterHasGitlabDomain(gitRemotes)
122+
gitlabRemotes := filterHasGitlabDomain(gitRemotes, c.Cfg)
123123
if len(gitlabRemotes) == 0 {
124124
return nil, fmt.Errorf("Not found gitlab remote repository")
125125
}
@@ -190,11 +190,13 @@ func (c *RemoteCollecter) collectTargetByArgs(pInfo *GitLabProjectInfo, project,
190190
return pInfo, nil
191191
}
192192

193-
func filterHasGitlabDomain(remoteInfos []*git.RemoteInfo) []*git.RemoteInfo {
194-
var gitlabRemotes []*git.RemoteInfo
193+
func filterHasGitlabDomain(remoteInfos []*git.RemoteInfo, cfg *config.Config) []*git.RemoteInfo {
194+
gitlabRemotes := []*git.RemoteInfo{}
195195
for _, remoteInfo := range remoteInfos {
196196
if strings.HasPrefix(remoteInfo.Domain, "gitlab") {
197197
gitlabRemotes = append(gitlabRemotes, remoteInfo)
198+
} else if cfg.HasDomain(remoteInfo.Domain) {
199+
gitlabRemotes = append(gitlabRemotes, remoteInfo)
198200
}
199201
}
200202
return gitlabRemotes

internal/gitutil/gitutil_test.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package gitutil
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
7+
"github.com/lighttiger2505/lab/git"
8+
"github.com/lighttiger2505/lab/internal/config"
9+
)
10+
11+
func Test_filterHasGitlabDomain(t *testing.T) {
12+
13+
gitlabRemoteInfo := &git.RemoteInfo{
14+
15+
Domain: "gitlab.com",
16+
}
17+
githubRemoteInfo := &git.RemoteInfo{
18+
19+
Domain: "github.com",
20+
}
21+
type args struct {
22+
remoteInfos []*git.RemoteInfo
23+
cfg *config.Config
24+
}
25+
tests := []struct {
26+
name string
27+
args args
28+
want []*git.RemoteInfo
29+
}{
30+
{
31+
name: "find the gitlab domain",
32+
args: args{
33+
remoteInfos: []*git.RemoteInfo{
34+
gitlabRemoteInfo,
35+
githubRemoteInfo,
36+
},
37+
cfg: &config.Config{
38+
Profiles: map[string]config.Profile{},
39+
},
40+
},
41+
want: []*git.RemoteInfo{gitlabRemoteInfo},
42+
},
43+
{
44+
name: "find the gitlab domain specified in the config file",
45+
args: args{
46+
remoteInfos: []*git.RemoteInfo{
47+
gitlabRemoteInfo,
48+
githubRemoteInfo,
49+
},
50+
cfg: &config.Config{
51+
Profiles: map[string]config.Profile{
52+
"gitlab.com": {},
53+
},
54+
},
55+
},
56+
want: []*git.RemoteInfo{gitlabRemoteInfo},
57+
},
58+
{
59+
name: "find the other domain specified in the config file",
60+
args: args{
61+
remoteInfos: []*git.RemoteInfo{
62+
gitlabRemoteInfo,
63+
githubRemoteInfo,
64+
},
65+
cfg: &config.Config{
66+
Profiles: map[string]config.Profile{
67+
"gitlab.com": {},
68+
"github.com": {},
69+
},
70+
},
71+
},
72+
want: []*git.RemoteInfo{gitlabRemoteInfo, githubRemoteInfo},
73+
},
74+
{
75+
name: "not found",
76+
args: args{
77+
remoteInfos: []*git.RemoteInfo{
78+
githubRemoteInfo,
79+
},
80+
cfg: &config.Config{
81+
Profiles: map[string]config.Profile{
82+
"gitlab.com": {},
83+
},
84+
},
85+
},
86+
want: []*git.RemoteInfo{},
87+
},
88+
}
89+
for _, tt := range tests {
90+
t.Run(tt.name, func(t *testing.T) {
91+
if got := filterHasGitlabDomain(tt.args.remoteInfos, tt.args.cfg); !reflect.DeepEqual(got, tt.want) {
92+
t.Errorf("filterHasGitlabDomain() = %v, want %v", got, tt.want)
93+
}
94+
})
95+
}
96+
}

0 commit comments

Comments
 (0)