From f6c6568bb5ecc6f6c87c2163024d0c47abe7ee3f Mon Sep 17 00:00:00 2001 From: quobix Date: Sat, 14 Mar 2026 08:20:48 -0400 Subject: [PATCH 1/2] Addressing comments from phil sturgeon argument issues and initial commit explosions cleaned up. --- cmd/console.go | 25 ++++++++++++++++++--- cmd/html_report.go | 11 ++++++++-- cmd/markdown_report.go | 11 ++++++++-- cmd/report.go | 13 ++++++++--- cmd/summary.go | 22 ++++++++++++++----- git/read_local.go | 5 ++++- git/read_local_test.go | 50 ++++++++++++------------------------------ go.mod | 7 +++--- go.sum | 14 +++++++----- 9 files changed, 97 insertions(+), 61 deletions(-) diff --git a/cmd/console.go b/cmd/console.go index 07b1179..ecd2c03 100644 --- a/cmd/console.go +++ b/cmd/console.go @@ -177,6 +177,11 @@ func GetConsoleCommand() *cobra.Command { panic(er) } + return nil + } else { + pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.") + pterm.Println() + PrintHowToUse("console") return nil } @@ -231,6 +236,11 @@ func GetConsoleCommand() *cobra.Command { return errs[0] } + if len(commits) == 0 { + pterm.Warning.Println("The file has no prior version to compare against — nothing to display") + return nil + } + // boot. app := tui.BuildApplication(commits, Version) if app == nil { @@ -274,7 +284,9 @@ func GetConsoleCommand() *cobra.Command { return nil } } - pterm.Error.Println("too many arguments, expecting two (2)") + pterm.Error.Println("Too many arguments provided, expecting two (2)") + pterm.Println() + PrintHowToUse("console") return nil }, } @@ -345,9 +357,16 @@ func runGitHistoryConsole(gitPath, filePath, baseCommit string, latest bool, glo } // populate history with changes and data - git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig) + commitHistory, _ = git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig) + + if len(commitHistory) == 0 { + model.SendProgressUpdate("extraction", + "no comparable changes found in history", true, updateChan) + close(updateChan) + return nil, nil + } - if latest { + if latest && len(commitHistory) > 0 { commitHistory = commitHistory[:1] } diff --git a/cmd/html_report.go b/cmd/html_report.go index efa27c4..e6086df 100644 --- a/cmd/html_report.go +++ b/cmd/html_report.go @@ -190,6 +190,11 @@ func GetHTMLReportCommand() *cobra.Command { return er[0] } return writeReportFile(reportFile, report) + } else { + pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.") + pterm.Println() + PrintHowToUse("html-report") + return nil } } else { @@ -274,7 +279,9 @@ func GetHTMLReportCommand() *cobra.Command { return writeReportFile(reportFile, report) } } - pterm.Error.Println("wrong number of arguments, expecting two (2)") + pterm.Error.Println("Too many arguments provided, expecting two (2)") + pterm.Println() + PrintHowToUse("html-report") return nil }, } @@ -341,7 +348,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath, baseCommit string, latest, useCD return nil, nil, err } - if latest { + if latest && len(commitHistory) > 0 { commitHistory = commitHistory[:1] } diff --git a/cmd/markdown_report.go b/cmd/markdown_report.go index be242d4..ea4a98f 100644 --- a/cmd/markdown_report.go +++ b/cmd/markdown_report.go @@ -190,6 +190,11 @@ func GetMarkdownReportCommand() *cobra.Command { return er[0] } return writeReportFile(reportFile, report) + } else { + pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.") + pterm.Println() + PrintHowToUse("markdown-report") + return nil } } else { @@ -274,7 +279,9 @@ func GetMarkdownReportCommand() *cobra.Command { return writeReportFile(reportFile, report) } } - pterm.Error.Println("wrong number of arguments, expecting two (2)") + pterm.Error.Println("Too many arguments provided, expecting two (2)") + pterm.Println() + PrintHowToUse("markdown-report") return nil }, } @@ -315,7 +322,7 @@ func RunGitHistoryMarkdownReport(gitPath, filePath, baseCommit string, latest, u return nil, nil, err } - if latest { + if latest && len(commitHistory) > 0 { commitHistory = commitHistory[:1] } diff --git a/cmd/report.go b/cmd/report.go index 301af6c..9a64ece 100644 --- a/cmd/report.go +++ b/cmd/report.go @@ -126,6 +126,11 @@ func GetReportCommand() *cobra.Command { jsonBytes, _ := json.MarshalIndent(flat, "", " ") fmt.Println(string(jsonBytes)) return nil + } else { + pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.") + pterm.Println() + PrintHowToUse("report") + return nil } } else { @@ -231,7 +236,9 @@ func GetReportCommand() *cobra.Command { return nil } } - pterm.Error.Println("wrong number of arguments, expecting two (2)") + pterm.Error.Println("Too many arguments provided, expecting two (2)") + pterm.Println() + PrintHowToUse("report") return nil }, } @@ -271,7 +278,7 @@ func runGitHistoryReport(gitPath, filePath, baseCommit string, latest bool, return nil, err } - if latest { + if latest && len(commitHistory) > 0 { commitHistory = commitHistory[:1] } @@ -309,7 +316,7 @@ func runGithubHistoryReport(username, repo, filePath, baseCommit string, latest return nil, errs } - if latest { + if latest && len(commitHistory) > 1 { commitHistory = commitHistory[:1] } diff --git a/cmd/summary.go b/cmd/summary.go index f4c0c14..09b2e02 100644 --- a/cmd/summary.go +++ b/cmd/summary.go @@ -201,7 +201,7 @@ func GetSummaryCommand() *cobra.Command { } return nil } else { - pterm.Error.Println("When using a single argument (URL), only github.com is supported at this time. Please provide a github url") + pterm.Error.Println("A single argument requires a github.com URL. For local comparison, provide two arguments: a git repository path and a file path within it.") return nil } @@ -286,7 +286,7 @@ func GetSummaryCommand() *cobra.Command { return nil } } - pterm.Error.Println("Invalid arguments") + pterm.Error.Println("Too many arguments provided, expecting two (2)") pterm.Println() PrintHowToUse("summary") return nil @@ -404,7 +404,7 @@ func runGithubHistorySummary(username, repo, filePath, baseCommit string, latest commitHistory, _ := git.ProcessGithubRepo(username, repo, filePath, baseCommit, progressChan, errorChan, false, limit, limitTime, base, remote, extRefs, breakingConfig) - if latest { + if latest && len(commitHistory) > 1 { commitHistory = commitHistory[:1] } @@ -441,9 +441,17 @@ func runGitHistorySummary(gitPath, filePath, baseCommit string, latest bool, } // populate history with changes and data - git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig) + commitHistory, _ = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs, breakingConfig) - if latest { + if len(commitHistory) == 0 { + model.SendProgressUpdate("extraction", + "no comparable changes found in history", true, updateChan) + close(updateChan) + pterm.Warning.Println("The file has no prior version to compare against — nothing to report") + return nil + } + + if latest && len(commitHistory) > 0 { commitHistory = commitHistory[:1] } @@ -461,6 +469,10 @@ func printSummaryDetails(commitHistory []*model.Commit, markdown, errOnDiff bool pterm.Println() errorStyle := pterm.NewStyle(pterm.FgLightRed, pterm.Italic) + if len(commitHistory) == 0 { + pterm.Info.Println("Nothing to report") + return nil + } if len(commitHistory) == 1 && commitHistory[0].Changes == nil { pterm.Success.Println("No changes found between specifications") return nil diff --git a/git/read_local.go b/git/read_local.go index 5046012..9c3d932 100644 --- a/git/read_local.go +++ b/git/read_local.go @@ -287,6 +287,9 @@ func BuildCommitChangelog(commitHistory []*model.Commit, } } if len(oldBits) == 0 && len(newBits) > 0 { + model.SendProgressWarning("building models", + fmt.Sprintf("Commit %s is the first version of '%s' — no prior version to compare against, skipping", + commitHistory[c].Hash, commitHistory[c].FilePath), progressChan) newDoc, err = libopenapi.NewDocumentWithConfiguration(newBits, docConfig) if err != nil { model.SendFatalError("building models", fmt.Sprintf("unable to create OpenAPI modified document: %s", err.Error()), errorChan) @@ -300,7 +303,7 @@ func BuildCommitChangelog(commitHistory []*model.Commit, if oldDoc != nil { commitHistory[c].OldDocument = oldDoc } - if (c == len(commitHistory)-1) || commitHistory[c].Changes != nil { + if commitHistory[c].Changes != nil { cleaned = append(cleaned, commitHistory[c]) } } diff --git a/git/read_local_test.go b/git/read_local_test.go index 7c87d07..fa7f0dd 100644 --- a/git/read_local_test.go +++ b/git/read_local_test.go @@ -4,12 +4,11 @@ package git import ( - "context" "testing" - "time" "github.com/pb33f/openapi-changes/model" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCheckLocalRepoAvailable(t *testing.T) { @@ -18,40 +17,19 @@ func TestCheckLocalRepoAvailable(t *testing.T) { } func TestExtractHistoryFromFile(t *testing.T) { - - c := make(chan *model.ProgressUpdate) - e := make(chan model.ProgressError) - d := make(chan bool) - go func() { - iterations := 0 - for iterations < 26 { - select { - case <-c: - - iterations++ - case <-e: - - iterations++ - } - } - d <- true - }() - - // this shit times out in the pipeline (damn you github runners) - ctx, cncl := context.WithTimeout(context.Background(), 5*time.Second) - history, _ := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1) - defer cncl() - - select { - - case <-d: - assert.NotNil(t, history) - assert.Equal(t, "A lot of clean up, after consuming the tool as a library.", history[len(history)-1].Message) - return - case <-ctx.Done(): - return - } - + c := make(chan *model.ProgressUpdate, 32) + e := make(chan model.ProgressError, 32) + + history, errs := ExtractHistoryFromFile("./", "read_local.go", "", c, e, false, 25, -1) + require.Empty(t, errs) + require.NotEmpty(t, history) + + oldest := history[len(history)-1] + assert.Equal(t, "./", oldest.RepoDirectory) + assert.Equal(t, "read_local.go", oldest.FilePath) + assert.NotEmpty(t, oldest.Hash) + assert.NotEmpty(t, oldest.Message) + assert.False(t, oldest.CommitDate.IsZero()) } func TestExtractHistoryFromFile_Fail(t *testing.T) { diff --git a/go.mod b/go.mod index 2dc9e9e..4337b7b 100644 --- a/go.mod +++ b/go.mod @@ -6,13 +6,13 @@ require ( github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/gdamore/tcell/v2 v2.13.4 github.com/google/uuid v1.6.0 - github.com/pb33f/libopenapi v0.30.0 + github.com/pb33f/libopenapi v0.34.2 github.com/pmezard/go-difflib v1.0.0 github.com/pterm/pterm v0.12.82 github.com/rivo/tview v0.42.0 github.com/spf13/cobra v1.10.2 github.com/stretchr/testify v1.11.1 - go.yaml.in/yaml/v4 v4.0.0-rc.3 + go.yaml.in/yaml/v4 v4.0.0-rc.4 golang.org/x/text v0.32.0 ) @@ -30,12 +30,13 @@ require ( github.com/lithammer/fuzzysearch v1.1.8 // indirect github.com/lucasb-eyer/go-colorful v1.3.0 // indirect github.com/mattn/go-runewidth v0.0.16 // indirect - github.com/pb33f/jsonpath v0.7.0 // indirect + github.com/pb33f/jsonpath v0.8.1 // indirect github.com/pb33f/ordered-map/v2 v2.3.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/spf13/pflag v1.0.9 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 // indirect + golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.38.0 // indirect golang.org/x/term v0.37.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 22b2e22..bddf33c 100644 --- a/go.sum +++ b/go.sum @@ -62,10 +62,10 @@ github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRC github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= -github.com/pb33f/jsonpath v0.7.0 h1:3oG6yu1RqNoMZpqnRjBMqi8fSIXWoDAKDrsB0QGTcoU= -github.com/pb33f/jsonpath v0.7.0/go.mod h1:/+JlSIjWA2ijMVYGJ3IQPF4Q1nLMYbUTYNdk0exCDPQ= -github.com/pb33f/libopenapi v0.30.0 h1:F5VmLZH/pJ7Cybe48Ya/5CA3TWE6XusR4KxrlrHA4R8= -github.com/pb33f/libopenapi v0.30.0/go.mod h1:4MP76dnaTMY+DM+bRhKBneAIhVISEEZM6G6sd7A9pus= +github.com/pb33f/jsonpath v0.8.1 h1:84C6QRyx6HcSm6PZnsMpcqYot3IsZ+m0n95+0NbBbvs= +github.com/pb33f/jsonpath v0.8.1/go.mod h1:zBV5LJW4OQOPatmQE2QdKpGQJvhDTlE5IEj6ASaRNTo= +github.com/pb33f/libopenapi v0.34.2 h1:ValgPCDIVSC1IzPY7rY6GPOslCzaAWEml40IuFGZXOc= +github.com/pb33f/libopenapi v0.34.2/go.mod h1:YOP20KzYe3mhE5301aQzJtzQ9MnvhABBGO7RMttA4V4= github.com/pb33f/ordered-map/v2 v2.3.0 h1:k2OhVEQkhTCQMhAicQ3Z6iInzoZNQ7L9MVomwKBZ5WQ= github.com/pb33f/ordered-map/v2 v2.3.0/go.mod h1:oe5ue+6ZNhy7QN9cPZvPA23Hx0vMHnNVeMg4fGdCANw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -106,8 +106,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= -go.yaml.in/yaml/v4 v4.0.0-rc.3 h1:3h1fjsh1CTAPjW7q/EMe+C8shx5d8ctzZTrLcs/j8Go= -go.yaml.in/yaml/v4 v4.0.0-rc.3/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= +go.yaml.in/yaml/v4 v4.0.0-rc.4 h1:UP4+v6fFrBIb1l934bDl//mmnoIZEDK0idg1+AIvX5U= +go.yaml.in/yaml/v4 v4.0.0-rc.4/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20241004190924-225e2abe05e6 h1:1wqE9dj9NpSm04INVsJhhEUzhuDVjbcyKH91sVyPATw= @@ -121,6 +121,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= +golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= From e62ccaf412eacaf62fdcb3907eb038c5a97a35c4 Mon Sep 17 00:00:00 2001 From: quobix Date: Sat, 14 Mar 2026 08:59:08 -0400 Subject: [PATCH 2/2] Updated deps and introduced a proxy --- .goreleaser.yaml | 4 +--- npm-install/postinstall.js | 21 +++++++++++++++++++-- package.json | 6 +++--- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 487bcfa..7022f2a 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -13,9 +13,7 @@ builds: goarch: - amd64 - arm64 - ignore: - - goos: windows - goarch: arm64 + - "386" archives: - name_template: >- {{ .ProjectName }}_ diff --git a/npm-install/postinstall.js b/npm-install/postinstall.js index d3d82d2..da6c615 100644 --- a/npm-install/postinstall.js +++ b/npm-install/postinstall.js @@ -1,12 +1,22 @@ import { createWriteStream } from "fs"; import * as fs from "fs/promises"; import fetch from "node-fetch"; +import { HttpsProxyAgent } from "https-proxy-agent"; import { pipeline } from "stream/promises"; -import tar from "tar"; +import * as tar from "tar"; import { execSync } from "child_process"; import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js"; +// Get proxy URL from environment variables (standard convention) +function getProxyUrl() { + return process.env.HTTPS_PROXY || + process.env.https_proxy || + process.env.HTTP_PROXY || + process.env.http_proxy || + null; +} + async function install() { if (process.platform === "android") { console.log("Installing, may take a moment..."); @@ -32,9 +42,16 @@ async function install() { url = url.replace(/{{version}}/g, version); url = url.replace(/{{bin_name}}/g, binName); + // Configure fetch options with proxy support + const fetchOptions = {}; + const proxyUrl = getProxyUrl(); + if (proxyUrl) { + console.log('Using proxy:', proxyUrl); + fetchOptions.agent = new HttpsProxyAgent(proxyUrl); + } console.log('fetching from URL', url) - const response = await fetch(url); + const response = await fetch(url, fetchOptions); if (!response.ok) { throw new Error("Failed fetching the binary: " + response.statusText); } diff --git a/package.json b/package.json index 8b26057..c1791f1 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "npm-install" ], "dependencies": { - "adm-zip": "^0.5.10", - "node-fetch": "^3.2.10", - "tar": "^6.1.11" + "https-proxy-agent": "^7.0.6", + "node-fetch": "^3.3.2", + "tar": "^7.5.11" }, "bugs": { "url": "https://github.com/pb33f/openapi-changes/issues"