Skip to content

refactor: unify GTFS parsing and real-time fetching across coverage and vehicle checks - #72

Merged
aaronbrethorst merged 5 commits into
OneBusAway:mainfrom
0xaboomar:refactor/use-helpers
Jul 16, 2025
Merged

aaronbrethorst merged 5 commits into
OneBusAway:mainfrom
0xaboomar:refactor/use-helpers

Conversation

@0xaboomar

Copy link
Copy Markdown
Member
  • Refactored CheckAgenciesWithCoverage and CheckBundleExpiration to use ParseGTFSFromCache for consistent static GTFS parsing.
  • Updated CountVehiclePositions to use FetchGTFSRTFeed for standardized real-time feed retrieval.

@coveralls

coveralls commented Jul 5, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 62.857% (+3.7%) from 59.189%
when pulling f593d8d on Abo-Omar-74:refactor/use-helpers
into 5c4d101 on OneBusAway:main.

@0xaboomar

Copy link
Copy Markdown
Member Author

Follow up

  • Added unit tests for FetchGTFSRTFeed, covering both success and failure cases.

@0xaboomar
0xaboomar force-pushed the refactor/use-helpers branch 2 times, most recently from 234e320 to 3d357f9 Compare July 10, 2025 00:18
@aaronbrethorst
aaronbrethorst requested a review from Copilot July 12, 2025 15:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors GTFS parsing and real-time feed fetching in metric checks to use centralized helper functions for consistency.

  • Replaced manual GTFS-RT HTTP request logic in CountVehiclePositions with FetchGTFSRTFeed.
  • Unified static GTFS parsing in CheckBundleExpiration and CheckAgenciesWithCoverage via ParseGTFSFromCache.
  • Updated imports accordingly and added unit tests for FetchGTFSRTFeed.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
internal/metrics/gtfs-realtime-bindings.go Swapped manual HTTP fetch for unified FetchGTFSRTFeed call.
internal/metrics/bundle_expiration.go Replaced direct file reading and ParseStatic with ParseGTFSFromCache.
internal/metrics/agencies_with_coverage.go Replaced direct file reading and ParseStatic with ParseGTFSFromCache and streamlined error return.
internal/gtfs/gtfs_bundles_test.go Added tests for FetchGTFSRTFeed, covering success and failure cases.
Comments suppressed due to low confidence (2)

internal/metrics/gtfs-realtime-bindings.go:21

  • This new call to FetchGTFSRTFeed in CountVehiclePositions isn't covered by existing tests; consider adding a unit test for CountVehiclePositions to validate correct feed retrieval and error handling.
	resp, err := gtfs.FetchGTFSRTFeed(server)

internal/metrics/bundle_expiration.go:18

  • The new call to ParseGTFSFromCache in CheckBundleExpiration isn't covered by any tests; add tests to verify successful parsing and error scenarios.
	staticData, err := gtfs.ParseGTFSFromCache(cachePath, server.ID)

"vehicle_position_url": server.VehiclePositionUrl,
},
})
return 0, err

Copilot AI Jul 12, 2025

Copy link

Choose a reason for hiding this comment

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

The error returned by FetchGTFSRTFeed is not wrapped or reported with additional context; consider using fmt.Errorf and/or reporting it via report.ReportErrorWithSentryOptions to preserve diagnostic information.

Suggested change
return 0, err
wrappedErr := fmt.Errorf("failed to fetch GTFS-RT feed from server %d (%s): %v", server.ID, server.VehiclePositionUrl, err)
report.ReportErrorWithSentryOptions(wrappedErr, report.SentryReportOptions{
Tags: map[string]string{
"server_id": strconv.Itoa(server.ID),
"vehicle_position_url": server.VehiclePositionUrl,
},
})
return 0, wrappedErr

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The error returned by FetchGTFSRTFeed is not wrapped or reported with additional context; consider using fmt.Errorf and/or reporting it via report.ReportErrorWithSentryOptions to preserve diagnostic information.

The error is already reported to Sentry inside the FetchGTFSRTFeed function.

Comment thread internal/metrics/agencies_with_coverage.go Outdated
Comment thread internal/metrics/bundle_expiration.go Outdated
)

// CheckBundleExpiration calculates the number of days remaining until the GTFS bundle expires.
func CheckBundleExpiration(cachePath string, logger *slog.Logger, currentTime time.Time, server models.ObaServer) (int, int, error) {

Copilot AI Jul 12, 2025

Copy link

Choose a reason for hiding this comment

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

Both logger and currentTime parameters appear unused in the updated implementation; consider removing them or adding appropriate logging/time-based logic.

Suggested change
func CheckBundleExpiration(cachePath string, logger *slog.Logger, currentTime time.Time, server models.ObaServer) (int, int, error) {
func CheckBundleExpiration(cachePath string, server models.ObaServer) (int, int, error) {

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Both logger and currentTime parameters appear unused in the updated implementation; consider removing them or adding appropriate logging/time-based logic.

I removed the logger, but since the current time is used inside the function, I kept it.

…iesWithCoverage

- Removed unnecessary logger argument

- Updated all callers accordingly to use centralized logging
@0xaboomar

Copy link
Copy Markdown
Member Author

I have made Copilot suggestions.

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good, great work!

@aaronbrethorst
aaronbrethorst merged commit b804ffc into OneBusAway:main Jul 16, 2025
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.

4 participants