Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [CODE-1907]: Fix go-scm azure driver for getting namespace in t… #307

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions scm/driver/azure/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"fmt"
"net/url"
"strings"

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

out := new(repository)
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
return convertRepository(out), res, err
return convertRepository(out, s.client.owner), res, err
}

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

out := new(repositories)
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)
return convertRepositoryList(out), res, err
return convertRepositoryList(out, s.client.owner), res, err
}

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

// helper function to convert from the gogs repository list to
// helper function to convert from the azure devops repository list to
// the common repository structure.
func convertRepositoryList(from *repositories) []*scm.Repository {
func convertRepositoryList(from *repositories, owner string) []*scm.Repository {
to := []*scm.Repository{}
for _, v := range from.Value {
to = append(to, convertRepository(v))
to = append(to, convertRepository(v, owner))
}
return to
}

// helper function to convert from the gogs repository structure
// helper function to convert from the azure devops repository structure
// to the common repository structure.
func convertRepository(from *repository) *scm.Repository {
func convertRepository(from *repository, owner string) *scm.Repository {
namespace := []string{owner, from.Project.Name}
return &scm.Repository{
ID: from.ID,
Name: from.Name,
Link: from.URL,
Branch: scm.TrimRef(from.DefaultBranch),
Clone: from.RemoteURL,
ID: from.ID,
Name: from.Name,
Namespace: strings.Join(namespace, "/"),
Link: from.URL,
Branch: scm.TrimRef(from.DefaultBranch),
Clone: from.RemoteURL,
}
}

Expand Down
1 change: 1 addition & 0 deletions scm/driver/azure/testdata/repo.json.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"ID": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"Name": "test_project",
"Namespace": "ORG/test_project",
"Branch": "main",
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"Clone": "https://[email protected]/tphoney/test_project/_git/test_project"
Expand Down
2 changes: 2 additions & 0 deletions scm/driver/azure/testdata/repos.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
{
"ID": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"Name": "test_project",
"Namespace": "ORG/test_project",
"Branch": "main",
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"Clone": "https://[email protected]/tphoney/test_project/_git/test_project"
},
{
"ID": "fde2d21f-13b9-4864-a995-83329045289a",
"Name": "test_repo2",
"Namespace": "ORG/test_project",
"Branch": "main",
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/fde2d21f-13b9-4864-a995-83329045289a",
"Clone": "https://[email protected]/tphoney/test_project/_git/test_repo2"
Expand Down