-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fjukstad/flags
u fukr
- Loading branch information
Showing
2 changed files
with
75 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|