· 7 years ago · Nov 27, 2017, 03:58 PM
1package main
2import (
3 "fmt"
4 "log"
5
6 "golang.org/x/net/context"
7
8 "github.com/google/go-github/github"
9 "golang.org/x/oauth2"
10)
11
12func check(err error) {
13 if err != nil {
14 log.Fatal(err)
15 }
16}
17
18/**
19 * this function is used to get the repositories of the client
20 */
21func getRepo(client *github.Client) []*github.Repository {
22 ctx := context.Background()
23
24 repos, _, err := client.Repositories.List(ctx, "", nil)
25
26 check(err)
27
28 fmt.Printf("n%vn", github.Stringify(repos))
29
30 return repos
31}
32
33/**
34 * this function is used to get Authentification using a oauth token
35 */
36func getAuth() *github.Client {
37 ctx := context.Background()
38
39 ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: "OAUTH_TOKEN"})
40
41 tc := oauth2.NewClient(ctx, ts)
42 client := github.NewClient(tc)
43
44 return client
45}
46
47/**
48 * this function is used to get notification on the client's account
49 */
50func getNotif(client *github.Client) []*github.Notification {
51 ctx := context.Background()
52
53 notifs, resp, err := client.Activity.ListRepositoryNotifications(ctx, "AlexandreMazgaj", "task_app", nil)
54
55 fmt.Printf("Status code of the response: %dn", resp.StatusCode)
56 check(err)
57
58 return notifs
59}
60
61func main() {
62 // first we get authentification
63 client := getAuth()
64 // then we get the notifications
65 notifs := getNotif(client)
66
67 fmt.Printf("n%vn", github.Stringify(notifs))
68
69}