Repository navigation
Extract parseWaitTime logic into shared WaitTimeUtils - #2339
Closed
Kamaldeep-singh0 wants to merge 2 commits into
Closed
Kamaldeep-singh0 wants to merge 2 commits into
Kamaldeep-singh0 wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1973.
Extracts the wait-time calculation and remote server
Dateheader parsing fromGitHubAbuseLimitHandlerandGitHubRateLimitHandlerinto a sharedWaitTimeUtilsclass. Both handlers previously carried near-duplicateparseWaitTimeimplementations, including an identical copy of the "server time from the response Date header" logic.Changes
org.kohsuke.github.internal.WaitTimeUtilswithparseRetryAfterWaitTime,parseRateLimitResetWaitTime, and a shared privateserverNow()that resolves server time from the responseDateheader (falling back to the local clock when the header is missing).GitHubAbuseLimitHandler.parseWaitTimeandGitHubRateLimitHandler.parseWaitTimeto delegate toWaitTimeUtils, preserving their existing method signatures and constants, including readingDEFAULT_WAIT_MILLISat call time.WaitTimeUtilsTest(8 tests) covering missing headers, seconds parsing, minimum clamping, HTTP-date math relative to the responseDate, rate-limit reset calculation, and theserverNowfallback when theDateheader is missing.Design question
I placed
WaitTimeUtilsas a public final class inorg.kohsuke.github.internal, matching the existingEnumUtilsprecedent. The issue mentioned considering exposing this as public — if you would prefer it in the top-levelorg.kohsuke.githubpackage 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.