Skip to content

Commit

Permalink
Adding ORM support
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Feb 11, 2023
1 parent 531523a commit 612c815
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
22 changes: 11 additions & 11 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func GetHTMLReportCommand() *cobra.Command {
<-doneChan
return err
}
report, er := RunGithubHistoryHTMLReport(user, repo, filePath, latestFlag, cdnFlag, updateChan, errorChan)
report, _, er := RunGithubHistoryHTMLReport(user, repo, filePath, latestFlag, cdnFlag, updateChan, errorChan)

// wait for things to be completed.
<-doneChan
Expand Down Expand Up @@ -150,7 +150,7 @@ func GetHTMLReportCommand() *cobra.Command {
}
go listenForUpdates(updateChan, errorChan)

report, er := RunGitHistoryHTMLReport(args[0], args[1], latestFlag, cdnFlag, updateChan, errorChan)
report, _, er := RunGitHistoryHTMLReport(args[0], args[1], latestFlag, cdnFlag, updateChan, errorChan)
<-doneChan
if er != nil {
for x := range er {
Expand Down Expand Up @@ -210,24 +210,24 @@ func ExtractGithubDetailsFromURL(url *url.URL) (string, string, string, error) {
}

func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]byte, []error) {
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]byte, []*model.Report, []error) {
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("reading paths",
err.Error(), errorChan)
return nil, []error{err}
return nil, nil, []error{err}
}

// build commit history.
commitHistory, err := git.ExtractHistoryFromFile(gitPath, filePath, progressChan, errorChan)
if err != nil {
return nil, err
return nil, nil, err
}

// populate history with changes and data
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, progressChan, errorChan)
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, progressChan, errorChan)
if err != nil {
return nil, err
return nil, nil, err
}

if latest {
Expand All @@ -247,19 +247,19 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
close(progressChan)

generator := html_report.NewHTMLReport(false, time.Now(), commitHistory)
return generator.GenerateReport(false, useCDN), nil
return generator.GenerateReport(false, useCDN), reports, nil
}

func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]byte, []error) {
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]byte, []*model.Report, []error) {

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true)

if errs != nil {
for x := range errs {
if _, ok := errs[x].(*resolver.ResolvingError); !ok {
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(errs)), errorChan)
return nil, errs
return nil, nil, errs
}
}
}
Expand All @@ -281,7 +281,7 @@ func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN
generator := html_report.NewHTMLReport(false, time.Now(), commitHistory)

close(progressChan)
return generator.GenerateReport(false, useCDN), nil
return generator.GenerateReport(false, useCDN), reports, nil
}

func RunLeftRightHTMLReport(left, right string, useCDN bool) ([]byte, []error) {
Expand Down
28 changes: 16 additions & 12 deletions model/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ import (
)

type Commit struct {
Hash string `json:"commitHash"`
Message string `json:"message"`
Author string `json:"author"`
AuthorEmail string `json:"authorEmail"`
CommitDate time.Time `json:"committed"`
Changes *model.DocumentChanges `json:"changeReport"`
Data []byte `json:"-"`
OldData []byte `json:"-"`
Document libopenapi.Document `json:"-"`
OldDocument libopenapi.Document `json:"-"`
RepoDirectory string `json:"-"`
FilePath string `json:"-"`
CreatedAt time.Time
UpdatedAt time.Time
ID uint `gorm:"primaryKey" json:"-"`
Hash string `json:"commitHash"`
Message string `json:"message"`
Author string `json:"author"`
AuthorEmail string `gorm:"index" json:"authorEmail"`
CommitDate time.Time `json:"committed"`
Changes *model.DocumentChanges `gorm:"-" json:"changeReport"`
SerializedChanges []byte `gorm:"-" json:"-"`
Data []byte `gorm:"-" json:"-"`
OldData []byte `gorm:"-" json:"-"`
Document libopenapi.Document `gorm:"-" json:"-"`
OldDocument libopenapi.Document `gorm:"-" json:"-"`
RepoDirectory string `gorm:"-" json:"-"`
FilePath string `gorm:"-" json:"-"`
}
17 changes: 12 additions & 5 deletions model/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@

package model

import "github.com/pb33f/libopenapi/what-changed/reports"
import (
"github.com/pb33f/libopenapi/what-changed/reports"
"time"
)

type Report struct {
Summary map[string]*reports.Changed `json:"reportSummary"`
Commit *Commit `json:"commitDetails"`
ID uint `gorm:"primaryKey" json:"-"`
Summary map[string]*reports.Changed `gorm:"-" json:"reportSummary"`
CreatedAt time.Time
UpdatedAt time.Time
Commit *Commit `gorm:"foreignKey:ID" json:"commitDetails"`
}

type HistoricalReport struct {
GitRepoPath string `json:"gitRepoPath"`
ID uint `gorm:"primaryKey" json:"-"`
GitRepoPath string `gorm:"index" json:"gitRepoPath"`
GitFilePath string `json:"gitFilePath"`
Filename string `json:"filename"`
DateGenerated string `json:"dateGenerated"`
Reports []*Report `json:"reports"`
Reports []*Report `gorm:"foreignKey:ID" json:"reports" `
}

0 comments on commit 612c815

Please sign in to comment.