Skip to content

Commit

Permalink
Merge pull request #2 from fjukstad/flags
Browse files Browse the repository at this point in the history
u fukr
  • Loading branch information
3inar committed Oct 6, 2014
2 parents d7f233b + 7558810 commit 6324e10
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 23 deletions.
92 changes: 69 additions & 23 deletions GEThub.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,74 @@
package main

import "fmt"
import "github.com/google/go-github/github"
import "code.google.com/p/goauth2/oauth"
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() {
// NB: go to github and make yourself an access token
token := "your token goes here"
t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
}

client := github.NewClient(t.Client())
repos, _, _ := client.Repositories.ListForks("uit-inf-3200", "Project-1",
nil)
messages := make([]string, 0)

for _, fork := range repos {
comms, _, _ := client.Repositories.ListCommits(*fork.Owner.Login,
*fork.Name, nil)
for _, commit := range comms{
messages= append(messages, *commit.Commit.Message)
}
}

for _, m := range messages { fmt.Println(m) }
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)
}
}
6 changes: 6 additions & 0 deletions conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Token": "your app token",
"Org": "Name of organization",
"Repo": "Repository name"
}

0 comments on commit 6324e10

Please sign in to comment.