Skip to content

Commit 7d81093

Browse files
committed
fix ns issue
1 parent 11a7ced commit 7d81093

File tree

4 files changed

+79
-2
lines changed

4 files changed

+79
-2
lines changed

scm/driver/gitlab/repo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ type repository struct {
3030
}
3131

3232
type namespace struct {
33-
Name string `json:"name"`
34-
Path string `json:"path"`
33+
Name string `json:"name"`
34+
Path string `json:"path"`
35+
FullPath string `json:"full_path"`
3536
}
3637

3738
type permissions struct {
@@ -184,6 +185,9 @@ func convertRepository(from *repository) *scm.Repository {
184185
Admin: canAdmin(from),
185186
},
186187
}
188+
if path := from.Namespace.FullPath; path != "" {
189+
to.Namespace = path
190+
}
187191
if to.Namespace == "" {
188192
if parts := strings.SplitN(from.PathNamespace, "/", 2); len(parts) == 2 {
189193
to.Namespace = parts[1]

scm/driver/gitlab/repo_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ func TestRepositoryFind(t *testing.T) {
4949
t.Run("Rate", testRate(res))
5050
}
5151

52+
func TestSubgroupFind(t *testing.T) {
53+
defer gock.Off()
54+
55+
gock.New("https://gitlab.com").
56+
Get("/api/v4/projects/gitlab-org/gitter/gitter-demo-app").
57+
Reply(200).
58+
Type("application/json").
59+
SetHeaders(mockHeaders).
60+
File("testdata/subgroup.json")
61+
62+
client := NewDefault()
63+
got, _, err := client.Repositories.Find(context.Background(), "gitlab-org/gitter/gitter-demo-app")
64+
if err != nil {
65+
t.Error(err)
66+
return
67+
}
68+
69+
want := new(scm.Repository)
70+
raw, _ := ioutil.ReadFile("testdata/subgroup.json.golden")
71+
json.Unmarshal(raw, want)
72+
73+
if diff := cmp.Diff(got, want); diff != "" {
74+
t.Errorf("Cannot parse subgroup")
75+
t.Log(diff)
76+
}
77+
}
78+
5279
func TestRepositoryPerms(t *testing.T) {
5380
defer gock.Off()
5481

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"id": 14264161,
3+
"description": "Gitter Demo App",
4+
"name": "gitter-demo-app",
5+
"name_with_namespace": "GitLab.org / gitter / gitter-demo-app",
6+
"path": "gitter-demo-app",
7+
"path_with_namespace": "gitlab-org/gitter/gitter-demo-app",
8+
"created_at": "2019-09-11T23:30:02.188Z",
9+
"default_branch": "master",
10+
"tag_list": [],
11+
"ssh_url_to_repo": "[email protected]:gitlab-org/gitter/gitter-demo-app.git",
12+
"http_url_to_repo": "https://gitlab.com/gitlab-org/gitter/gitter-demo-app.git",
13+
"web_url": "https://gitlab.com/gitlab-org/gitter/gitter-demo-app",
14+
"readme_url": "https://gitlab.com/gitlab-org/gitter/gitter-demo-app/blob/master/README.md",
15+
"avatar_url": null,
16+
"star_count": 0,
17+
"forks_count": 1,
18+
"last_activity_at": "2020-01-09T10:11:44.250Z",
19+
"namespace": {
20+
"id": 1540914,
21+
"name": "gitter",
22+
"path": "gitter",
23+
"kind": "group",
24+
"full_path": "gitlab-org/gitter",
25+
"parent_id": 9970,
26+
"avatar_url": "/uploads/-/system/group/avatar/1540914/icon_128x128.png",
27+
"web_url": "https://gitlab.com/groups/gitlab-org/gitter"
28+
}
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"ID": "14264161",
3+
"Namespace": "gitlab-org/gitter",
4+
"Name": "gitter-demo-app",
5+
"Perm": {
6+
"Pull": true,
7+
"Push": false,
8+
"Admin": false
9+
},
10+
"Branch": "master",
11+
"Private": false,
12+
"Clone": "https://gitlab.com/gitlab-org/gitter/gitter-demo-app.git",
13+
"CloneSSH": "[email protected]:gitlab-org/gitter/gitter-demo-app.git",
14+
"Link": "",
15+
"Created": "0001-01-01T00:00:00Z",
16+
"Updated": "0001-01-01T00:00:00Z"
17+
}

0 commit comments

Comments
 (0)