@@ -7,6 +7,7 @@ package bitbucket
7
7
import (
8
8
"context"
9
9
"fmt"
10
+ "strings"
10
11
"time"
11
12
12
13
"github.com/jenkins-x/go-scm/scm"
@@ -17,7 +18,37 @@ type gitService struct {
17
18
}
18
19
19
20
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
+ */
21
52
}
22
53
23
54
func (s * gitService ) DeleteRef (ctx context.Context , repo , ref string ) (* scm.Response , error ) {
0 commit comments