Skip to content

Commit

Permalink
Merge pull request #1 from smartystreets/skip-repos
Browse files Browse the repository at this point in the history
Adding the option to skip reviewing a repository.
  • Loading branch information
Michael Whatcott authored Aug 30, 2019
2 parents 241f209 + 8043254 commit 00e2dc7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ CLI Flags:
line arguments representing paths to git repositories are provided.
--> (default "CDPATH")
```


Skipping Repositories:

If you have repositories in your list that you would rather not review,
you can mark them to be skipped by adding a config variable to the
repository. The following command will produce this result:

git config --add review.skip true
21 changes: 20 additions & 1 deletion git.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var (
gitFetchPendingReview = ".." // ie. [7761a97..1bbecb6 master -> origin/master]
gitRevListCommand = "git rev-list --left-right master...origin/master" // 1 line per commit w/ prefix '<' (ahead) or '>' (behind)
gitErrorTemplate = "[ERROR] Could not execute [%s]: %v" + "\n"
gitSkipCommand = "git config --get review.skip"
)

type GitReport struct {
Expand All @@ -21,11 +22,13 @@ type GitReport struct {
StatusError string
FetchError string
RevListError string
SkipError string

RemoteOutput string
StatusOutput string
FetchOutput string
RevListOutput string
SkipOutput string

RevListAhead string
RevListBehind string
Expand Down Expand Up @@ -55,6 +58,17 @@ func (this *GitReport) GitStatus() {
this.StatusOutput = output
}
}
func (this *GitReport) GitSkipStatus() bool {
out, err := execute(this.RepoPath, gitSkipCommand)
if err != nil && err.Error() != "exit status 1" {
this.SkipError = fmt.Sprintf(gitErrorTemplate, gitSkipCommand, err)
}
if strings.Contains(out, "true") {
this.SkipOutput = out
return true
}
return false
}
func (this *GitReport) GitFetch() {
out, err := execute(this.RepoPath, gitFetchCommand)
if err != nil {
Expand Down Expand Up @@ -113,5 +127,10 @@ func (this *GitReport) Progress() string {
} else {
status += " "
}
return fmt.Sprintf("[%-5s] %s", status, this.RepoPath)
if len(this.SkipOutput) > 0 {
status += "S"
} else {
status += " "
}
return fmt.Sprintf("[%-6s] %s", status, this.RepoPath)
}
8 changes: 7 additions & 1 deletion review.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type GitReviewer struct {
behind map[string]string
fetched map[string]string
journal map[string]string
skipped map[string]string
}

func NewGitReviewer(config *Config) *GitReviewer {
Expand All @@ -33,12 +34,13 @@ func NewGitReviewer(config *Config) *GitReviewer {
behind: make(map[string]string),
fetched: make(map[string]string),
journal: 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: [!] = error; [M] = messy; [A] = ahead; [B] = behind; [F] = fetched;")
log.Println("Legend: [!] = error; [M] = messy; [A] = ahead; [B] = behind; [F] = fetched; [S] = skipped;")
reports := NewAnalyzer(workerCount).AnalyzeAll(this.repoPaths)
for _, report := range reports {
if len(report.StatusError) > 0 {
Expand All @@ -63,6 +65,9 @@ func (this *GitReviewer) GitAnalyzeAll() {
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
Expand All @@ -87,6 +92,7 @@ func (this *GitReviewer) ReviewAll() {
printMapKeys(this.behind, "Repositories behind origin master: %d")
printMapKeys(this.fetched, "Repositories with new content since the last review: %d")
printMapKeys(this.journal, "Repositories to be included in the final report: %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)))
Expand Down
10 changes: 6 additions & 4 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ func (this *Worker) Start() {
func (this *Worker) git(path string) *GitReport {
path, _ = filepath.Abs(path)
report := &GitReport{RepoPath: path}
report.GitRemote()
report.GitStatus()
report.GitFetch()
report.GitRevList()
if !report.GitSkipStatus() {
report.GitRemote()
report.GitStatus()
report.GitFetch()
report.GitRevList()
}
log.Println(report.Progress())
return report
}

0 comments on commit 00e2dc7

Please sign in to comment.