Skip to content

Commit

Permalink
capture the git object hash
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Nov 3, 2020
1 parent 427b8a8 commit 5230330
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions scm/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ type (
Content struct {
Path string
Data []byte

// the has of the blob. this is the equivalent
// to running the git hash-object command.
Hash string
}

// ContentParams provide parameters for creating and
Expand Down
2 changes: 2 additions & 0 deletions scm/driver/github/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"encoding/base64"
"fmt"

"github.com/drone/go-scm/scm"
)

Expand All @@ -21,6 +22,7 @@ func (s *contentService) Find(ctx context.Context, repo, path, ref string) (*scm
res, err := s.client.do(ctx, "GET", endpoint, nil, out)
raw, _ := base64.StdEncoding.DecodeString(out.Content)
return &scm.Content{
Hash: out.Sha,
Path: out.Path,
Data: raw,
}, res, err
Expand Down
3 changes: 2 additions & 1 deletion scm/driver/github/testdata/content.json.golden
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Path": "README",
"Data": "SGVsbG8gV29ybGQhCg=="
"Data": "SGVsbG8gV29ybGQhCg==",
"Hash": "980a0d5f19a64b4b30a87d4206aade58726b60e3"
}

0 comments on commit 5230330

Please sign in to comment.