Skip to content

Commit

Permalink
Add support for repositry find in azure
Browse files Browse the repository at this point in the history
  • Loading branch information
goelsatyam2 committed Apr 4, 2022
1 parent e53d749 commit 4e58ae3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scm/driver/azure/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ type RepositoryService struct {

// Find returns the repository by name.
func (s *RepositoryService) Find(ctx context.Context, repo string) (*scm.Repository, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
// https://docs.microsoft.com/en-us/rest/api/azure/devops/git/repositories/get?view=azure-devops-rest-4.1
endpoint := fmt.Sprintf("%s/%s/_apis/git/repositories/%s?api-version=6.0", s.client.owner, s.client.project, repo)

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

// FindHook returns a repository hook.
Expand Down
30 changes: 30 additions & 0 deletions scm/driver/azure/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,33 @@ func TestRepositoryHookDelete(t *testing.T) {
}

}

func TestRepositoryFind(t *testing.T) {
defer gock.Off()

gock.New("https:/dev.azure.com/").
Get("/ORG/PROJ/_apis/git/repositories/test_project").
Reply(200).
Type("application/json").
File("testdata/repo.json")

client := NewDefault("ORG", "PROJ")
got, _, err := client.Repositories.Find(context.Background(), "test_project")
if err != nil {
t.Error(err)
return
}

want := new(scm.Repository)
raw, _ := ioutil.ReadFile("testdata/repo.json.golden")
jsonErr := json.Unmarshal(raw, &want)
if jsonErr != nil {
t.Error(jsonErr)
}

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}

}
20 changes: 20 additions & 0 deletions scm/driver/azure/testdata/repo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"id": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"name": "test_project",
"url": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"project": {
"id": "d350c9c0-7749-4ff8-a78f-f9c1f0e56729",
"name": "test_project",
"url": "https://dev.azure.com/tphoney/_apis/projects/d350c9c0-7749-4ff8-a78f-f9c1f0e56729",
"state": "wellFormed",
"revision": 11,
"visibility": "private",
"lastUpdateTime": "2022-02-24T15:31:27.89Z"
},
"defaultBranch": "refs/heads/main",
"size": 1232,
"remoteUrl": "https://tphoney@dev.azure.com/tphoney/test_project/_git/test_project",
"sshUrl": "git@ssh.dev.azure.com:v3/tphoney/test_project/test_project",
"webUrl": "https://dev.azure.com/tphoney/test_project/_git/test_project",
"isDisabled": false
}
6 changes: 6 additions & 0 deletions scm/driver/azure/testdata/repo.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ID": "91f0d4cb-4c36-49a5-b28d-2d72da089c4d",
"Name": "test_project",
"Branch": "refs/heads/main",
"Link": "https://dev.azure.com/tphoney/d350c9c0-7749-4ff8-a78f-f9c1f0e56729/_apis/git/repositories/91f0d4cb-4c36-49a5-b28d-2d72da089c4d"
}

0 comments on commit 4e58ae3

Please sign in to comment.