-
Notifications
You must be signed in to change notification settings - Fork 1
/
description.go
47 lines (37 loc) · 956 Bytes
/
description.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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)
var logger = log.New(os.Stdout, ">>> ", log.Lshortfile)
func main() {
flag.Parse()
description, err := fetchRepoDescription(context.Background(), "mbtamuli", "playground")
if err != nil {
log.Fatal(err)
}
fmt.Println(description)
}
func fetchRepoDescription(ctx context.Context, owner, name string) (string, error) {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
httpClient := oauth2.NewClient(context.Background(), src)
client := githubv4.NewClient(httpClient)
var q struct {
Repository struct {
Description string
} `graphql:"repository(owner: $owner, name: $name)"`
}
variables := map[string]interface{}{
"owner": githubv4.String(owner),
"name": githubv4.String(name),
}
err := client.Query(ctx, &q, variables)
return q.Repository.Description, err
}