Skip to content

Commit

Permalink
feat: [CODE-1907]: Fix go-scm azure driver for getting namespace in t…
Browse files Browse the repository at this point in the history
…he response (#307)
  • Loading branch information
karansaraswat19 authored May 15, 2024
1 parent 9e8b4ca commit 9b7f437
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
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

0 comments on commit 9b7f437

Please sign in to comment.