Skip to content

Commit

Permalink
config file with org and repo
Browse files Browse the repository at this point in the history
  • Loading branch information
fjukstad committed Oct 6, 2014
1 parent bce3c99 commit 451abc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 10 additions & 9 deletions GEThub.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,48 @@ import (

type Config struct {
Token string
Org string
Repo string
}

func getAppToken(filename string) (string, error) {
func readConfig(filename string) (Config, error) {

file, err := os.Open(filename)
config := Config{}

if err != nil {
return "", errors.New("Cannot find config file!")
return config, errors.New("Cannot find config file!")
}

decoder := json.NewDecoder(file)
config := Config{}

err = decoder.Decode(&config)

if err != nil {
fmt.Println("error:", err)
}

return config.Token, nil
return config, nil
}

func main() {
configFile := flag.String("configfile", "conf.json",
configFile := flag.String("config", "conf.json",
"Configuration file. Where your app token lives")

flag.Parse()

token, err := getAppToken(*configFile)
config, err := readConfig(*configFile)
if err != nil {
fmt.Println(err)
return
}

t := &oauth.Transport{
Token: &oauth.Token{AccessToken: token},
Token: &oauth.Token{AccessToken: config.Token},
}

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

for _, fork := range repos {
Expand Down
4 changes: 3 additions & 1 deletion conf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"Token": "your app token"
"Token": "your app token",
"Org": "Name of organization",
"Repo": "Repository name"
}

0 comments on commit 451abc7

Please sign in to comment.