diff --git a/github/examples_test.go b/github/examples_test.go new file mode 100644 index 0000000..7b754cd --- /dev/null +++ b/github/examples_test.go @@ -0,0 +1,75 @@ +// Copyright 2016 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github_test + +import ( + "fmt" + "log" + + "github.com/google/go-github/github" +) + +func ExampleClient_Markdown() { + client := github.NewClient(nil) + + input := "# heading #\n\nLink to issue #1" + opt := &github.MarkdownOptions{Mode: "gfm", Context: "google/go-github"} + + output, _, err := client.Markdown(input, opt) + if err != nil { + fmt.Println(err) + } + + fmt.Println(output) +} + +func ExampleRepositoriesService_GetReadme() { + client := github.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 ExampleRepositoriesService_List() { + client := github.NewClient(nil) + + user := "willnorris" + opt := &github.RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} + + repos, _, err := client.Repositories.List(user, opt) + if err != nil { + fmt.Println(err) + } + + fmt.Printf("Recently updated repositories by %q: %v", user, github.Stringify(repos)) +} + +func ExampleUsersService_ListAll() { + client := github.NewClient(nil) + opts := &github.UserListOptions{} + for { + users, _, err := client.Users.ListAll(opts) + if err != nil { + log.Fatalf("error listing users: %v", err) + } + if len(users) == 0 { + break + } + opts.Since = *users[len(users)-1].ID + // Process users... + } +} diff --git a/github/misc_test.go b/github/misc_test.go index 16c5512..8ca58d2 100644 --- a/github/misc_test.go +++ b/github/misc_test.go @@ -46,20 +46,6 @@ func TestMarkdown(t *testing.T) { } } -func ExampleClient_Markdown() { - client := NewClient(nil) - - input := "# heading #\n\nLink to issue #1" - opt := &MarkdownOptions{Mode: "gfm", Context: "google/go-github"} - - output, _, err := client.Markdown(input, opt) - if err != nil { - fmt.Println(err) - } - - fmt.Println(output) -} - func TestListEmojis(t *testing.T) { setup() defer teardown() diff --git a/github/repos_contents_test.go b/github/repos_contents_test.go index 65b917c..543d8be 100644 --- a/github/repos_contents_test.go +++ b/github/repos_contents_test.go @@ -119,24 +119,6 @@ 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() diff --git a/github/repos_test.go b/github/repos_test.go index c864aff..4544c55 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -67,20 +67,6 @@ func TestRepositoriesService_List_invalidUser(t *testing.T) { testURLParseError(t, err) } -func ExampleRepositoriesService_List() { - client := NewClient(nil) - - user := "willnorris" - opt := &RepositoryListOptions{Type: "owner", Sort: "updated", Direction: "desc"} - - repos, _, err := client.Repositories.List(user, opt) - if err != nil { - fmt.Println(err) - } - - fmt.Printf("Recently updated repositories by %q: %v", user, Stringify(repos)) -} - func TestRepositoriesService_ListByOrg(t *testing.T) { setup() defer teardown() diff --git a/github/users.go b/github/users.go index 1c57612..1315636 100644 --- a/github/users.go +++ b/github/users.go @@ -145,20 +145,6 @@ type UserListOptions struct { // ListAll lists all GitHub users. // // To paginate through all users, populate 'Since' with the ID of the last user. -// Example (warning: this will quickly eat through your GitHub API quota!): -// -// opts := &github.UserListOptions{} -// for { -// users, _, err := client.Users.ListAll(opts) -// if err != nil { -// log.Fatalf("error listing users: %v", err) -// } -// if len(users) == 0 { -// break -// } -// opts.Since = *users[len(users)-1].ID -// // Process users... -// } // // GitHub API docs: http://developer.github.com/v3/users/#get-all-users func (s *UsersService) ListAll(opt *UserListOptions) ([]User, *Response, error) {