davsclaus commented on code in PR #28199:
URL: https://github.com/apache/camel/pull/28199#discussion_r4333294840
##########
components/camel-github2/src/main/java/org/apache/camel/component/github2/consumer/CommitConsumer.java:
##########
@@ -109,13 +110,25 @@ protected int poll() throws Exception {
}
List<GHCommit> commits = new ArrayList<>();
+ // read up to the last routed commit: the commits pushed since
then all come before it. Stopping after the
+ // first 100 would lose the older ones when more were pushed
between two polls, as lastSha then moves to
+ // the newest one. Without a last commit, or when it is not among
the remembered number of newest commits
+ // (it is no longer on the branch), only the 100 newest are
considered
+ int limit = lastSha != null ? CAPACITY :
MAX_COMMITS_WITHOUT_LAST_SHA;
+ boolean lastShaFound = false;
for (GHCommit commit :
getRepository().queryCommits().from(branchName).list().withPageSize(100)) {
commits.add(commit);
- // Stop after 100 commits to avoid fetching too many
- if (commits.size() >= 100) {
+ if (lastSha != null && lastSha.equals(commit.getSHA1())) {
+ lastShaFound = true;
+ break;
+ }
+ if (commits.size() >= limit) {
break;
}
}
+ if (!lastShaFound && commits.size() >
MAX_COMMITS_WITHOUT_LAST_SHA) {
+ commits = commits.subList(0, MAX_COMMITS_WITHOUT_LAST_SHA);
Review Comment:
Optional: when `lastSha != null` and the listing stopped at `CAPACITY`
without finding it, more than 999 commits may have been pushed since the last
poll, and the ones before the newest 100 are skipped here without a log line. A
WARN in that case would help someone looking for missing commits (point 1).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]