Skip to content

Commit

Permalink
working through consumability tuneups.
Browse files Browse the repository at this point in the history
  • Loading branch information
daveshanley committed Feb 11, 2023
1 parent edb4f05 commit dbd0198
Show file tree
Hide file tree
Showing 24 changed files with 209 additions and 105 deletions.
2 changes: 1 addition & 1 deletion cmd/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func GetConsoleCommand() *cobra.Command {
func runGithubHistoryConsole(username, repo, filePath string, latest bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) ([]*model.Commit, []error) {

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

if errs != nil {
return nil, errs
Expand Down
47 changes: 30 additions & 17 deletions cmd/html_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ func GetHTMLReportCommand() *cobra.Command {
return
}
case err := <-errorChan:
failed = true
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
pterm.Println()
pterm.Println()
doneChan <- true
return
//failed = true
if err.Fatal {
spinner.Fail(fmt.Sprintf("Stopped: %s", err.Message))
doneChan <- true
return
} else {
pterm.Warning.Println(err.Message)
}
}
}
}
Expand All @@ -104,15 +106,15 @@ 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, 3)

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

if err != nil {
if len(report) <= 0 && er != nil {
return er[0]
}
if !failed {
if len(report) > 0 {
err = os.WriteFile("report.html", report, 0664)
if err != nil {
pterm.Error.Println(err.Error())
Expand Down Expand Up @@ -247,19 +249,20 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
close(progressChan)

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

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

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

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, nil, errs
if e, ok := errs[x].(*resolver.ResolvingError); !ok {
model.SendProgressError("git", fmt.Sprintf("resolving error: %s", e.Error()), errorChan)
} else {
model.SendProgressError("git", fmt.Sprintf("parsing error: %s", e.Error()), errorChan)
}
}
}
Expand All @@ -278,10 +281,20 @@ func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN
model.SendProgressUpdate("extraction",
fmt.Sprintf("extracted %d reports from history", len(reports)), true, progressChan)

// if there are no reports and no commits, return no bytes.
if len(reports) == 0 && len(commitHistory) == 0 {

model.SendProgressError("extraction",
fmt.Sprintf("history extraction failed %d reports generated for '%s'", len(reports), filePath), errorChan)

close(progressChan)
return nil, nil, append(errs, fmt.Errorf("no repors extracted, no history found for file '%s'", filePath))
}

generator := html_report.NewHTMLReport(false, time.Now(), commitHistory)

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

func RunLeftRightHTMLReport(left, right string, useCDN bool) ([]byte, []error) {
Expand Down Expand Up @@ -319,5 +332,5 @@ func RunLeftRightHTMLReport(left, right string, useCDN bool) ([]byte, []error) {
return nil, errs
}
generator := html_report.NewHTMLReport(false, time.Now(), commits)
return generator.GenerateReport(false, useCDN), nil
return generator.GenerateReport(false, useCDN, false), nil
}
2 changes: 1 addition & 1 deletion cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
func runGithubHistoryReport(username, repo, filePath string, latest bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) (*model.HistoricalReport, []error) {

commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, false)
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, false,3)
if errs != nil {
return nil, errs
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func runLeftRightSummary(left, right string) []error {

func runGithubHistorySummary(username, repo, filePath string, latest bool,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError) error {
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, false)
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, false,3)
if errs != nil {
return errs[0]
}
Expand Down
17 changes: 13 additions & 4 deletions git/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type APIFile struct {

func GetCommitsForGithubFile(user, repo, path string,
progressChan chan *model.ProgressUpdate, progressErrorChan chan model.ProgressError,
forceCutoff bool) ([]*APICommit, error) {
forceCutoff bool, limit int) ([]*APICommit, error) {

// we can make a lot of http calls, very quickly - so ensure we give the client enough
// breathing space to cope with lots of TLS handshakes.
Expand Down Expand Up @@ -196,12 +196,21 @@ func GetCommitsForGithubFile(user, repo, path string,
errChan := make(chan error)

totalCommits := len(commits)

if limit > 0 && totalCommits > limit {
totalCommits = limit + 1
}
completedCommits := 0

b := 0
for x := range commits {
model.SendProgressUpdate(fmt.Sprintf("commit: %s", commits[x].Hash),
fmt.Sprintf("commit %s being fetched", commits[x].Hash), false, progressChan)
go extractFilesFromCommit(user, repo, path, commits[x], sigChan, errChan)
b++
if limit > 0 && b > limit {
break
}
}

for completedCommits < totalCommits {
Expand Down Expand Up @@ -259,23 +268,23 @@ func ConvertGithubCommitsIntoModel(ghCommits []*APICommit,
model.SendProgressUpdate("converting commits",
fmt.Sprintf("%d commits normalized", len(normalized)), true, progressChan)
} else {
model.SendProgressError("converting commits", "no commits were normalized! Check URL", progressErrorChan)
model.SendFatalError("converting commits", "no commits were normalized! Check URL", progressErrorChan)
}
}
return normalized, errs
}

func ProcessGithubRepo(username string, repo string, filePath string,
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError,
forceCutoff bool) ([]*model.Commit, []error) {
forceCutoff bool, limit int) ([]*model.Commit, []error) {

if username == "" || repo == "" || filePath == "" {
err := errors.New("please supply valid github username/repo and filepath")
model.SendProgressError("git", err.Error(), errorChan)
return nil, []error{err}
}

githubCommits, err := GetCommitsForGithubFile(username, repo, filePath, progressChan, errorChan, forceCutoff)
githubCommits, err := GetCommitsForGithubFile(username, repo, filePath, progressChan, errorChan, forceCutoff, limit)

if err != nil {
return nil, []error{err}
Expand Down
26 changes: 14 additions & 12 deletions html-report/build_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ var header string
//go:embed ui/build/static/bundle.js
var bundledJS string

//go:embed ui/build/static/main.css
//go:embed ui/build/static/bundle.css
var bundledCSS string

type HTMLReportGenerator interface {
GetHTMLReport() *model.HTMLReport
GenerateReport(testMode, useCDN bool) []byte
GenerateReport(testMode, useCDN, embeddedMode bool) []byte
}

type ReportData struct {
Expand All @@ -42,6 +42,7 @@ type ReportData struct {
ReportData *model.HTMLReport `json:"-"`
Generated time.Time `json:"generated"`
DisableTimestamp bool `json:"-"`
EmbeddedMode bool `json:"-"`
}

type htmlReport struct {
Expand Down Expand Up @@ -120,7 +121,7 @@ func (html *htmlReport) GetHTMLReport() *model.HTMLReport {
return html.model
}

func (html *htmlReport) GenerateReport(test, useCDN bool) []byte {
func (html *htmlReport) GenerateReport(test, useCDN, embedded bool) []byte {

templateFuncs := template.FuncMap{
"renderJSON": func(data interface{}) string {
Expand All @@ -140,15 +141,16 @@ func (html *htmlReport) GenerateReport(test, useCDN bool) []byte {
data, _ := json.Marshal(html.model)

reportData := &ReportData{
BundledJS: bundledJS,
BundledCSS: bundledCSS,
JsCDN: "https://pb33f.github.io/openapi-changes/html-report/ui/build/static/bundle.js",
CssCDN: "https://pb33f.github.io/openapi-changes/html-report/ui/build/static/main.css",
Report: string(data),
ReportData: html.model,
Generated: time.Now(),
TestMode: test,
UseCDN: useCDN,
BundledJS: bundledJS,
BundledCSS: bundledCSS,
JsCDN: "https://pb33f.github.io/openapi-changes/html-report/ui/build/static/bundle.js",
CssCDN: "https://pb33f.github.io/openapi-changes/html-report/ui/build/static/main.css",
Report: string(data),
ReportData: html.model,
Generated: time.Now(),
TestMode: test,
UseCDN: useCDN,
EmbeddedMode: embedded,
}
if html.disableTimestamp {
reportData.DisableTimestamp = true
Expand Down
24 changes: 12 additions & 12 deletions html-report/templates/header.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@
}
.ellipsis div:nth-child(1) {
left: 8px;
animation: lds-ellipsis1 0.6s infinite;
animation: ellipsis1 0.6s infinite;
}
.ellipsis div:nth-child(2) {
left: 8px;
animation: lds-ellipsis2 0.6s infinite;
animation: ellipsis2 0.6s infinite;
}
.ellipsis div:nth-child(3) {
left: 32px;
animation: lds-ellipsis2 0.6s infinite;
animation: ellipsis2 0.6s infinite;
}
.ellipsis div:nth-child(4) {
left: 56px;
animation: lds-ellipsis3 0.6s infinite;
animation: ellipsis3 0.6s infinite;
}
@keyframes ellipsis1 {
0% {
Expand All @@ -82,17 +82,17 @@
transform: translate(24px, 0);
}
}

{{- if not .UseCDN -}}
{{ .BundledCSS }}
{{- if not .TestMode -}}
{{- if not .UseCDN -}}
{{ .BundledCSS }}
{{- end -}}
{{- end -}}
</style>
</style>
{{- if .TestMode -}}
<link rel="stylesheet" href="http://localhost:3000/bundle.css"/>
{{- end -}}
{{- if .UseCDN }}
<link rel="stylesheet" href="{{- .CssCDN -}}"/>
{{- end }}
<script>
let rawData = {{ .Report }}
window.data = JSON.parse(JSON.stringify(rawData));
</script>
</head>
{{ end }}
33 changes: 21 additions & 12 deletions html-report/templates/report.gohtml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
<!DOCTYPE html>
<html lang="en">
{{- template "header" . -}}
<body>
<div id="root">
<div class="preloader">
<div class="ellipsis">
<div></div><div></div><div></div><div></div></div><br/>
OpenAPI Changes report is loading...
</div>
</div>
</body>
<body {{ if .EmbeddedMode }}data-embedded="true"{{ end }}>
<div class="preloader" id="preloader">
<div class="ellipsis">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<br/>
OpenAPI Changes report is loading...
</div>
<div id="root">
</div>
</body>
<script>
let rawData = {{ .Report }};
window.data = JSON.parse(JSON.stringify(rawData));
</script>
{{- if not .TestMode -}}
{{- if not .UseCDN -}}
<script>
{{ .BundledJS }}
</script>
<script>
{{ .BundledJS }}
</script>
{{- else -}}
<script src="{{- .JsCDN -}}" async></script>
{{- end -}}
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion html-report/ui/build/static/bundle.js

Large diffs are not rendered by default.

24 changes: 23 additions & 1 deletion html-report/ui/src/OpenAPIChanges.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
width: calc(100vw - 50px);
}

body[data-embedded] #main_container {
width: 100vw;
}


hr {
border: none;
border-bottom: 1px dashed var(--secondary-color);
}

body[data-embedded] hr {
margin-block-end: 0;
margin-block-start: 0;
}


.height-100 {
height: 100px;
}
Expand Down Expand Up @@ -90,6 +99,13 @@ hr {
width: 100%
}

body[data-embedded] section.report-header > header {
padding-left: 10px;
padding-right: 10px;
padding-top: 10px;
height: 40px;
}


.breaking-change {
color: var(--error-color)
Expand Down Expand Up @@ -124,6 +140,9 @@ hr {
vertical-align: middle;
}

.ant-tabs >.ant-tabs-nav {
margin-bottom: 0!important;
}

.ant-tabs-tab {
border-radius: 0px!important;
Expand All @@ -141,11 +160,14 @@ hr {
border-bottom: 1px dashed var(--secondary-color)!important;
}


footer {
font-size: 0.6em;
}

body[data-embedded] footer {
display: none;
}


@media only screen and (max-width: 1000px) {

Expand Down
Loading

0 comments on commit dbd0198

Please sign in to comment.