Skip to content

Commit 9b7f437

Browse files
feat: [CODE-1907]: Fix go-scm azure driver for getting namespace in the response (#307)
1 parent 9e8b4ca commit 9b7f437

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

scm/driver/azure/repo.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"fmt"
1010
"net/url"
11+
"strings"
1112

1213
"github.com/drone/go-scm/scm"
1314
)
@@ -28,7 +29,7 @@ func (s *RepositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
2829

2930
out := new(repository)
3031
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
31-
return convertRepository(out), res, err
32+
return convertRepository(out, s.client.owner), res, err
3233
}
3334

3435
// FindHook returns a repository hook.
@@ -53,7 +54,7 @@ func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*
5354

5455
out := new(repositories)
5556
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
56-
return convertRepositoryList(out), res, err
57+
return convertRepositoryList(out, s.client.owner), res, err
5758
}
5859

5960
// ListV2 returns the user repository list.
@@ -261,25 +262,27 @@ type subscription struct {
261262
URL string `json:"url"`
262263
}
263264

264-
// helper function to convert from the gogs repository list to
265+
// helper function to convert from the azure devops repository list to
265266
// the common repository structure.
266-
func convertRepositoryList(from *repositories) []*scm.Repository {
267+
func convertRepositoryList(from *repositories, owner string) []*scm.Repository {
267268
to := []*scm.Repository{}
268269
for _, v := range from.Value {
269-
to = append(to, convertRepository(v))
270+
to = append(to, convertRepository(v, owner))
270271
}
271272
return to
272273
}
273274

274-
// helper function to convert from the gogs repository structure
275+
// helper function to convert from the azure devops repository structure
275276
// to the common repository structure.
276-
func convertRepository(from *repository) *scm.Repository {
277+
func convertRepository(from *repository, owner string) *scm.Repository {
278+
namespace := []string{owner, from.Project.Name}
277279
return &scm.Repository{
278-
ID: from.ID,
279-
Name: from.Name,
280-
Link: from.URL,
281-
Branch: scm.TrimRef(from.DefaultBranch),
282-
Clone: from.RemoteURL,
280+
ID: from.ID,
281+
Name: from.Name,
282+
Namespace: strings.Join(namespace, "/"),
283+
Link: from.URL,
284+
Branch: scm.TrimRef(from.DefaultBranch),
285+
Clone: from.RemoteURL,
283286
}
284287
}
285288

scm/driver/azure/testdata/repo.json.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"ID": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
33
"Name": "test_project",
4+
"Namespace": "ORG/test_project",
45
"Branch": "main",
56
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
67
"Clone": "https://[email protected]/tphoney/test_project/_git/test_project"

scm/driver/azure/testdata/repos.json.golden

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
{
33
"ID": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
44
"Name": "test_project",
5+
"Namespace": "ORG/test_project",
56
"Branch": "main",
67
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
78
"Clone": "https://[email protected]/tphoney/test_project/_git/test_project"
89
},
910
{
1011
"ID": "fde2d21f-13b9-4864-a995-83329045289a",
1112
"Name": "test_repo2",
13+
"Namespace": "ORG/test_project",
1214
"Branch": "main",
1315
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a",
1416
"Clone": "https://[email protected]/tphoney/test_project/_git/test_repo2"

0 commit comments

Comments
 (0)