Skip to content

Commit

Permalink
Fixing git history error handling for commands.
Browse files Browse the repository at this point in the history
Signed-off-by: quobix <[email protected]>
  • Loading branch information
daveshanley committed Dec 1, 2023
1 parent 536045a commit 44e0ea2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
4 changes: 0 additions & 4 deletions builder/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package builder

import (
"fmt"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
wcModel "github.com/pb33f/libopenapi/what-changed/model"
"github.com/pb33f/libopenapi/what-changed/reports"
Expand Down Expand Up @@ -287,9 +286,6 @@ func extractChangeCount(change reports.HasChanges) (int, int) {

func DigIntoTreeNode[T any](parent *model.TreeNode, field reflect.Value, label string, tc, br int) {
if !field.IsZero() {
if label == "path" {
fmt.Println("hello")
}
e := &model.TreeNode{
TitleString: label,
Key: uuid.NewV4().String(),
Expand Down
7 changes: 7 additions & 0 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,25 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
model.SendProgressError("reading paths",
err.Error(), errorChan)
close(progressChan)
return nil, nil, []error{err}
}

// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, progressChan, errorChan)
if err != nil {
model.SendFatalError("extraction",
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
close(progressChan)
return nil, nil, err
}

// populate history with changes and data
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, progressChan, errorChan, base, remote)
if err != nil {
model.SendFatalError("extraction",
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
close(progressChan)
return nil, nil, err
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func GetReportCommand() *cobra.Command {
}

listenForUpdates := func(updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) {

for {
select {
case _, ok := <-updateChan:
Expand All @@ -65,9 +66,7 @@ func GetReportCommand() *cobra.Command {
return
}
case <-errorChan:
failed = true
doneChan <- true
return
// do nothing.
}
}
}
Expand All @@ -93,7 +92,7 @@ func GetReportCommand() *cobra.Command {
}
report, er := runGithubHistoryReport(user, repo, filePath, latestFlag, limitFlag, updateChan,
errorChan, baseFlag, remoteFlag)

// wait for things to be completed.
<-doneChan

Expand Down Expand Up @@ -220,6 +219,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
if gitPath == "" || filePath == "" {
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
model.SendProgressError("git", err.Error(), errorChan)
close(updateChan)
return nil, []error{err}
}

Expand All @@ -230,13 +230,16 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan)
if err != nil {
model.SendProgressError("git", fmt.Sprintf("%d errors found building history", len(err)), errorChan)
close(updateChan)
return nil, err
}

// populate history with changes and data
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, updateChan, errorChan, base, remote)
if err != nil {
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(err)), errorChan)
close(updateChan)
return nil, err
}

Expand Down Expand Up @@ -271,6 +274,8 @@ func runGithubHistoryReport(username, repo, filePath string, latest bool, limit
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan,
false, limit, base, remote)
if errs != nil {
model.SendProgressError("git", errors.Join(errs...).Error(), errorChan)
close(progressChan)
return nil, errs
}

Expand Down
1 change: 1 addition & 0 deletions cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ func runGitHistorySummary(gitPath, filePath string, latest bool,
commitHistory, errs := git.ExtractHistoryFromFile(gitPath, filePath, updateChan, errorChan)
if errs != nil {
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(errs)), errorChan)
close(updateChan)
return errs[0]
}

Expand Down

0 comments on commit 44e0ea2

Please sign in to comment.