Skip to content

Commit a894170

Browse files
committed
Addressed #186
added `—ext-refs` flag
1 parent 9492f7a commit a894170

9 files changed

+58
-47
lines changed

.github/workflows/publish.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/setup-go@v3
2020
id: go
2121
with:
22-
go-version: ^1.23
22+
go-version: ^1.24
2323

2424
- name: Run GoReleaser
2525
uses: goreleaser/goreleaser-action@v3

cmd/console.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func GetConsoleCommand() *cobra.Command {
4242
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
4343
baseFlag, _ := cmd.Flags().GetString("base")
4444
remoteFlag, _ := cmd.Flags().GetBool("remote")
45+
extRefs, _ := cmd.Flags().GetBool("ext-refs")
4546

4647
noBanner, _ := cmd.Flags().GetBool("no-logo")
4748
if !noBanner {
@@ -146,7 +147,7 @@ func GetConsoleCommand() *cobra.Command {
146147
return err
147148
}
148149
commits, e := runGithubHistoryConsole(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
149-
errorChan, baseFlag, remoteFlag)
150+
errorChan, baseFlag, remoteFlag, extRefs)
150151

151152
// wait for things to be completed.
152153
<-doneChan
@@ -211,7 +212,7 @@ func GetConsoleCommand() *cobra.Command {
211212
go listenForUpdates(updateChan, errorChan)
212213

213214
commits, errs := runGitHistoryConsole(args[0], args[1], latestFlag, globalRevisionsFlag, limitFlag, limitTimeFlag,
214-
updateChan, errorChan, baseFlag, remoteFlag)
215+
updateChan, errorChan, baseFlag, remoteFlag, extRefs)
215216

216217
// wait.
217218
<-doneChan
@@ -251,7 +252,7 @@ func GetConsoleCommand() *cobra.Command {
251252
return urlErr
252253
}
253254

254-
errs := runLeftRightCompare(left, right, updateChan, errorChan, baseFlag, remoteFlag)
255+
errs := runLeftRightCompare(left, right, updateChan, errorChan, baseFlag, remoteFlag, extRefs)
255256
// wait.
256257
<-doneChan
257258
if len(errs) > 0 {
@@ -271,10 +272,11 @@ func GetConsoleCommand() *cobra.Command {
271272
return cmd
272273
}
273274

275+
// TODO: we have got to clean up these methods and replace with a message based design.
274276
func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit int, limitTime int,
275-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]*model.Commit, []error) {
277+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) ([]*model.Commit, []error) {
276278

277-
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote)
279+
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote, extRefs)
278280

279281
if latest && len(commitHistory) > 1 {
280282
commitHistory = commitHistory[:1]
@@ -307,7 +309,7 @@ func runGithubHistoryConsole(username, repo, filePath string, latest bool, limit
307309
}
308310

309311
func runGitHistoryConsole(gitPath, filePath string, latest bool, globalRevisions bool, limit int, limitTime int,
310-
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]*model.Commit, []error) {
312+
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) ([]*model.Commit, []error) {
311313

312314
if gitPath == "" || filePath == "" {
313315
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
@@ -329,7 +331,7 @@ func runGitHistoryConsole(gitPath, filePath string, latest bool, globalRevisions
329331
}
330332

331333
// populate history with changes and data
332-
git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote)
334+
git.PopulateHistoryWithChanges(commitHistory, limit, limitTime, updateChan, errorChan, base, remote, extRefs)
333335

334336
if latest {
335337
commitHistory = commitHistory[:1]
@@ -344,7 +346,7 @@ func runGitHistoryConsole(gitPath, filePath string, latest bool, globalRevisions
344346
}
345347

346348
func runLeftRightCompare(left, right string, updateChan chan *model.ProgressUpdate,
347-
errorChan chan model.ProgressError, base string, remote bool) []error {
349+
errorChan chan model.ProgressError, base string, remote, extRefs bool) []error {
348350

349351
var leftBytes, rightBytes []byte
350352
var errs []error
@@ -380,7 +382,7 @@ func runLeftRightCompare(left, right string, updateChan chan *model.ProgressUpda
380382
},
381383
}
382384

383-
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote)
385+
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote, extRefs)
384386
if len(errs) > 0 {
385387
return errs
386388
}

cmd/html_report.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func GetHTMLReportCommand() *cobra.Command {
4747
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
4848
remoteFlag, _ := cmd.Flags().GetBool("remote")
4949
reportFile, _ := cmd.Flags().GetString("report-file")
50+
extRefs, _ := cmd.Flags().GetBool("ext-refs")
5051

5152
if noColorFlag {
5253
pterm.DisableStyling()
@@ -171,7 +172,7 @@ func GetHTMLReportCommand() *cobra.Command {
171172
return err
172173
}
173174
report, _, er := RunGithubHistoryHTMLReport(user, repo, filePath, latestFlag, cdnFlag,
174-
false, updateChan, errorChan, limitFlag, limitTimeFlag, baseFlag, remoteFlag)
175+
false, updateChan, errorChan, limitFlag, limitTimeFlag, baseFlag, remoteFlag, extRefs)
175176

176177
// wait for things to be completed.
177178
<-doneChan
@@ -233,7 +234,7 @@ func GetHTMLReportCommand() *cobra.Command {
233234
go listenForUpdates(updateChan, errorChan)
234235

235236
report, _, er := RunGitHistoryHTMLReport(args[0], args[1], latestFlag, cdnFlag,
236-
updateChan, errorChan, baseFlag, remoteFlag, globalRevisionsFlag, limitFlag, limitTimeFlag)
237+
updateChan, errorChan, baseFlag, remoteFlag, extRefs, globalRevisionsFlag, limitFlag, limitTimeFlag)
237238
<-doneChan
238239
if er != nil {
239240
for x := range er {
@@ -269,7 +270,7 @@ func GetHTMLReportCommand() *cobra.Command {
269270
return urlErr
270271
}
271272

272-
report, errs := RunLeftRightHTMLReport(left, right, cdnFlag, updateChan, errorChan, baseFlag, remoteFlag)
273+
report, errs := RunLeftRightHTMLReport(left, right, cdnFlag, updateChan, errorChan, baseFlag, remoteFlag, extRefs)
273274
<-doneChan
274275
if len(errs) > 0 {
275276
for e := range errs {
@@ -311,7 +312,7 @@ func ExtractGithubDetailsFromURL(url *url.URL) (string, string, string, error) {
311312
}
312313

313314
func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
314-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool, globalRevisions bool, limit int, limitTime int) ([]byte, []*model.Report, []error) {
315+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool, globalRevisions bool, limit int, limitTime int) ([]byte, []*model.Report, []error) {
315316
if gitPath == "" || filePath == "" {
316317
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
317318
model.SendProgressError("reading paths",
@@ -330,7 +331,7 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
330331
}
331332

332333
// populate history with changes and data
333-
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, progressChan, errorChan, base, remote)
334+
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, progressChan, errorChan, base, remote, extRefs)
334335
if err != nil {
335336
model.SendFatalError("extraction",
336337
fmt.Sprintf("cannot extract history %s", errors.Join(err...)), errorChan)
@@ -361,9 +362,9 @@ func RunGitHistoryHTMLReport(gitPath, filePath string, latest, useCDN bool,
361362
}
362363

363364
func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN, embeddedMode bool,
364-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, limit int, limitTime int, base string, remote bool) ([]byte, []*model.Report, []error) {
365+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, limit int, limitTime int, base string, remote, extRefs bool) ([]byte, []*model.Report, []error) {
365366

366-
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote)
367+
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan, true, limit, limitTime, base, remote, extRefs)
367368
if latest && len(commitHistory) > 1 {
368369
commitHistory = commitHistory[:1]
369370
}
@@ -396,7 +397,7 @@ func RunGithubHistoryHTMLReport(username, repo, filePath string, latest, useCDN,
396397
}
397398

398399
func RunLeftRightHTMLReport(left, right string, useCDN bool,
399-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]byte, []error) {
400+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) ([]byte, []error) {
400401

401402
var leftBytes, rightBytes []byte
402403
var errs []error
@@ -433,7 +434,7 @@ func RunLeftRightHTMLReport(left, right string, useCDN bool,
433434
},
434435
}
435436

436-
commits, errs = git.BuildCommitChangelog(commits, progressChan, errorChan, base, remote)
437+
commits, errs = git.BuildCommitChangelog(commits, progressChan, errorChan, base, remote, extRefs)
437438
if len(errs) > 0 {
438439
close(progressChan)
439440
return nil, errs
@@ -446,7 +447,7 @@ func RunLeftRightHTMLReport(left, right string, useCDN bool,
446447
}
447448

448449
func RunLeftRightHTMLReportViaString(left, right string, useCDN, embedded bool,
449-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) ([]byte, []error) {
450+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) ([]byte, []error) {
450451

451452
var errs []error
452453

@@ -465,7 +466,7 @@ func RunLeftRightHTMLReportViaString(left, right string, useCDN, embedded bool,
465466
},
466467
}
467468

468-
commits, errs = git.BuildCommitChangelog(commits, progressChan, errorChan, base, remote)
469+
commits, errs = git.BuildCommitChangelog(commits, progressChan, errorChan, base, remote, extRefs)
469470
if len(errs) > 0 {
470471
close(progressChan)
471472
return nil, errs

cmd/report.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func GetReportCommand() *cobra.Command {
4242
baseFlag, _ := cmd.Flags().GetString("base")
4343
noColorFlag, _ := cmd.Flags().GetBool("no-color")
4444
remoteFlag, _ := cmd.Flags().GetBool("remote")
45+
extRefs, _ := cmd.Flags().GetBool("ext-refs")
4546

4647
if noColorFlag {
4748
pterm.DisableStyling()
@@ -93,7 +94,7 @@ func GetReportCommand() *cobra.Command {
9394
return err
9495
}
9596
report, er := runGithubHistoryReport(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
96-
errorChan, baseFlag, remoteFlag)
97+
errorChan, baseFlag, remoteFlag, extRefs)
9798

9899
// wait for things to be completed.
99100
<-doneChan
@@ -158,7 +159,7 @@ func GetReportCommand() *cobra.Command {
158159
go listenForUpdates(updateChan, errorChan)
159160

160161
report, er := runGitHistoryReport(repo, p, latestFlag, updateChan, errorChan, baseFlag,
161-
remoteFlag, globalRevisionsFlag, limitFlag, limitTimeFlag)
162+
remoteFlag, extRefs, globalRevisionsFlag, limitFlag, limitTimeFlag)
162163

163164
<-doneChan
164165

@@ -198,7 +199,7 @@ func GetReportCommand() *cobra.Command {
198199
return urlErr
199200
}
200201

201-
report, errs := runLeftRightReport(left, right, updateChan, errorChan, baseFlag, remoteFlag)
202+
report, errs := runLeftRightReport(left, right, updateChan, errorChan, baseFlag, remoteFlag, extRefs)
202203
<-doneChan
203204
if len(errs) > 0 {
204205
for e := range errs {
@@ -229,7 +230,7 @@ func GetReportCommand() *cobra.Command {
229230
}
230231

231232
func runGitHistoryReport(gitPath, filePath string, latest bool,
232-
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool, globalRevisions bool, limit int, limitTime int) (*model.HistoricalReport, []error) {
233+
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool, globalRevisions bool, limit int, limitTime int) (*model.HistoricalReport, []error) {
233234

234235
if gitPath == "" || filePath == "" {
235236
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
@@ -251,7 +252,7 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
251252
}
252253

253254
// populate history with changes and data
254-
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote)
255+
commitHistory, err = git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs)
255256
if err != nil {
256257
model.SendProgressError("git", fmt.Sprintf("%d errors found extracting history", len(err)), errorChan)
257258
close(updateChan)
@@ -284,10 +285,10 @@ func runGitHistoryReport(gitPath, filePath string, latest bool,
284285
}
285286

286287
func runGithubHistoryReport(username, repo, filePath string, latest bool, limit int, limitTime int,
287-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) (*model.HistoricalReport, []error) {
288+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) (*model.HistoricalReport, []error) {
288289

289290
commitHistory, errs := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan,
290-
false, limit, limitTime, base, remote)
291+
false, limit, limitTime, base, remote, extRefs)
291292
if errs != nil {
292293
model.SendProgressError("git", errors.Join(errs...).Error(), errorChan)
293294
close(progressChan)
@@ -320,7 +321,7 @@ func runGithubHistoryReport(username, repo, filePath string, latest bool, limit
320321
}
321322

322323
func runLeftRightReport(left, right string,
323-
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote bool) (*model.Report, []error) {
324+
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, extRefs bool) (*model.Report, []error) {
324325

325326
var leftBytes, rightBytes []byte
326327
var errs []error
@@ -356,7 +357,7 @@ func runLeftRightReport(left, right string,
356357
},
357358
}
358359

359-
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote)
360+
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote, extRefs)
360361
close(updateChan)
361362

362363
if len(errs) > 0 {

cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func init() {
6767
rootCmd.PersistentFlags().BoolP("no-logo", "b", false, "Don't print the big purple pb33f banner")
6868
rootCmd.PersistentFlags().StringP("base", "p", "", "Base URL or path to use for resolving relative or remote references")
6969
rootCmd.PersistentFlags().BoolP("remote", "r", true, "Allow remote reference (URLs and files) to be auto resolved, without a base URL or path (default is on)")
70+
rootCmd.PersistentFlags().BoolP("ext-refs", "", false, "Turn on $ref lookups and resolving for extensions (x-) objects")
7071
}
7172

7273
func initConfig() {

cmd/summary.go

+12-9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func GetSummaryCommand() *cobra.Command {
4848
limitTimeFlag, _ := cmd.Flags().GetInt("limit-time")
4949
remoteFlag, _ := cmd.Flags().GetBool("remote")
5050
markdownFlag, _ := cmd.Flags().GetBool("markdown")
51+
extRefs, _ := cmd.Flags().GetBool("ext-refs")
5152

5253
if noColorFlag {
5354
pterm.DisableStyling()
@@ -181,7 +182,7 @@ func GetSummaryCommand() *cobra.Command {
181182
}
182183

183184
er := runGithubHistorySummary(user, repo, filePath, latestFlag, limitFlag, limitTimeFlag, updateChan,
184-
errorChan, baseFlag, remoteFlag, markdownFlag)
185+
errorChan, baseFlag, remoteFlag, markdownFlag, extRefs)
185186
// wait for things to be completed.
186187
<-doneChan
187188
if er != nil {
@@ -236,7 +237,7 @@ func GetSummaryCommand() *cobra.Command {
236237
go listenForUpdates(updateChan, errorChan)
237238

238239
err = runGitHistorySummary(args[0], args[1], latestFlag, updateChan, errorChan,
239-
baseFlag, remoteFlag, markdownFlag, globalRevisionsFlag, limitFlag, limitTimeFlag)
240+
baseFlag, remoteFlag, extRefs, markdownFlag, globalRevisionsFlag, limitFlag, limitTimeFlag)
240241

241242
<-doneChan
242243

@@ -263,7 +264,7 @@ func GetSummaryCommand() *cobra.Command {
263264
return urlErr
264265
}
265266

266-
errs := runLeftRightSummary(left, right, updateChan, errorChan, baseFlag, remoteFlag, markdownFlag)
267+
errs := runLeftRightSummary(left, right, updateChan, errorChan, baseFlag, remoteFlag, markdownFlag, extRefs)
267268
<-doneChan
268269
if len(errs) > 0 {
269270
for e := range errs {
@@ -321,7 +322,7 @@ func checkURL(urlString string, errorChan chan model.ProgressError) (string, err
321322
}
322323

323324
func runLeftRightSummary(left, right string, updateChan chan *model.ProgressUpdate,
324-
errorChan chan model.ProgressError, base string, remote, markdown bool) []error {
325+
errorChan chan model.ProgressError, base string, remote, markdown, extRefs bool) []error {
325326

326327
var leftBytes, rightBytes []byte
327328
// var errs []error
@@ -358,7 +359,7 @@ func runLeftRightSummary(left, right string, updateChan chan *model.ProgressUpda
358359
}
359360

360361
var errs []error
361-
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote)
362+
commits, errs = git.BuildCommitChangelog(commits, updateChan, errorChan, base, remote, extRefs)
362363
if len(errs) > 0 {
363364
close(updateChan)
364365
return errs
@@ -383,9 +384,9 @@ func runLeftRightSummary(left, right string, updateChan chan *model.ProgressUpda
383384
}
384385

385386
func runGithubHistorySummary(username, repo, filePath string, latest bool, limit int, limitTime int,
386-
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown bool) error {
387+
progressChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown, extRefs bool) error {
387388
commitHistory, _ := git.ProcessGithubRepo(username, repo, filePath, progressChan, errorChan,
388-
false, limit, limitTime, base, remote)
389+
false, limit, limitTime, base, remote, extRefs)
389390

390391
if latest {
391392
commitHistory = commitHistory[:1]
@@ -400,7 +401,9 @@ func runGithubHistorySummary(username, repo, filePath string, latest bool, limit
400401
}
401402

402403
func runGitHistorySummary(gitPath, filePath string, latest bool,
403-
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown bool, globalRevisions bool, limit int, limitTime int) error {
404+
updateChan chan *model.ProgressUpdate, errorChan chan model.ProgressError, base string, remote, markdown, extRefs bool,
405+
globalRevisions bool, limit int, limitTime int) error {
406+
404407
if gitPath == "" || filePath == "" {
405408
err := errors.New("please supply a path to a git repo via -r, and a path to a file via -f")
406409
model.SendProgressError("git", err.Error(), errorChan)
@@ -420,7 +423,7 @@ func runGitHistorySummary(gitPath, filePath string, latest bool,
420423
}
421424

422425
// populate history with changes and data
423-
git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote)
426+
git.PopulateHistoryWithChanges(commitHistory, 0, limitTime, updateChan, errorChan, base, remote, extRefs)
424427

425428
if latest {
426429
commitHistory = commitHistory[:1]

0 commit comments

Comments
 (0)