-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.go
111 lines (97 loc) · 1.98 KB
/
worker.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"clickyab.com/git-report/assert"
git "gopkg.in/src-d/go-git.v4"
)
type config struct {
Name string `json:"name"`
URL string `json:"url"`
Github string `json:"github"`
Redmine string `json:"redmine"`
Users []struct {
ID string `json:"id"`
Pass string `json:"pass"`
} `json:"users"`
Path string `json:"_"`
}
var (
path = ""
port = 0
configName = ".report.conf"
repositories = make([]repository, 0)
)
func loadConfig() {
path = os.Getenv("REPORTPATH")
if path == "" {
panic("please set REPORTPATH in your environment")
}
var e error
port, e = strconv.Atoi(os.Getenv("PORT"))
assert.Nil(e)
if port == 0 {
panic("please add a valid PORT in your environment ")
}
if c := os.Getenv("RCONFIG"); c != "" {
configName = c
}
}
func init() {
loadConfig()
}
var configs = make([]*config, 0)
func find(path string) []*config {
var configs = make([]*config, 0)
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if !strings.HasSuffix(path, configName) {
return nil
}
b, e := ioutil.ReadFile(path)
assert.Nil(e)
c := &config{}
e = json.Unmarshal(b, c)
assert.Nil(e)
c.Path = strings.Replace(path, configName, "", -1)
fmt.Println(c.Name)
configs = append(configs, c)
return nil
})
if len(configs) < 1 {
fmt.Println(fmt.Sprintf(`Didn't find any config file in "%s"`, path))
os.Exit(1)
}
return configs
}
func filter(id, pass string) []*config {
r := make([]*config, 0)
for _, c := range configs {
for _, u := range c.Users {
if u.ID == id && u.Pass == pass {
r = append(r, c)
}
}
}
return r
}
func getRepo(c config) repository {
r, e := git.PlainOpen(c.Path)
assert.Nil(e)
cs := commits(r)
return repository{
Name: c.Name,
Commits: cs,
URL: c.URL,
Github: c.Github,
Redmine: c.Redmine,
}
}
type user struct {
ID string `json:"id"`
Pass string `json:"pass"`
}