diff --git a/scm/driver/stash/git.go b/scm/driver/stash/git.go index 38d8f54f..c311be90 100644 --- a/scm/driver/stash/git.go +++ b/scm/driver/stash/git.go @@ -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) { @@ -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"` diff --git a/scm/driver/stash/git_test.go b/scm/driver/stash/git_test.go index 280b4390..32a3e978 100644 --- a/scm/driver/stash/git_test.go +++ b/scm/driver/stash/git_test.go @@ -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()