Skip to content

Commit 6998dcc

Browse files
Merge pull request drone#35 from jstrachan/stuff
fix: add a bitbucket cloud FindRef method
2 parents 6fc527f + 57391e9 commit 6998dcc

File tree

3 files changed

+1021
-1
lines changed

3 files changed

+1021
-1
lines changed

scm/driver/bitbucket/git.go

Lines changed: 32 additions & 1 deletion
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/jenkins-x/go-scm/scm"
@@ -17,7 +18,37 @@ type gitService struct {
1718
}
1819

1920
func (s *gitService) FindRef(ctx context.Context, repo, ref string) (string, *scm.Response, error) {
20-
panic("implement me")
21+
commit, res, err := s.FindCommit(ctx, repo, ref)
22+
if err != nil && res.Status != 404 {
23+
return "", res, err
24+
}
25+
if commit != nil {
26+
if commit.Sha != "" {
27+
return commit.Sha, res, nil
28+
}
29+
}
30+
idx := strings.LastIndex(ref, "/")
31+
if idx >= 0 {
32+
ref = ref[idx+1:]
33+
}
34+
return ref, nil, nil
35+
36+
/*
37+
path := fmt.Sprintf("2.0/repositories/%s/refs?%s", repo, encodeRefQueryOptions(ref))
38+
out := new(branches)
39+
res, err := s.client.do(ctx, "GET", path, nil, out)
40+
if debugDump {
41+
var buf bytes.Buffer
42+
res, err := s.client.do(ctx, "GET", path, nil, &buf)
43+
fmt.Printf("%s\n", buf.String())
44+
return "", res, err
45+
}
46+
branches := convertBranchList(out)
47+
if len(branches) == 0 {
48+
return "", res, err
49+
}
50+
return branches[0].Name, res, err
51+
*/
2152
}
2253

2354
func (s *gitService) DeleteRef(ctx context.Context, repo, ref string) (*scm.Response, error) {

0 commit comments

Comments
 (0)