Skip to content

Commit

Permalink
Merge pull request #320 from drone/bittagfix
Browse files Browse the repository at this point in the history
feat: [CI-13826]: add check for bitbucket tag slash
  • Loading branch information
smjt-h authored Aug 27, 2024
2 parents 0ad4451 + 48eec0e commit 44424ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scm/driver/bitbucket/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package bitbucket
import (
"context"
"fmt"
"strings"
"time"

"github.com/drone/go-scm/scm"
Expand Down Expand Up @@ -44,7 +45,12 @@ func (s *gitService) FindCommit(ctx context.Context, repo, ref string) (*scm.Com
ref = branch.Sha // replace ref with sha
}
}
path := fmt.Sprintf("2.0/repositories/%s/commit/%s", repo, ref)
var path string
if strings.Contains(ref, "/") {
path = fmt.Sprintf("2.0/repositories/%s/?at=%s", repo, ref)
} else {
path = fmt.Sprintf("2.0/repositories/%s/commit/%s", repo, ref)
}
out := new(commit)
res, err := s.client.do(ctx, "GET", path, nil, out)
return convertCommit(out), res, err
Expand Down
26 changes: 26 additions & 0 deletions scm/driver/bitbucket/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,32 @@ func TestGitFindCommit(t *testing.T) {
}
}

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

gock.New("https://api.bitbucket.org").
Get("/2.0/repositories/atlassian/stash-example-plugin").
MatchParam("at", "ab/cd").
Reply(200).
Type("application/json").
File("testdata/commit.json")

client, _ := New("https://api.bitbucket.org")
got, _, err := client.Git.FindCommit(context.Background(), "atlassian/stash-example-plugin", "ab/cd")
if err != nil {
t.Error(err)
}

want := new(scm.Commit)
raw, _ := ioutil.ReadFile("testdata/commit.json.golden")
json.Unmarshal(raw, &want)

if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Unexpected Results")
t.Log(diff)
}
}

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

Expand Down

0 comments on commit 44424ac

Please sign in to comment.