diff --git a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java index 418bc63185b1562ead820bef5d8dfe932b86e213..90c4552dfe7a8b98045f917aac04fdd7a9b3b271 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java +++ b/src/main/java/org/eclipsefoundation/git/eca/api/GithubAPI.java @@ -167,36 +167,4 @@ public interface GithubAPI { @Path("installation/repositories") public Response getInstallationRepositories(@BeanParam BaseAPIParameters params, @HeaderParam(HttpHeaders.AUTHORIZATION) String bearer); - /** - * Recursively fetches all comments from a pull request by handling pagination manually. - * - * @param bearer GitHub bearer token - * @param apiVersion GitHub API version - * @param org organization name - * @param repo repository name - * @param prNumber pull request number - * @return List of all comments from the pull request - */ - default List<GithubPullRequestComment> getAllPullRequestComments(String bearer, String apiVersion, String org, String repo, - int prNumber) { - List<GithubPullRequestComment> allComments = new ArrayList<>(); - int page = 1; - int perPage = 100; // GitHub's maximum items per page - - // Given that there's no pagination in the response, we need to query until we get an empty response, that would mean that we've - // reached the end - while (true) { - RestResponse<List<GithubPullRequestComment>> response = getComments(bearer, apiVersion, org, repo, prNumber, perPage, page); - - List<GithubPullRequestComment> comments = response.getEntity(); - if (Objects.isNull(comments) || comments.isEmpty()) { - break; - } - - allComments.addAll(comments); - page++; - } - - return allComments; - } } diff --git a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubHelper.java b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubHelper.java index 073032ed9e4e2e42e889f618debb05959f8ec73f..66dc3dc720dc52048c31c385b31718245809df7e 100644 --- a/src/main/java/org/eclipsefoundation/git/eca/helper/GithubHelper.java +++ b/src/main/java/org/eclipsefoundation/git/eca/helper/GithubHelper.java @@ -57,6 +57,7 @@ import org.eclipsefoundation.persistence.model.RDBMSQuery; import org.eclipsefoundation.persistence.service.FilterService; import org.eclipsefoundation.utils.helper.DateTimeHelper; import org.eclipsefoundation.utils.helper.TransformationHelper; +import org.jboss.resteasy.reactive.RestResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import io.quarkus.qute.Location; @@ -481,6 +482,40 @@ public class GithubHelper { .build()); } + + /** + * Recursively fetches all comments from a pull request by handling pagination manually. + * + * @param bearer GitHub bearer token + * @param apiVersion GitHub API version + * @param org organization name + * @param repo repository name + * @param prNumber pull request number + * @return List of all comments from the pull request + */ + private List<GithubPullRequestComment> getAllPullRequestComments(String bearer, String apiVersion, String org, String repo, + int prNumber) { + List<GithubPullRequestComment> allComments = new ArrayList<>(); + int page = 1; + int perPage = 100; // GitHub's maximum items per page + + // Given that there's no pagination in the response, we need to query until we get an empty response, that would mean that we've + // reached the end + while (true) { + RestResponse<List<GithubPullRequestComment>> response = ghApi.getComments(bearer, apiVersion, org, repo, prNumber, perPage, page); + + List<GithubPullRequestComment> comments = response.getEntity(); + if (Objects.isNull(comments) || comments.isEmpty()) { + break; + } + + allComments.addAll(comments); + page++; + } + + return allComments; + } + /** * This method posts a comment to the pull request detailing the validation errors and mentioning the usernames that need to take * action. @@ -503,8 +538,7 @@ public class GithubHelper { Integer pullRequestNumber = request.getPullRequest().getNumber(); // Get existing comments using pagination - List<GithubPullRequestComment> comments = ghApi - .getAllPullRequestComments(ghBearerString, apiVersion, login, repositoryName, pullRequestNumber); + List<GithubPullRequestComment> comments = getAllPullRequestComments(ghBearerString, apiVersion, login, repositoryName, pullRequestNumber); Set<String> nonMentionedUsers = usernames .stream()