aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/google/go-github/github/git_blobs.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/google/go-github/github/git_blobs.go')
-rw-r--r--vendor/github.com/google/go-github/github/git_blobs.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/vendor/github.com/google/go-github/github/git_blobs.go b/vendor/github.com/google/go-github/github/git_blobs.go
index 67ea74a..5290c55 100644
--- a/vendor/github.com/google/go-github/github/git_blobs.go
+++ b/vendor/github.com/google/go-github/github/git_blobs.go
@@ -6,6 +6,7 @@
package github
import (
+ "bytes"
"context"
"fmt"
)
@@ -17,9 +18,10 @@ type Blob struct {
SHA *string `json:"sha,omitempty"`
Size *int `json:"size,omitempty"`
URL *string `json:"url,omitempty"`
+ NodeID *string `json:"node_id,omitempty"`
}
-// GetBlob fetchs a blob from a repo given a SHA.
+// GetBlob fetches a blob from a repo given a SHA.
//
// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha string) (*Blob, *Response, error) {
@@ -29,11 +31,31 @@ func (s *GitService) GetBlob(ctx context.Context, owner string, repo string, sha
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
+
blob := new(Blob)
resp, err := s.client.Do(ctx, req, blob)
return blob, resp, err
}
+// GetBlobRaw fetches a blob's contents from a repo.
+// Unlike GetBlob, it returns the raw bytes rather than the base64-encoded data.
+//
+// GitHub API docs: https://developer.github.com/v3/git/blobs/#get-a-blob
+func (s *GitService) GetBlobRaw(ctx context.Context, owner, repo, sha string) ([]byte, *Response, error) {
+ u := fmt.Sprintf("repos/%v/%v/git/blobs/%v", owner, repo, sha)
+ req, err := s.client.NewRequest("GET", u, nil)
+ if err != nil {
+ return nil, nil, err
+ }
+ req.Header.Set("Accept", "application/vnd.github.v3.raw")
+
+ var buf bytes.Buffer
+ resp, err := s.client.Do(ctx, req, &buf)
+ return buf.Bytes(), resp, err
+}
+
// CreateBlob creates a blob object.
//
// GitHub API docs: https://developer.github.com/v3/git/blobs/#create-a-blob
@@ -44,6 +66,9 @@ func (s *GitService) CreateBlob(ctx context.Context, owner string, repo string,
return nil, nil, err
}
+ // TODO: remove custom Accept header when this API fully launches.
+ req.Header.Set("Accept", mediaTypeGraphQLNodeIDPreview)
+
t := new(Blob)
resp, err := s.client.Do(ctx, req, t)
return t, resp, err