Skip to content

Commit

Permalink
Merge pull request drone#35 from jstrachan/stuff
Browse files Browse the repository at this point in the history
fix: add a bitbucket cloud FindRef method
  • Loading branch information
jenkins-x-bot authored Oct 7, 2019
2 parents 6fc527f + 57391e9 commit 6998dcc
Show file tree
Hide file tree
Showing 3 changed files with 1,021 additions and 1 deletion.
33 changes: 32 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/jenkins-x/go-scm/scm"
Expand All @@ -17,7 +18,37 @@ type gitService struct {
}

func (s *gitService) FindRef(ctx context.Context, repo, ref string) (string, *scm.Response, error) {
panic("implement me")
commit, res, err := s.FindCommit(ctx, repo, ref)
if err != nil && res.Status != 404 {
return "", res, err
}
if commit != nil {
if commit.Sha != "" {
return commit.Sha, res, nil
}
}
idx := strings.LastIndex(ref, "/")
if idx >= 0 {
ref = ref[idx+1:]
}
return ref, nil, nil

/*
path := fmt.Sprintf("2.0/repositories/%s/refs?%s", repo, encodeRefQueryOptions(ref))
out := new(branches)
res, err := s.client.do(ctx, "GET", path, nil, out)
if debugDump {
var buf bytes.Buffer
res, err := s.client.do(ctx, "GET", path, nil, &buf)
fmt.Printf("%s\n", buf.String())
return "", res, err
}
branches := convertBranchList(out)
if len(branches) == 0 {
return "", res, err
}
return branches[0].Name, res, err
*/
}

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

0 comments on commit 6998dcc

Please sign in to comment.