fix limit & offset computation

This commit is contained in:
Hemachandar
2025-11-28 12:20:13 +05:30
parent d517ca8444
commit 6f0c4d6c4e
2 changed files with 41 additions and 4 deletions
+4 -4
View File
@@ -1057,11 +1057,11 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$queries = Query::parseQueries($queries);
$limitQuery = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT);
$offsetQuery = array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET);
$limitQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_LIMIT));
$offsetQuery = current(array_filter($queries, fn ($query) => $query->getMethod() === Query::TYPE_OFFSET));
$limit = !empty($limitQuery) ? $limitQuery[0]->getValue() : 4;
$offset = !empty($offsetQuery) ? $offsetQuery[0]->getValue() : 0;
$limit = !empty($limitQuery) ? $limitQuery->getValue() : 4;
$offset = !empty($offsetQuery) ? $offsetQuery->getValue() : 0;
$page = ($offset / $limit) + 1;
$owner = $github->getOwnerName($providerInstallationId);
@@ -316,6 +316,43 @@ class VCSConsoleClientTest extends Scope
$this->assertEquals($searchedRepositories['body']['runtimeProviderRepositories'][0]['name'], 'appwrite');
$this->assertEquals($searchedRepositories['body']['runtimeProviderRepositories'][0]['runtime'], 'other');
// with limit and offset
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'runtime',
'limit' => 1,
'offset' => 0
]);
$this->assertSame(200, $repositories['headers']['status-code']);
$this->assertSame(4, $repositories['body']['total']);
$this->assertSame(1, \count($repositories['body']['runtimeProviderRepositories']));
$this->assertSame('starter-for-svelte', $repositories['body']['runtimeProviderRepositories'][0]['name']);
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'runtime',
'limit' => 2,
'offset' => 1
]);
$this->assertSame(200, $repositories['headers']['status-code']);
$this->assertSame(4, $repositories['body']['total']);
$this->assertSame(2, \count($repositories['body']['runtimeProviderRepositories']));
$this->assertSame('templates-for-functions', $repositories['body']['runtimeProviderRepositories'][0]['name']);
$this->assertSame('appwrite', $repositories['body']['runtimeProviderRepositories'][1]['name']);
$repositories = $this->client->call(Client::METHOD_GET, '/vcs/github/installations/' . $installationId . '/providerRepositories', array_merge([
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'type' => 'runtime',
'limit' => 2,
'offset' => 100
]);
$this->assertSame(200, $repositories['headers']['status-code']);
$this->assertSame(4, $repositories['body']['total']);
$this->assertSame(0, \count($repositories['body']['runtimeProviderRepositories']));
// TODO: If you are about to add another check, rewrite this to @provideScenarios
/**