forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples_test.go
76 lines (60 loc) · 1.66 KB
/
examples_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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 (
"context"
"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(context.Background(), input, opt)
if err != nil {
fmt.Println(err)
}
fmt.Println(output)
}
func ExampleRepositoriesService_GetReadme() {
client := github.NewClient(nil)
readme, _, err := client.Repositories.GetReadme(context.Background(), "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(context.Background(), 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(context.Background(), 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...
}
}