-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (52 loc) · 1.12 KB
/
main.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
package main
import (
"context"
"fmt"
"io/ioutil"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
const (
owner = "siansiansu"
repo = "nvim"
contentPath = "README.md"
branch = "main"
token = ""
)
func main() {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)
c := github.NewClient(tc)
oct, _, err := c.Octocat(ctx, "hello world!")
if err != nil {
fmt.Println(err)
}
fmt.Println(oct)
_, tree, _, err := c.Repositories.GetContents(ctx, owner, repo, ".", &github.RepositoryContentGetOptions{
Ref: "main",
})
if err != nil {
panic(err)
}
for i := range tree {
if tree[i].GetType() == "file" {
fmt.Println(tree[i].GetName())
}
}
// // Get File From Github repositories
readCloser, err := c.Repositories.DownloadContents(ctx, owner, repo, contentPath, &github.RepositoryContentGetOptions{
Ref: branch,
})
defer readCloser.Close()
if err != nil {
panic(err)
}
content, err := ioutil.ReadAll(readCloser)
if err != nil {
panic(err)
}
fmt.Println(string(content))
}