Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-34727] Disable cache and delay branch indexing #54

Merged
merged 6 commits into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ public class Connector {

gb.withRateLimitHandler(CUSTOMIZED);
OkHttpClient client = new OkHttpClient().setProxy(getProxy(defaultIfBlank(apiUrl, GITHUB_URL)));
client.setCache(GitHubClientCacheOps.toCacheDir().apply(config));
if (config.getClientCacheSize() > 0) {
Cache cache = toCacheDir().apply(config);
client.setCache(cache);
}

gb.withConnector(new OkHttpConnector(new OkUrlFactory(client)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package org.jenkinsci.plugins.github_branch_source;

import java.util.concurrent.TimeUnit;

import com.cloudbees.jenkins.GitHubRepositoryName;
import com.cloudbees.jenkins.GitHubWebHook;
import hudson.Extension;
Expand All @@ -33,6 +35,7 @@
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.SCMSourceOwners;
import jenkins.util.Timer;

/**
* This listener is registered only when {@link org.kohsuke.github.GHEvent} PUSH is received.
Expand All @@ -44,26 +47,31 @@ public class GitHubWebhookListenerImpl extends GitHubWebHook.Listener {

@Override
public void onPushRepositoryChanged(final String pusherName, final GitHubRepositoryName changedRepository) {
ACL.impersonate(ACL.SYSTEM, new Runnable() {
// Delaying the indexing for some seconds to avoid GitHub cache
Timer.get().schedule(new Runnable() {
@Override public void run() {
boolean found = false;
for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
for (SCMSource source : owner.getSCMSources()) {
if (source instanceof GitHubSCMSource) {
GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
if (gitHubSCMSource.getRepoOwner().equals(changedRepository.getUserName()) &&
gitHubSCMSource.getRepository().equals(changedRepository.getRepositoryName())) {
found = true;
LOGGER.log(Level.FINE, "push event from {0} on {1}:{2}/{3} forwarded to {4}", new Object[] {pusherName, changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName(), owner.getFullName()});
owner.onSCMSourceUpdated(gitHubSCMSource);
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
boolean found = false;
for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
for (SCMSource source : owner.getSCMSources()) {
if (source instanceof GitHubSCMSource) {
GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
if (gitHubSCMSource.getRepoOwner().equals(changedRepository.getUserName()) &&
gitHubSCMSource.getRepository().equals(changedRepository.getRepositoryName())) {
found = true;
LOGGER.log(Level.FINE, "push event from {0} on {1}:{2}/{3} forwarded to {4}", new Object[] {pusherName, changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName(), owner.getFullName()});
owner.onSCMSourceUpdated(gitHubSCMSource);
}
}
}
}
if (!found) {
LOGGER.log(Level.FINE, "push event from {0} on {1}:{2}/{3} did not match any project", new Object[] {pusherName, changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName()});
}
}
}
if (!found) {
LOGGER.log(Level.FINE, "push event from {0} on {1}:{2}/{3} did not match any project", new Object[] {pusherName, changedRepository.getHost(), changedRepository.getUserName(), changedRepository.getRepositoryName()});
}
});
}
});
}, 5, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@
import com.cloudbees.jenkins.GitHubRepositoryName;
import hudson.Extension;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import hudson.security.ACL;
import jenkins.scm.api.SCMSource;
import jenkins.scm.api.SCMSourceOwner;
import jenkins.scm.api.SCMSourceOwners;
import jenkins.util.Timer;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.github.extension.GHEventsSubscriber;
import org.kohsuke.github.GHEvent;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -97,21 +96,26 @@ protected void onEvent(GHEvent event, String payload) {
LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
return;
}
ACL.impersonate(ACL.SYSTEM, new Runnable() {
// Delaying the indexing for some seconds to avoid GitHub cache
Timer.get().schedule(new Runnable() {
@Override public void run() {
for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
for (SCMSource source : owner.getSCMSources()) {
if (source instanceof GitHubSCMSource) {
GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
if (gitHubSCMSource.getRepoOwner().equals(changedRepository.getUserName()) &&
gitHubSCMSource.getRepository().equals(changedRepository.getRepositoryName())) {
owner.onSCMSourceUpdated(gitHubSCMSource);
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override public void run() {
for (final SCMSourceOwner owner : SCMSourceOwners.all()) {
for (SCMSource source : owner.getSCMSources()) {
if (source instanceof GitHubSCMSource) {
GitHubSCMSource gitHubSCMSource = (GitHubSCMSource) source;
if (gitHubSCMSource.getRepoOwner().equals(changedRepository.getUserName()) &&
gitHubSCMSource.getRepository().equals(changedRepository.getRepositoryName())) {
owner.onSCMSourceUpdated(gitHubSCMSource);
}
}
}
}
}
}
});
}
});
}, 5, TimeUnit.SECONDS);
} else {
LOGGER.log(Level.WARNING, "Malformed repository URL {0}", repoUrl);
}
Expand Down