...
1
2
3
4
5
6
7
8 package demo
9
10 import (
11 "fmt"
12 "net/http"
13 "os"
14
15 "github.com/google/go-github/v33/github"
16 "golang.org/x/oauth2"
17 "google.golang.org/appengine"
18 "google.golang.org/appengine/log"
19 )
20
21 func init() {
22 http.HandleFunc("/", handler)
23 }
24
25 func handler(w http.ResponseWriter, r *http.Request) {
26 if r.URL.Path != "/" {
27 http.NotFound(w, r)
28 return
29 }
30
31 ctx := appengine.NewContext(r)
32 ts := oauth2.StaticTokenSource(
33 &oauth2.Token{AccessToken: os.Getenv("GITHUB_AUTH_TOKEN")},
34 )
35 tc := oauth2.NewClient(ctx, ts)
36 client := github.NewClient(tc)
37
38 commits, _, err := client.Repositories.ListCommits(ctx, "google", "go-github", nil)
39 if err != nil {
40 log.Errorf(ctx, "ListCommits: %v", err)
41 http.Error(w, err.Error(), http.StatusInternalServerError)
42 return
43 }
44
45 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
46 for _, commit := range commits {
47 fmt.Fprintln(w, commit.GetHTMLURL())
48 }
49 }
50
View as plain text