Skip to content

Commit 44424ac

Browse files
authored
Merge pull request #320 from drone/bittagfix
feat: [CI-13826]: add check for bitbucket tag slash
2 parents 0ad4451 + 48eec0e commit 44424ac

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

scm/driver/bitbucket/git.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package bitbucket
77
import (
88
"context"
99
"fmt"
10+
"strings"
1011
"time"
1112

1213
"github.com/drone/go-scm/scm"
@@ -44,7 +45,12 @@ func (s *gitService) FindCommit(ctx context.Context, repo, ref string) (*scm.Com
4445
ref = branch.Sha // replace ref with sha
4546
}
4647
}
47-
path := fmt.Sprintf("2.0/repositories/%s/commit/%s", repo, ref)
48+
var path string
49+
if strings.Contains(ref, "/") {
50+
path = fmt.Sprintf("2.0/repositories/%s/?at=%s", repo, ref)
51+
} else {
52+
path = fmt.Sprintf("2.0/repositories/%s/commit/%s", repo, ref)
53+
}
4854
out := new(commit)
4955
res, err := s.client.do(ctx, "GET", path, nil, out)
5056
return convertCommit(out), res, err

scm/driver/bitbucket/git_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,32 @@ func TestGitFindCommit(t *testing.T) {
4141
}
4242
}
4343

44+
func TestGitFindCommitForTagSlash(t *testing.T) {
45+
defer gock.Off()
46+
47+
gock.New("https://api.bitbucket.org").
48+
Get("/2.0/repositories/atlassian/stash-example-plugin").
49+
MatchParam("at", "ab/cd").
50+
Reply(200).
51+
Type("application/json").
52+
File("testdata/commit.json")
53+
54+
client, _ := New("https://api.bitbucket.org")
55+
got, _, err := client.Git.FindCommit(context.Background(), "atlassian/stash-example-plugin", "ab/cd")
56+
if err != nil {
57+
t.Error(err)
58+
}
59+
60+
want := new(scm.Commit)
61+
raw, _ := ioutil.ReadFile("testdata/commit.json.golden")
62+
json.Unmarshal(raw, &want)
63+
64+
if diff := cmp.Diff(got, want); diff != "" {
65+
t.Errorf("Unexpected Results")
66+
t.Log(diff)
67+
}
68+
}
69+
4470
func TestGitFindCommitForBranch(t *testing.T) {
4571
defer gock.Off()
4672

0 commit comments

Comments
 (0)