Skip to content

Conversation

@drewda
Copy link
Member

@drewda drewda commented Dec 11, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 11, 2025 05:22
@github-actions
Copy link

Generated Code Changes Required

The following files may need to be regenerated. Please run go generate ./... and commit the changes:

diff --git a/doc/cli/transitland_validate.md b/doc/cli/transitland_validate.md
index e92dade..082ca72 100644
--- a/doc/cli/transitland_validate.md
+++ b/doc/cli/transitland_validate.md
@@ -16,21 +16,26 @@ transitland validate [flags] <reader>
 

% transitland validate "https://www.bart.gov/dev/schedules/google_transit.zip"
+% transitland validate --output-format json --include-entities "http://developer.trimet.org/schedule/gtfs.zip"


### Options

   --best-practices                     Include Best Practices validations
  •  --error-limit int                    Max number of detailed errors per error group (default 1000)
    
  •  --error-limit int                    Max number of detailed errors per error group (default: 1000) (default 1000)
     --error-threshold strings            Fail validation if file exceeds error percentage; format: 'filename:percent' or '*:percent' for default (e.g., 'stops.txt:5' or '*:10')
     --ext strings                        Include GTFS Extension
    
    -h, --help help for validate
  •  --o string                           Write validation report as JSON to file
    
  •  --rt strings                         Include GTFS-RT proto message in validation report
    
  •  --rt-json                            Include GTFS-RT proto messages as JSON in validation report
    
  •  --include-entities                   Include GTFS entities in JSON output
    
  •  --include-route-geometries           Include route geometries in JSON output
    
  •  --include-service-levels             Include service levels in JSON output
    
  • -o, --output string Write validation report as JSON to file
  •  --output-format string               Output format. Values: json (JSON to stdout, suppresses logs). Default: log messages
    
  •  --rt strings                         Include GTFS-RT proto message in validation report (default: none)
    
  •  --rt-json                            Include GTFS-RT proto messages as JSON in validation report (default: false)
     --save-fvid int                      Save report to feed version ID
    
  •  --validation-report                  Save static validation report in database
    
  •  --validation-report                  Save static validation report in database (default: false)
     --validation-report-storage string   Storage path for saving validation report JSON
    


Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds JSON output functionality to the validator command, allowing validation results to be written to stdout in JSON format with log suppression, making it easier to programmatically consume the output. The changes also expose options to include additional data in the JSON output such as GTFS entities, route geometries, and service levels.

Key Changes:

  • Added --output-format json flag to output JSON to stdout while suppressing log messages
  • Added three new include flags (--include-entities, --include-route-geometries, --include-service-levels) to optionally include extra data in JSON output
  • Renamed the output flag from -o to --output/-o with improved help text

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


// Validate output format
if cmd.OutputFormat != "" && cmd.OutputFormat != "json" {
return errors.New("invalid output format: only 'json' is supported")
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message states "only 'json' is supported" but this might be confusing since the empty string is also valid (representing the default behavior). Consider clarifying the error message to something like "invalid output format: must be empty or 'json'" or "invalid output format: supported values are 'json' or empty for default".

Suggested change
return errors.New("invalid output format: only 'json' is supported")
return errors.New("invalid output format: supported values are 'json' or empty for default")

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +98
// Set log level to fatal when outputting JSON to stdout to prevent log pollution
if !cmd.shouldShowLogs() {
log.SetLevel(zerolog.FatalLevel)
}
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the global log level in Parse could affect other loggers if multiple commands are run in the same process or if this code is used as a library. Consider using a context-aware logger or storing the log level preference in the command struct and checking it before each log call, similar to how shouldShowLogs is already being checked at lines 105 and 150.

Suggested change
// Set log level to fatal when outputting JSON to stdout to prevent log pollution
if !cmd.shouldShowLogs() {
log.SetLevel(zerolog.FatalLevel)
}
// Do not set global log level; rely on shouldShowLogs() checks before logging

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +137
outf := os.Stdout
if cmd.OutputFile != "" {
var err error
outf, err = os.Create(cmd.OutputFile)
if err != nil {
return err
}
defer outf.Close()
}
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When both OutputFile and OutputFormat are set to json, the JSON output goes only to the file and not to stdout. This might be unexpected behavior - users might expect JSON to be written to both locations, or at least have logs explaining where the output went. Consider documenting this behavior in the help text or adding a validation check to prevent both flags from being used together.

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +66
fl.BoolVar(&cmd.Options.IncludeRealtimeJson, "rt-json", false, "Include GTFS-RT proto messages as JSON in validation report (default: false)")
fl.BoolVar(&cmd.SaveValidationReport, "validation-report", false, "Save static validation report in database (default: false)")
fl.StringVar(&cmd.ValidationReportStorage, "validation-report-storage", "", "Storage path for saving validation report JSON")
fl.IntVar(&cmd.FVID, "save-fvid", 0, "Save report to feed version ID")
fl.StringSliceVar(&cmd.rtFiles, "rt", nil, "Include GTFS-RT proto message in validation report")
fl.IntVar(&cmd.Options.ErrorLimit, "error-limit", 1000, "Max number of detailed errors per error group")
fl.StringSliceVar(&cmd.rtFiles, "rt", nil, "Include GTFS-RT proto message in validation report (default: none)")
fl.IntVar(&cmd.Options.ErrorLimit, "error-limit", 1000, "Max number of detailed errors per error group (default: 1000)")
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding explicit default values in the help text like "(default: false)" and "(default: 1000)" is inconsistent with the codebase convention. The convention in this codebase is to only document defaults in help text when they come from environment variables (e.g., "default: $TL_DATABASE_URL"). The pflag library already displays the default values automatically, so these additions are redundant. Consider removing the explicit default value documentation from lines 61, 62, 65, and 66.

Copilot uses AI. Check for mistakes.
func (cmd *ValidatorCommand) AddFlags(fl *pflag.FlagSet) {
fl.StringSliceVar(&cmd.extensionDefs, "ext", nil, "Include GTFS Extension")
fl.StringVar(&cmd.OutputFile, "o", "", "Write validation report as JSON to file")
fl.StringVarP(&cmd.OutputFile, "output", "o", "", "Write validation report as JSON to file")
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long flag name "output" is inconsistent with the similar RTConvertCommand which uses "out" for its output file flag. For consistency across the codebase, consider using "out" as the long flag name instead of "output".

Suggested change
fl.StringVarP(&cmd.OutputFile, "output", "o", "", "Write validation report as JSON to file")
fl.StringVarP(&cmd.OutputFile, "out", "o", "", "Write validation report as JSON to file")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants