diff --git a/github/repos_contents.go b/github/repos_contents.go index 84b3400..ebf4d04 100644 --- a/github/repos_contents.go +++ b/github/repos_contents.go @@ -21,11 +21,14 @@ import ( // RepositoryContent represents a file or directory in a github repository. type RepositoryContent struct { - Type *string `json:"type,omitempty"` - Encoding *string `json:"encoding,omitempty"` - Size *int `json:"size,omitempty"` - Name *string `json:"name,omitempty"` - Path *string `json:"path,omitempty"` + Type *string `json:"type,omitempty"` + Encoding *string `json:"encoding,omitempty"` + Size *int `json:"size,omitempty"` + Name *string `json:"name,omitempty"` + Path *string `json:"path,omitempty"` + // Content contains the actual file content, which may be encoded. + // Callers should call GetContent which will decode the content if + // necessary. Content *string `json:"content,omitempty"` SHA *string `json:"sha,omitempty"` URL *string `json:"url,omitempty"` @@ -56,6 +59,7 @@ type RepositoryContentGetOptions struct { Ref string `url:"ref,omitempty"` } +// String converts RepositoryContent to a string. It's primarily for testing. func (r RepositoryContent) String() string { return Stringify(r) } diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index 543d8be..65b917c 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -119,6 +119,24 @@ func TestRepositoriesService_GetReadme(t *testing.T) { } } +func ExampleRepositoriesService_GetReadme() { + client := NewClient(nil) + + readme, _, err := client.Repositories.GetReadme("google", "go-github", nil) + if err != nil { + fmt.Println(err) + return + } + + content, err := readme.GetContent() + if err != nil { + fmt.Println(err) + return + } + + fmt.Printf("google/go-github README:\n%v\n", content) +} + func TestRepositoriesService_DownloadContents_Success(t *testing.T) { setup() defer teardown()