31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-05-29 03:50:46 +00:00

[#327] Process pull requests with more than 30 files

Signed-off-by: Roland Dalmulder <contact@rolandd.com>
This commit is contained in:
Roland Dalmulder 2021-11-05 22:48:36 +01:00
parent 635327e36a
commit b64c1d3356
No known key found for this signature in database
GPG Key ID: 6D30CD38749A5B9E
2 changed files with 76 additions and 37 deletions

View File

@ -221,10 +221,10 @@ class GitHub
*
* @since 3.0.0
*/
public function getFilesForPullRequest($user, $repo, $pullId)
public function getFilesForPullRequest($user, $repo, $pullId, $page = 1)
{
// Build the request path.
$path = "/repos/$user/$repo/pulls/" . (int) $pullId . '/files';
$path = "/repos/$user/$repo/pulls/" . (int) $pullId . '/files?page=' . $page;
$prepared = $this->prepareRequest($path);

View File

@ -37,7 +37,8 @@ class PullModel extends AbstractModel
* @var array
* @since 2.0
*/
protected $nonProductionFolders = array(
protected $nonProductionFolders
= array(
'build',
'docs',
'installation',
@ -51,7 +52,8 @@ class PullModel extends AbstractModel
* @var array
* @since 2.0
*/
protected $nonProductionFiles = array(
protected $nonProductionFiles
= array(
'.drone.yml',
'.gitignore',
'.php_cs',
@ -522,7 +524,6 @@ class PullModel extends AbstractModel
*/
private function applyWithGitHub(int $id): bool
{
// Get the Github object
$github = Helper::initializeGithub();
$pull = $this->retrieveGitHubData($github, $id);
@ -534,12 +535,7 @@ class PullModel extends AbstractModel
try
{
$filesResponse = $github->getFilesForPullRequest(
$this->getState()->get('github_user'),
$this->getState()->get('github_repo'),
$id
);
$files = json_decode($filesResponse->body, false);
$files = $this->getFiles($id, 1);
}
catch (UnexpectedResponse $exception)
{
@ -710,6 +706,49 @@ class PullModel extends AbstractModel
return true;
}
/**
* Get all files from Github.
*
* @param int $id The pull ID
* @param int $page THhe page umber to process
* @param array $files The list of files retrieved from Github
*
* @return array LIst of files to process.
*
* @since 4.2.0
*/
private function getFiles(int $id, int $page, array $files = []): array
{
$github = Helper::initializeGithub();
$filesResponse = $github->getFilesForPullRequest(
$this->getState()->get('github_user'),
$this->getState()->get('github_repo'),
$id,
$page
);
$files = array_merge($files, json_decode($filesResponse->getBody(), false));
$lastPage = 1;
preg_match(
'/(\?page=[0-9]{1,3}>; rel=\"last\")/', $filesResponse->getHeaders()['link'][0], $matches
);
if ($matches && isset($matches[0]))
{
preg_match('/\d+/', $matches[0], $pages);
$lastPage = (int) $pages[0];
}
if ($page <= $lastPage)
{
$files = $this->getFiles($id, ++$page, $files);
}
return $files;
}
/**
* Parse the list of modified files from a pull request
*