diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2018-06-20 22:39:07 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2018-06-20 22:39:07 +0100 |
commit | de6d2c524430287c699aaa898c1325da6afea539 (patch) | |
tree | f78eb841208d667668a7bc92a9290d693cc7103b /vendor/github.com/google/go-github/github/git_blobs.go | |
parent | eb99016e1629e690e55633de6fc63a14c53e7ea2 (diff) |
Update dependencies
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.go | 27 |
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 |