This repository has been archived by the owner on Oct 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
69 lines (56 loc) · 1.51 KB
/
main.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
package main
import (
"fmt"
"os"
"encoding/json"
"github.com/cloudfoundry-incubator/cf-extensions/bot"
"io/ioutil"
)
const VERSION = "0.9.0"
type Credentials struct {
Username string `json:"username"`
Email string `json:"email"`
AccessToken string `json:"accessToken"`
TopicFilters []string `json:"topicFilters"`
Orgs []string `json:"orgs"`
}
const credentialsExample = `{
"username": "john",
"email": "john@smith.com",
"accessToken": "ADD-GITHUB-ACCESS-TOKEN-HERE",
"topicFilters": ["test", "topic"],
"orgs": ["org0", "org1"]
}
`
func main() {
fmt.Printf("CF-Extensions github bot v%s\n", VERSION)
if len(os.Args) < 2 {
usage()
os.Exit(0)
}
credentials, err := parseCredentials(os.Args[1])
if err != nil {
fmt.Printf("Error parsing credentials from file: %s, message: %s\n", os.Args[1], err.Error())
usage()
os.Exit(1)
}
app := bot.NewApp(credentials.AccessToken, credentials.Username, credentials.Email)
app.Run(credentials.Orgs[0], credentials.TopicFilters)
}
func usage() {
fmt.Printf("Usage:\n")
fmt.Printf(" $cf-extensions credentials.json\n")
fmt.Printf(" where credentials.json contains GitHub credentials and info, e.g., \n%s\n", credentialsExample)
}
func parseCredentials(filePath string) (Credentials, error) {
fileBytes, err := ioutil.ReadFile(filePath)
if err != nil {
return Credentials{}, err
}
credentials := Credentials{}
err = json.Unmarshal(fileBytes, &credentials)
if err != nil {
return Credentials{}, err
}
return credentials, nil
}