Skip to content

Extract parseWaitTime logic into shared WaitTimeUtils - #2339

Closed
Kamaldeep-singh0 wants to merge 2 commits into
hub4j:mainfrom
Kamaldeep-singh0:refactor/extract-parse-wait-time
Closed

Kamaldeep-singh0 wants to merge 2 commits into
hub4j:mainfrom
Kamaldeep-singh0:refactor/extract-parse-wait-time

Conversation

@Kamaldeep-singh0

Copy link
Copy Markdown

Summary

Fixes #1973.

Extracts the wait-time calculation and remote server Date header parsing from GitHubAbuseLimitHandler and GitHubRateLimitHandler into a shared WaitTimeUtils class. Both handlers previously carried near-duplicate parseWaitTime implementations, including an identical copy of the "server time from the response Date header" logic.

Changes

  • Added org.kohsuke.github.internal.WaitTimeUtils with parseRetryAfterWaitTime, parseRateLimitResetWaitTime, and a shared private serverNow() that resolves server time from the response Date header (falling back to the local clock when the header is missing).
  • Updated GitHubAbuseLimitHandler.parseWaitTime and GitHubRateLimitHandler.parseWaitTime to delegate to WaitTimeUtils, preserving their existing method signatures and constants, including reading DEFAULT_WAIT_MILLIS at call time.
  • Added WaitTimeUtilsTest (8 tests) covering missing headers, seconds parsing, minimum clamping, HTTP-date math relative to the response Date, rate-limit reset calculation, and the serverNow fallback when the Date header is missing.

Design question

I placed WaitTimeUtils as a public final class in org.kohsuke.github.internal, matching the existing EnumUtils precedent. The issue mentioned considering exposing this as public — if you would prefer it in the top-level org.kohsuke.github package so external callers implementing custom error handlers can use it as public API, I am happy to move it.

Tests

New WaitTimeUtilsTest: 8 tests, all passing. Code formatted with the project's Spotless configuration.

Fixes hub4j#1973. GitHubAbuseLimitHandler and GitHubRateLimitHandler each
carried near-duplicate parseWaitTime implementations, including the
server-time-from-Date-header block. Both now delegate to the new
org.kohsuke.github.internal.WaitTimeUtils, preserving their existing
signatures and constants. Adds WaitTimeUtilsTest (8 tests) covering
header parsing, minimum clamping, reset math, and the Date-header
fallback.
Move rateLimitResetReturnsDefaultWhenHeaderMissing after the
fallback test so the test methods follow the alphabetical member
order enforced by the project's Spotless configuration. No logic
changes.
@Kamaldeep-singh0
Kamaldeep-singh0 deleted the refactor/extract-parse-wait-time branch October 16, 2026 16:45
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.

Extract parseWaitTime method to shared utility

1 participant