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

Implement Delete Ref Endpoint in Git Service for Bitbucket Server (stash) #473

Merged
merged 1 commit into from
Dec 28, 2024
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
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