Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit 4354db6

Browse files
committed
Merge pull request #90 from netceler/master
Using RateLimiter from Guava to avoid triggering GitHub abuse detection mechanism
2 parents b40a589 + a202931 commit 4354db6

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

github-core/src/main/java/com/github/maven/plugins/core/GitHubProjectMojo.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected GitHubClient createClient(String host, String userName,
192192
}
193193
}
194194
}
195-
195+
196196
if (configureUsernamePassword(client, userName, password)
197197
|| configureOAuth2Token(client, oauth2Token)
198198
|| configureServerCredentials(client, serverId, settings,
@@ -215,10 +215,10 @@ protected GitHubClient createClient(String host, String userName,
215215
protected GitHubClient createClient(String hostname)
216216
throws MojoExecutionException {
217217
if (!hostname.contains("://"))
218-
return new GitHubClientEgit(hostname);
218+
return new RateLimitedGitHubClient(hostname);
219219
try {
220220
URL hostUrl = new URL(hostname);
221-
return new GitHubClientEgit(hostUrl.getHost(), hostUrl.getPort(),
221+
return new RateLimitedGitHubClient(hostUrl.getHost(), hostUrl.getPort(),
222222
hostUrl.getProtocol());
223223
} catch (MalformedURLException e) {
224224
throw new MojoExecutionException("Could not parse host URL "
@@ -234,7 +234,7 @@ protected GitHubClient createClient(String hostname)
234234
* @return non-null client
235235
*/
236236
protected GitHubClient createClient() {
237-
return new GitHubClientEgit();
237+
return new RateLimitedGitHubClient();
238238
}
239239

240240
/**
@@ -333,7 +333,7 @@ protected boolean configureServerCredentials(final GitHubClient client,
333333
throw new MojoExecutionException( "Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle );
334334
}
335335
}
336-
336+
337337
serverUsername = server.getUsername();
338338
serverPassword = server.getPassword();
339339
// }
@@ -407,7 +407,7 @@ protected Server getServer(final Settings settings, final String serverId) {
407407

408408
/**
409409
* Check hostname that matched nonProxy setting
410-
*
410+
*
411411
* @param proxy Maven Proxy. Must not null
412412
* @param hostname
413413
* @return matching result. true: match nonProxy
@@ -515,10 +515,10 @@ protected Proxy getProxy(final Settings settings, final String serverId, final S
515515

516516
return null;
517517
}
518-
518+
519519
@Requirement
520520
private PlexusContainer container;
521-
521+
522522
/**
523523
* {@inheritDoc}
524524
*/
@@ -527,5 +527,5 @@ public void contextualize( Context context )
527527
{
528528
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
529529
}
530-
530+
531531
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.github.maven.plugins.core;
2+
3+
import com.github.maven.plugins.core.egit.GitHubClientEgit;
4+
import com.google.common.util.concurrent.RateLimiter;
5+
6+
import java.io.IOException;
7+
import java.net.HttpURLConnection;
8+
9+
public class RateLimitedGitHubClient extends GitHubClientEgit {
10+
11+
/**
12+
* AS per https://github.com/octokit/octokit.net/issues/638#issuecomment-67795998,
13+
* it seems that GitHub only allow 20 API calls per 1-minute period
14+
*/
15+
private RateLimiter rateLimiter = RateLimiter.create(20.0/60.0);
16+
17+
public RateLimitedGitHubClient() {
18+
super();
19+
}
20+
21+
public RateLimitedGitHubClient(String hostname) {
22+
super(hostname);
23+
}
24+
25+
public RateLimitedGitHubClient(String hostname, int port, String scheme) {
26+
super(hostname, port, scheme);
27+
}
28+
29+
@Override
30+
protected HttpURLConnection createDelete(String uri) throws IOException {
31+
//rateLimiter.acquire();
32+
return super.createDelete(uri);
33+
}
34+
35+
@Override
36+
protected HttpURLConnection createGet(String uri) throws IOException {
37+
//rateLimiter.acquire();
38+
return super.createGet(uri);
39+
}
40+
41+
@Override
42+
protected HttpURLConnection createPost(String uri) throws IOException {
43+
rateLimiter.acquire();
44+
return super.createPost(uri);
45+
}
46+
47+
@Override
48+
protected HttpURLConnection createPut(String uri) throws IOException {
49+
rateLimiter.acquire();
50+
return super.createPut(uri);
51+
}
52+
}

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@
185185
<version>2.2.2</version>
186186
</dependency>
187187

188+
<dependency>
189+
<groupId>com.google.guava</groupId>
190+
<artifactId>guava</artifactId>
191+
<!-- More recent version incompatible with Guice from Maven / Sisu -->
192+
<version>14.0</version>
193+
</dependency>
194+
188195
<dependency>
189196
<groupId>junit</groupId>
190197
<artifactId>junit</artifactId>

0 commit comments

Comments
 (0)