From a3028eb9fd2180459efc511b30e9dd46937d44fd Mon Sep 17 00:00:00 2001 From: Carroll Chiou Date: Mon, 18 Sep 2023 10:33:52 -0600 Subject: [PATCH] Revert "[JENKINS-71849] Allow `NoThrottle` to be used even on github.com (#653)" (#730) This reverts commit 51d5810e9e8c15d7b4835bc6eb19fb882ffdf8e6. --- .../ApiRateLimitChecker.java | 23 +++++++++++++------ .../ApiRateLimitCheckerTest.java | 3 --- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitChecker.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitChecker.java index c845dbc07..57ce199ad 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitChecker.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitChecker.java @@ -100,13 +100,22 @@ long checkRateLimitImpl(@NonNull GHRateLimit.Record rateLimit, long count, long NoThrottle(Messages.ApiRateLimitChecker_NoThrottle()) { @Override public LocalChecker getChecker(@NonNull TaskListener listener, String apiUrl) { - return new LocalChecker(listener) { - @Override - long checkRateLimitImpl(@NonNull GHRateLimit.Record rateLimit, long count, long now) - throws InterruptedException { - return now; - } - }; + if (GitHubServerConfig.GITHUB_URL.equals(apiUrl)) { + // If the GitHub public API is being used, this will fallback to ThrottleOnOver + LocalChecker checker = ThrottleOnOver.getChecker(listener, apiUrl); + checker.writeLog( + "GitHub throttling is disabled, which is not allowed for public GitHub usage, " + + "so ThrottleOnOver will be used instead. To configure a different rate limiting strategy, go to \"GitHub API usage\" under \"Configure System\" in the Jenkins settings."); + return checker; + } else { + return new LocalChecker(listener) { + @Override + long checkRateLimitImpl(@NonNull GHRateLimit.Record rateLimit, long count, long now) + throws InterruptedException { + return now; + } + }; + } } }; diff --git a/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java b/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java index 89fb5fe7b..a47d6eb4c 100644 --- a/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java +++ b/src/test/java/org/jenkinsci/plugins/github_branch_source/ApiRateLimitCheckerTest.java @@ -27,7 +27,6 @@ import org.jenkinsci.plugins.github.config.GitHubServerConfig; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.kohsuke.github.GHRateLimit; import org.kohsuke.github.GitHub; @@ -160,7 +159,6 @@ private void setupStubs(List scenarios) throws Exception { assertEquals(2, initialRequestCount); } - @Ignore("behavior deliberately modified") @Test public void NoCheckerConfigured() throws Exception { // set up scenarios @@ -351,7 +349,6 @@ public void NoThrottleTestShouldNotThrottle404() throws Exception { * * @author Marc Salles Navarro */ - @Ignore("behavior deliberately modified") @Test public void NoThrottleTestShouldFallbackToThrottleOnOverForGitHubDotCom() throws Exception { GitHubConfiguration.get().setApiRateLimitChecker(ApiRateLimitChecker.ThrottleOnOver);