From 523033025a7ee875fcfb156f4c660b37e269b1a8 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 3 Nov 2020 12:33:12 -0500 Subject: [PATCH] capture the git object hash --- scm/content.go | 4 ++++ scm/driver/github/content.go | 2 ++ scm/driver/github/testdata/content.json.golden | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/scm/content.go b/scm/content.go index 99a3553c0..e28dc7b56 100644 --- a/scm/content.go +++ b/scm/content.go @@ -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 diff --git a/scm/driver/github/content.go b/scm/driver/github/content.go index ac67a05ff..16ae4b506 100644 --- a/scm/driver/github/content.go +++ b/scm/driver/github/content.go @@ -8,6 +8,7 @@ import ( "context" "encoding/base64" "fmt" + "github.com/drone/go-scm/scm" ) @@ -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 diff --git a/scm/driver/github/testdata/content.json.golden b/scm/driver/github/testdata/content.json.golden index e088c4bac..4c414c519 100644 --- a/scm/driver/github/testdata/content.json.golden +++ b/scm/driver/github/testdata/content.json.golden @@ -1,4 +1,5 @@ { "Path": "README", - "Data": "SGVsbG8gV29ybGQhCg==" + "Data": "SGVsbG8gV29ybGQhCg==", + "Hash": "980a0d5f19a64b4b30a87d4206aade58726b60e3" } \ No newline at end of file