[PL-24911]: Make project name as optional param in Azure Repo APIs (#173)

* [fix]: [PL-24880]: Trim the ref when fetching default branch
* [PL-24911]: Make the project id as optional param
pull/176/head^2
Deepak Patankar 2 years ago committed by GitHub
parent 985a17351f
commit 30f8094b0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,8 +25,8 @@ func New(uri, owner, project string) (*scm.Client, error) {
if !strings.HasSuffix(base.Path, "/") {
base.Path = base.Path + "/"
}
if owner == "" || project == "" {
return nil, fmt.Errorf("azure owner and azure project are required")
if owner == "" {
return nil, fmt.Errorf("azure owner is required")
}
client := &wrapper{
new(scm.Client),

@ -28,8 +28,8 @@ func TestClient_Default(t *testing.T) {
func TestClient_azure_special(t *testing.T) {
client, _ := New("https://dev.azure.com", "org", "")
if client != nil {
t.Errorf("Want nil client, got %v", client)
if got, want := client.BaseURL.String(), "https://dev.azure.com/"; got != want {
t.Errorf("Want Client URL %q, got %q", want, got)
}
client2, _ := New("https://dev.azure.com", "", "proj")
if client2 != nil {

@ -40,7 +40,12 @@ func (s *RepositoryService) FindPerms(ctx context.Context, repo string) (*scm.Pe
// List returns the user repository list.
func (s *RepositoryService) List(ctx context.Context, opts scm.ListOptions) ([]*scm.Repository, *scm.Response, error) {
// https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-6.0
endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories?api-version=6.0", s.client.owner, s.client.project)
var endpoint string
if s.client.project == "" {
endpoint = fmt.Sprintf("%s/_apis/git/repositories?api-version=6.0", s.client.owner)
} else {
endpoint = fmt.Sprintf("%s/%s/_apis/git/repositories?api-version=6.0", s.client.owner, s.client.project)
}
out := new(repositories)
res, err := s.client.do(ctx, "GET", endpoint, nil, &out)

Loading…
Cancel
Save