forked from smarty/gitreview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreview.go
More file actions
103 lines (93 loc) · 3.12 KB
/
review.go
File metadata and controls
103 lines (93 loc) · 3.12 KB
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
package main
import (
"fmt"
"log"
"os/exec"
"time"
)
type GitReviewer struct {
config *Config
repoPaths []string
erred map[string]string
messy map[string]string
ahead map[string]string
behind map[string]string
fetched map[string]string
skipped map[string]string
}
func NewGitReviewer(config *Config) *GitReviewer {
return &GitReviewer{
config: config,
repoPaths: collectGitRepositories(config.GitRepositoryRoot),
erred: make(map[string]string),
messy: make(map[string]string),
ahead: make(map[string]string),
behind: make(map[string]string),
fetched: make(map[string]string),
skipped: make(map[string]string),
}
}
func (this *GitReviewer) GitAnalyzeAll() {
log.Printf("Analyzing %d git repositories...", len(this.repoPaths))
log.Println("Legend:")
log.Println(" [!] error")
log.Println(" [M] messy")
log.Println(" [A] ahead")
log.Println(" [B] behind")
log.Println(" [F] fetched")
log.Println(" [S] skipped")
reports := NewAnalyzer(workerCount, this.config.GitDefaultBranch).AnalyzeAll(this.repoPaths)
for _, report := range reports {
if len(report.StatusError) > 0 {
this.erred[report.RepoPath] += report.StatusError
log.Println(report.RepoPath, report.StatusError)
}
if len(report.FetchError) > 0 {
this.erred[report.RepoPath] += report.FetchError
log.Println(report.RepoPath, report.FetchError)
}
if len(report.RevListError) > 0 {
this.erred[report.RepoPath] += report.RevListError
log.Println(report.RepoPath, report.RevListError)
}
if len(report.StatusOutput) > 0 {
this.messy[report.RepoPath] += report.StatusOutput
}
if len(report.RevListAhead) > 0 {
this.ahead[report.RepoPath] += report.RevListAhead
}
if len(report.RevListBehind) > 0 {
this.behind[report.RepoPath] += report.RevListBehind
}
if len(report.SkipOutput) > 0 {
this.skipped[report.RepoPath] += report.SkipOutput
}
if this.config.GitFetch && len(report.FetchOutput) > 0 {
this.fetched[report.RepoPath] += report.FetchOutput + report.RevListOutput
}
}
}
func (this *GitReviewer) ReviewAll() {
reviewable := sortUniqueKeys(this.erred, this.messy, this.ahead, this.behind, this.fetched)
if len(reviewable) == 0 {
log.Println("Nothing to review at this time.")
return
}
printMapKeys(this.erred, "Repositories with git errors: %d")
printMapKeys(this.messy, "Repositories with uncommitted changes: %d")
printMapKeys(this.ahead, "Repositories ahead of their origin: %d")
printMapKeys(this.behind, "Repositories behind their origin: %d")
printMapKeys(this.fetched, "Repositories with new content since the last review: %d")
printMapKeys(this.skipped, "Repositories that were skipped: %d")
printStrings(reviewable, "Repositories to be reviewed: %d")
prompt(fmt.Sprintf("Press <ENTER> to initiate the review process (will open %d review windows)...", len(reviewable)))
for _, path := range reviewable {
log.Printf("Opening %s at %s", this.config.GitGUILauncher, path)
err := exec.Command(this.config.GitGUILauncher, path).Run()
if err != nil {
log.Println("Failed to open git GUI:", err)
}
time.Sleep(time.Millisecond * 25)
}
}
const workerCount = 16