Skip to content

Commit

Permalink
Implement delete ref endpoint in git service
Browse files Browse the repository at this point in the history
implemented delete ref endpoint in git service for Bitbucket server.

Signed-off-by: Zaki Shaikh <[email protected]>
  • Loading branch information
zakisk committed Dec 28, 2024
1 parent 1269559 commit 4096de8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
11 changes: 10 additions & 1 deletion scm/driver/stash/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ func (s *gitService) CreateRef(ctx context.Context, repo, ref, sha string) (*scm
}

func (s *gitService) DeleteRef(ctx context.Context, repo, ref string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
namespace, name := scm.Split(repo)
path := fmt.Sprintf("rest/branch-utils/latest/projects/%s/repos/%s/branches", namespace, name)
in := deleteRefInput{Name: ref}
return s.client.do(ctx, "DELETE", path, &in, nil)
}

func (s *gitService) FindBranch(ctx context.Context, repo, branch string) (*scm.Reference, *scm.Response, error) {
Expand Down Expand Up @@ -150,6 +153,12 @@ func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string
return convertDiffstats(out), res, err
}

type deleteRefInput struct {
DryRun bool `json:"dryRun,omitempty"`
EndPoint string `json:"endPoint,omitempty"`
Name string `json:"name,omitempty"`
}

type branch struct {
ID string `json:"id"`
DisplayID string `json:"displayId"`
Expand Down
19 changes: 19 additions & 0 deletions scm/driver/stash/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ func TestGitCreateRef(t *testing.T) {
}
}

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

gock.New("http://example.com:7990").
Delete("rest/branch-utils/latest/projects/PRJ/repos/my-repo/branches").
Reply(204).
Type("application/json")

client, _ := New("http://example.com:7990")
resp, err := client.Git.DeleteRef(context.Background(), "PRJ/my-repo", "delete")
if err != nil {
t.Error(err)
}

if resp.Status != 204 {
t.Errorf("DeleteRef returned %v", resp.Status)
}
}

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

Expand Down

0 comments on commit 4096de8

Please sign in to comment.