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

Add support for repository find in azure #164

Merged
merged 1 commit into from
Apr 4, 2022
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
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"
}