/
GEThub.go
74 lines (57 loc) · 1.28 KB
/
GEThub.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
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"os"
"strings"
"code.google.com/p/goauth2/oauth"
"github.com/google/go-github/github"
)
type Config struct {
Token string
Org string
Repo string
}
func readConfig(filename string) (Config, error) {
file, err := os.Open(filename)
config := Config{}
if err != nil {
return config, errors.New("Cannot find config file!")
}
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
fmt.Println("error:", err)
}
return config, nil
}
func main() {
configFile := flag.String("config", "conf.json",
"Configuration file. Where your app token lives")
flag.Parse()
config, err := readConfig(*configFile)
if err != nil {
fmt.Println(err)
return
}
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: config.Token},
}
client := github.NewClient(t.Client())
repos, _, _ := client.Repositories.ListForks(config.Org, config.Repo, nil)
messages := make([]string, 0)
for _, fork := range repos {
comms, _, _ := client.Repositories.ListCommits(*fork.Owner.Login,
*fork.Name, nil)
for _, commit := range comms {
m := *commit.Commit.Message
brief := strings.Split(m, "\n")[0]
messages = append(messages, brief)
}
}
for _, m := range messages {
fmt.Println(m)
}
}