-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.go
125 lines (111 loc) · 3.35 KB
/
project.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package dashboard
import (
"fmt"
"log"
"sync"
"time"
)
var (
defaultProjectMap map[string]*Project
defaultProjects = []*Project{
makeProject("bunto", "bunto/bunto", "ruby", "bunto"),
makeProject("bemoji", "bunto/bemoji", "master", "bemoji"),
makeProject("mercenary", "bunto/mercenary", "master", "bunto-mercenary"),
makeProject("bunto-import", "bunto/bunto-import", "master", "bunto-import"),
makeProject("bunto-feed", "bunto/bunto-feed", "master", "bunto-feed"),
makeProject("bunto-sitemap", "bunto/bunto-sitemap", "master", "bunto-sitemap"),
makeProject("bunto-mentions", "bunto/bunto-mentions", "master", "bunto-mentions"),
makeProject("bunto-watch", "bunto/bunto-watch", "master", "bunto-watch"),
makeProject("bunto-compose", "bunto/bunto-compose", "master", "bunto-compose"),
makeProject("bunto-paginate", "bunto/bunto-paginate", "master", "bunto-paginate"),
makeProject("bunto-gist", "bunto/bunto-gist", "master", "bunto-gist"),
makeProject("bunto-coffeescript", "bunto/bunto-coffeescript", "master", "bunto-coffeescript"),
makeProject("bunto-opal", "bunto/bunto-opal", "master", "bunto-opal"),
makeProject("classifier-reborn", "bunto/classifier-reborn", "master", "bunto-classifier-reborn"),
makeProject("bunto-sass-converter", "bunto/bunto-sass-converter", "master", "bunto-sass-converter"),
makeProject("bunto-textile-converter", "bunto/bunto-textile-converter", "master", "bunto-textile-converter"),
makeProject("bunto-redirect-from", "bunto/bunto-redirect-from", "master", "bunto-redirect-from"),
makeProject("github-metadata", "bunto/github-metadata", "master", "bunto-github-metadata"),
makeProject("plugins.buntorb", "bunto/plugins", "gh-pages", ""),
makeProject("bunto docker", "bunto/docker", "", ""),
}
)
func init() {
go resetProjectsPeriodically()
}
func resetProjectsPeriodically() {
for range time.Tick(time.Hour / 2) {
log.Println("resetting projects' cache")
resetProjects()
}
}
func resetProjects() {
for _, p := range defaultProjects {
p.reset()
}
}
type Project struct {
Name string `json:"name"`
Nwo string `json:"nwo"`
Branch string `json:"branch"`
GemName string `json:"gem_name"`
Gem *RubyGem `json:"gem"`
Travis *TravisReport `json:"travis"`
GitHub *GitHub `json:"github"`
fetched bool
}
func (p *Project) fetch() {
if !p.fetched {
rubyGemChan := rubygem(p.GemName)
travisChan := travis(p.Nwo, p.Branch)
githubChan := github(p.Nwo)
p.Gem = <-rubyGemChan
p.Travis = <-travisChan
p.GitHub = <-githubChan
p.fetched = true
}
}
func (p *Project) reset() {
p.fetched = false
p.Gem = nil
p.Travis = nil
p.GitHub = nil
}
func buildProjectMap() {
defaultProjectMap = map[string]*Project{}
for _, p := range defaultProjects {
defaultProjectMap[p.Name] = p
}
}
func makeProject(name, nwo, branch, rubygem string) *Project {
return &Project{
Name: name,
Nwo: nwo,
Branch: branch,
GemName: rubygem,
}
}
func getProject(name string) Project {
if defaultProjectMap == nil {
buildProjectMap()
}
if p, ok := defaultProjectMap[name]; ok {
if !p.fetched {
p.fetch()
}
return *p
}
panic(fmt.Sprintf("no project named '%s'", name))
}
func getAllProjects() []*Project {
var wg sync.WaitGroup
for _, p := range defaultProjects {
wg.Add(1)
go func(project *Project) {
project.fetch()
wg.Done()
}(p)
}
wg.Wait()
return defaultProjects
}