asfgit closed pull request #60: IGNITE-10146 Refresh missing from Git prs while full reindex
URL: https://github.com/apache/ignite-teamcity-bot/pull/60 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java index 6a373668..a9b5d959 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/ignited/GitHubConnIgnitedImpl.java @@ -16,6 +16,7 @@ */ package org.apache.ignite.ci.github.ignited; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -52,7 +53,6 @@ /** Ignite provider. */ @Inject Provider<Ignite> igniteProvider; - /** Scheduler. */ @Inject IScheduler scheduler; @@ -125,6 +125,9 @@ protected String runActualizePrs(String srvId, boolean fullReindex) { AtomicReference<String> outLinkNext = new AtomicReference<>(); List<PullRequest> ghData = conn.getPullRequests(null, outLinkNext); + + Set<Integer> actualPrs = new HashSet<>(); + int cntSaved = saveChunk(ghData); int totalChecked = ghData.size(); while (outLinkNext.get() != null) { @@ -134,13 +137,31 @@ protected String runActualizePrs(String srvId, boolean fullReindex) { cntSaved += savedThisChunk; totalChecked += ghData.size(); + if (fullReindex) { + actualPrs.addAll(ghData.stream() + .map(pr -> pr.getNumber()) + .collect(Collectors.toSet())); + } + if (!fullReindex && savedThisChunk == 0) break; } + if (fullReindex) + refreshOutdatedPrs(actualPrs); + return "Entries saved " + cntSaved + " PRs checked " + totalChecked; } + /** */ + private void refreshOutdatedPrs(Set<Integer> actualPrs) { + StreamSupport.stream(prCache.spliterator(), false) + .filter(entry -> entry.getKey() >> 32 == srvIdMaskHigh) + .filter(entry -> PullRequest.OPEN.equals(entry.getValue().getState())) + .filter(entry -> !actualPrs.contains(entry.getValue().getNumber())) + .forEach(entry -> prCache.put(entry.getKey(), conn.getPullRequest(entry.getValue().getNumber()))); + } + private int saveChunk(List<PullRequest> ghData) { Set<Long> ids = ghData.stream().map(PullRequest::getNumber) .map(this::prNumberToCacheKey) diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java index f591b7fa..72a0921b 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/GitHubConnectionImpl.java @@ -17,9 +17,6 @@ package org.apache.ignite.ci.github.pure; import com.google.common.base.Preconditions; -import com.google.common.base.Strings; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.File; @@ -33,13 +30,10 @@ import java.util.List; import java.util.Properties; import java.util.StringTokenizer; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.apache.ignite.ci.HelperConfig; import org.apache.ignite.ci.di.AutoProfiling; import org.apache.ignite.ci.github.PullRequest; -import org.apache.ignite.ci.util.ExceptionUtil; import org.apache.ignite.ci.util.HttpUtil; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -98,11 +92,8 @@ gitApiUrl = (props.getProperty(HelperConfig.GIT_API_URL)); } - /** {@inheritDoc} */ - @AutoProfiling - @Override public PullRequest getPullRequest(String branchForTc) { - Preconditions.checkState(!isNullOrEmpty(gitApiUrl), "Git API URL is not configured for this server."); - + /** */ + private Integer convertBranchToId(String branchForTc) { String id = null; // Get PR id from string "pull/XXXX/head" @@ -116,6 +107,14 @@ } } + return Integer.parseInt(id); + } + + /** {@inheritDoc} */ + @AutoProfiling + @Override public PullRequest getPullRequest(Integer id) { + Preconditions.checkState(!isNullOrEmpty(gitApiUrl), "Git API URL is not configured for this server."); + String pr = gitApiUrl + "pulls/" + id; try (InputStream is = HttpUtil.sendGetToGit(gitAuthTok, pr, null)) { @@ -128,6 +127,12 @@ } } + /** {@inheritDoc} */ + @AutoProfiling + @Override public PullRequest getPullRequest(String branchForTc) { + return getPullRequest(convertBranchToId(branchForTc)); + } + /** {@inheritDoc} */ @AutoProfiling @Override public boolean notifyGit(String url, String body) { diff --git a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java index 268d2c7f..dba5c2fe 100644 --- a/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java +++ b/ignite-tc-helper-web/src/main/java/org/apache/ignite/ci/github/pure/IGitHubConnection.java @@ -31,6 +31,9 @@ */ PullRequest getPullRequest(String branch); + /** */ + PullRequest getPullRequest(Integer id); + /** * Send POST request with given body. * ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [hidden email] With regards, Apache Git Services |
Free forum by Nabble | Edit this page |