Skip to content

Commit

Permalink
fetch branch for bitbucket onprem
Browse files Browse the repository at this point in the history
  • Loading branch information
devkimittal committed Feb 8, 2023
1 parent ca3776c commit dd80adf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
14 changes: 13 additions & 1 deletion scm/driver/stash/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@ func (s *repositoryService) Find(ctx context.Context, repo string) (*scm.Reposit
path := fmt.Sprintf("rest/api/1.0/projects/%s/repos/%s", namespace, name)
out := new(repository)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertRepository(out), res, err
outputRepo := convertRepository(out)

branch := new(branch)
pathBranch := fmt.Sprintf("rest/api/1.0/projects/%s/repos/%s/branches/default", namespace, name)
_, errBranch := s.client.do(ctx, "GET", pathBranch, nil, branch)
if errBranch == nil {
outputRepo.Branch = branch.DisplayID
}
if err == nil {
err = errBranch
}

return outputRepo, res, err
}

// FindHook returns a repository hook.
Expand Down
30 changes: 30 additions & 0 deletions scm/driver/stash/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ func TestRepositoryFind(t *testing.T) {
Type("application/json").
File("testdata/repo.json")

gock.New("http://example.com:7990").
Get("/rest/api/1.0/projects/PRJ/repos/my-repo/branches/default").
Reply(200).
Type("application/json").
File("testdata/default_branch.json")

client, _ := New("http://example.com:7990")
got, _, err := client.Repositories.Find(context.Background(), "PRJ/my-repo")
if err != nil {
Expand Down Expand Up @@ -76,6 +82,12 @@ func TestRepositoryPerms(t *testing.T) {
Type("application/json").
File("testdata/webhooks.json")

gock.New("http://example.com:7990").
Get("/rest/api/1.0/projects/PRJ/repos/my-repo/branches/default").
Reply(200).
Type("application/json").
File("testdata/default_branch.json")

client, _ := New("http://example.com:7990")
got, _, err := client.Repositories.FindPerms(context.Background(), "PRJ/my-repo")
if err != nil {
Expand Down Expand Up @@ -117,6 +129,12 @@ func TestRepositoryPerms_ReadOnly(t *testing.T) {
Type("application/json").
File("testdata/repo.json")

gock.New("http://example.com:7990").
Get("/rest/api/1.0/projects/PRJ/repos/my-repo/branches/default").
Reply(200).
Type("application/json").
File("testdata/default_branch.json")

client, _ := New("http://example.com:7990")
got, _, err := client.Repositories.FindPerms(context.Background(), "PRJ/my-repo")
if err != nil {
Expand Down Expand Up @@ -162,6 +180,12 @@ func TestRepositoryPerms_Write(t *testing.T) {
Type("application/json").
File("testdata/repos.json")

gock.New("http://example.com:7990").
Get("/rest/api/1.0/projects/PRJ/repos/my-repo/branches/default").
Reply(200).
Type("application/json").
File("testdata/default_branch.json")

client, _ := New("http://example.com:7990")
got, _, err := client.Repositories.FindPerms(context.Background(), "PRJ/my-repo")
if err != nil {
Expand Down Expand Up @@ -207,6 +231,12 @@ func TestRepositoryPermsDifferentProjectName_Write(t *testing.T) {
Type("application/json").
File("testdata/repos.json")

gock.New("http://example.com:7990").
Get("/rest/api/1.0/projects/PRJ/repos/quux/branches/default").
Reply(200).
Type("application/json").
File("testdata/default_branch.json")

client, _ := New("http://example.com:7990")
got, _, err := client.Repositories.FindPerms(context.Background(), "PRJ/quux")
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions scm/driver/stash/testdata/content_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"stash.go",
"stash_test.go",
"testdata/branch.json",
"testdata/default_branch.json",
"testdata/branch.json.golden",
"testdata/branches.json",
"testdata/branches.json.golden",
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/stash/testdata/default_branch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "refs/heads/mohit/mohit-temp",
"displayId": "notmaster",
"type": "BRANCH",
"latestCommit": "c567b3f4a2980299e2a1148360f23ffb0f4c9764",
"latestChangeset": "c567b3f4a2980299e2a1148360f23ffb0f4c9764",
"isDefault": true
}
2 changes: 1 addition & 1 deletion scm/driver/stash/testdata/repo.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Namespace": "PRJ",
"Name": "my-repo",
"Perm": null,
"Branch": "master",
"Branch": "notmaster",
"Private": true,
"Clone": "http://example.com:7990/scm/prj/my-repo.git",
"CloneSSH": "ssh://[email protected]:7999/prj/my-repo.git",
Expand Down

0 comments on commit dd80adf

Please sign in to comment.