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 <zashaikh@redhat.com>
  • Loading branch information
zakisk committed Dec 26, 2024
1 parent f6bded3 commit 186a80f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scm/driver/stash/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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 @@ -142,6 +145,11 @@ func (s *gitService) CompareCommits(ctx context.Context, repo, ref1, ref2 string
return convertDiffstats(out), res, err
}

type deleteRefInput struct {
DryRun bool `json:"dryRun"`
Name string `json:"name"`
}

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 @@ -44,6 +44,25 @@ func TestGitFindCommit(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 186a80f

Please sign in to comment.