This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 1386c518da8 CAMEL-18439: camel-github - Consumer that polls commits 
crashed when repository has more than 100 commits
1386c518da8 is described below

commit 1386c518da8f23ed5f1aca923c04ea3de573eab2
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Aug 31 09:37:19 2022 +0200

    CAMEL-18439: camel-github - Consumer that polls commits crashed when 
repository has more than 100 commits
---
 .../apache/camel/component/github/consumer/CommitConsumer.java    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git 
a/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/CommitConsumer.java
 
b/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/CommitConsumer.java
index 3bf44be6bc7..b78e4922e65 100644
--- 
a/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/CommitConsumer.java
+++ 
b/components/camel-github/src/main/java/org/apache/camel/component/github/consumer/CommitConsumer.java
@@ -119,11 +119,16 @@ public class CommitConsumer extends 
AbstractGitHubConsumer {
         for (RepositoryCommit commit : commits) {
             if (!commitHashes.contains(commit.getSha())) {
                 newCommits.push(commit);
+                // make room when adding new elements
+                while (commitHashes.size() > CAPACITY - 1) {
+                    commitHashes.remove();
+                }
                 commitHashes.add(commit.getSha());
                 lastSha = commit.getSha();
             }
         }
 
+        int counter = 0;
         while (!newCommits.empty()) {
             RepositoryCommit newCommit = newCommits.pop();
             Exchange e = createExchange(true);
@@ -133,7 +138,8 @@ public class CommitConsumer extends AbstractGitHubConsumer {
             e.getMessage().setHeader(GitHubConstants.GITHUB_COMMIT_URL, 
newCommit.getUrl());
             e.getMessage().setBody(newCommit.getCommit().getMessage());
             getProcessor().process(e);
+            counter++;
         }
-        return newCommits.size();
+        return counter;
     }
 }

Reply via email to