44import org .kohsuke .github .authorization .AuthorizationProvider ;
55import org .kohsuke .github .authorization .ImmutableAuthorizationProvider ;
66import org .kohsuke .github .connector .GitHubConnector ;
7+ import org .kohsuke .github .connector .GitHubConnectorResponse ;
78import org .kohsuke .github .extras .ImpatientHttpConnector ;
89import org .kohsuke .github .internal .GitHubConnectorHttpConnectorAdapter ;
910
@@ -34,8 +35,8 @@ public class GitHubBuilder implements Cloneable {
3435
3536 private GitHubConnector connector ;
3637
37- private RateLimitHandler rateLimitHandler = RateLimitHandler .WAIT ;
38- private AbuseLimitHandler abuseLimitHandler = AbuseLimitHandler .WAIT ;
38+ private GitHubRateLimitHandler rateLimitHandler = RateLimitHandler .WAIT ;
39+ private GitHubAbuseLimitHandler abuseLimitHandler = AbuseLimitHandler .WAIT ;
3940 private GitHubRateLimitChecker rateLimitChecker = new GitHubRateLimitChecker ();
4041 /* private */ AuthorizationProvider authorizationProvider = AuthorizationProvider .ANONYMOUS ;
4142
@@ -334,6 +335,7 @@ public GitHubBuilder withJwtToken(String jwtToken) {
334335 * the connector
335336 * @return the git hub builder
336337 */
338+ @ Deprecated
337339 public GitHubBuilder withConnector (@ Nonnull HttpConnector connector ) {
338340 return withConnector (GitHubConnectorHttpConnectorAdapter .adapt (connector ));
339341 }
@@ -373,6 +375,32 @@ public GitHubBuilder withConnector(GitHubConnector connector) {
373375 * @see #withRateLimitChecker(RateLimitChecker)
374376 */
375377 public GitHubBuilder withRateLimitHandler (RateLimitHandler handler ) {
378+ return withRateLimitHandler ((GitHubRateLimitHandler ) handler );
379+ }
380+
381+ /**
382+ * Adds a {@link GitHubRateLimitHandler} to this {@link GitHubBuilder}.
383+ * <p>
384+ * GitHub allots a certain number of requests to each user or application per period of time (usually per hour). The
385+ * number of requests remaining is returned in the response header and can also be requested using
386+ * {@link GitHub#getRateLimit()}. This requests per interval is referred to as the "rate limit".
387+ * </p>
388+ * <p>
389+ * When the remaining number of requests reaches zero, the next request will return an error. If this happens,
390+ * {@link GitHubRateLimitHandler#onError(GitHubConnectorResponse)} will be called.
391+ * </p>
392+ * <p>
393+ * NOTE: GitHub treats clients that exceed their rate limit very harshly. If possible, clients should avoid
394+ * exceeding their rate limit. Consider adding a {@link RateLimitChecker} to automatically check the rate limit for
395+ * each request and wait if needed.
396+ * </p>
397+ *
398+ * @param handler
399+ * the handler
400+ * @return the git hub builder
401+ * @see #withRateLimitChecker(RateLimitChecker)
402+ */
403+ public GitHubBuilder withRateLimitHandler (GitHubRateLimitHandler handler ) {
376404 this .rateLimitHandler = handler ;
377405 return this ;
378406 }
@@ -389,7 +417,24 @@ public GitHubBuilder withRateLimitHandler(RateLimitHandler handler) {
389417 * the handler
390418 * @return the git hub builder
391419 */
420+ @ Deprecated
392421 public GitHubBuilder withAbuseLimitHandler (AbuseLimitHandler handler ) {
422+ return withAbuseLimitHandler ((GitHubAbuseLimitHandler ) handler );
423+ }
424+
425+ /**
426+ * Adds a {@link GitHubAbuseLimitHandler} to this {@link GitHubBuilder}.
427+ * <p>
428+ * When a client sends too many requests in a short time span, GitHub may return an error and set a header telling
429+ * the client to not make any more request for some period of time. If this happens,
430+ * {@link GitHubAbuseLimitHandler#onError(GitHubConnectorResponse)} will be called.
431+ * </p>
432+ *
433+ * @param handler
434+ * the handler
435+ * @return the git hub builder
436+ */
437+ public GitHubBuilder withAbuseLimitHandler (GitHubAbuseLimitHandler handler ) {
393438 this .abuseLimitHandler = handler ;
394439 return this ;
395440 }
0 commit comments