From 14d0bf05a2a39e59e4b347f5f2e05330c53844b0 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Sat, 16 Mar 2019 01:31:44 -0700 Subject: [PATCH] Ensure to check all pages of comments --- app/Listeners/GitHubCommentListener.php | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/Listeners/GitHubCommentListener.php b/app/Listeners/GitHubCommentListener.php index 6d7ec2d..a351717 100644 --- a/app/Listeners/GitHubCommentListener.php +++ b/app/Listeners/GitHubCommentListener.php @@ -7,6 +7,7 @@ use App\Helpers\Format; use App\Models\Build; use App\Models\Project; +use Github\ResultPager; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; @@ -130,7 +131,7 @@ private function buildMessage(array $artifacts, int $base_total_size, int $total | File name | Previous Size | New Size | Change | | --------- | ------------- | -------- | ------ | - + EOT; foreach ($artifacts as $artifact) { $message .= '| ' . $artifact['name'] . ' | '; @@ -163,16 +164,27 @@ private function checkForExistingComment( Project $project, Build $build ) { - $comments = $github->issue()->comments()->all( + $issueCommentsApi = $github->issue()->comments(); + $paginator = new ResultPager($github); + $comments = $paginator->fetch($issueCommentsApi, 'all', [ $project->org_name, $project->repo_name, $build->pull_request - ); - foreach ($comments as $comment) { - if (ends_with($comment['user']['html_url'], '/apps/' . env('GITHUB_APP_ALIAS'))) { - return $comment['id']; + ]); + + do { + $hasNext = false; + foreach ($comments as $comment) { + if (ends_with($comment['user']['html_url'], '/apps/' . env('GITHUB_APP_ALIAS'))) { + return $comment['id']; + } } - } + if ($paginator->hasNext()) { + $hasNext = true; + $comments = $paginator->fetchNext(); + } + } while ($hasNext); + return null; } }