Skip to content

Commit 5b16579

Browse files
committed
Increase the default limits for finding activities
1 parent ac5cce2 commit 5b16579

File tree

7 files changed

+61
-8
lines changed

7 files changed

+61
-8
lines changed

go-tests/activity_list_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tests
22

33
import (
44
"net/http/httptest"
5+
"strconv"
56
"testing"
67
"time"
78

@@ -87,4 +88,51 @@ func TestActivityList(t *testing.T) {
8788

8889
assertTrimmed(t, "complete", f.Run("act:get", "-p", projectID, "-e", ".", "act1", "-P", "state"))
8990
assertTrimmed(t, "2014-04-01T10:00:00+00:00", f.Run("act:get", "-p", projectID, "-e", ".", "act1", "-P", "created_at"))
91+
92+
// Generate a longer list of activities.
93+
var activities = make([]*mockapi.Activity, 30)
94+
for i := range activities {
95+
num := i + 1
96+
createdAt := aprilFoolsDay10am.Add(time.Duration(i) * time.Minute)
97+
varName := "X" + strconv.Itoa(num)
98+
activities[i] = &mockapi.Activity{
99+
ID: "act" + strconv.Itoa(num),
100+
Type: "environment.variable.create",
101+
State: "complete",
102+
Result: "success",
103+
CompletionPercent: 100,
104+
Project: projectID,
105+
Environments: []string{"main"},
106+
Description: "<user>Mock User</user> created variable <variable>" + varName + "</variable> on environment <environment>main</environment>",
107+
Text: "Mock User created variable " + varName + " on environment main",
108+
CreatedAt: createdAt,
109+
UpdatedAt: createdAt,
110+
}
111+
}
112+
apiHandler.SetProjectActivities(projectID, activities)
113+
114+
assertTrimmed(t, `
115+
ID Created Description Progress State Result
116+
act30 2014-04-01T10:29:00+00:00 Mock User created variable X30 on environment main 100% complete success
117+
act29 2014-04-01T10:28:00+00:00 Mock User created variable X29 on environment main 100% complete success
118+
act28 2014-04-01T10:27:00+00:00 Mock User created variable X28 on environment main 100% complete success
119+
act27 2014-04-01T10:26:00+00:00 Mock User created variable X27 on environment main 100% complete success
120+
act26 2014-04-01T10:25:00+00:00 Mock User created variable X26 on environment main 100% complete success`,
121+
f.Run("act", "-p", projectID, "-e", ".", "--format", "plain", "--limit", "5"))
122+
123+
assertTrimmed(t, `
124+
ID Created Description Progress State Result
125+
act30 2014-04-01T10:29:00+00:00 Mock User created variable X30 on environment main 100% complete success
126+
act29 2014-04-01T10:28:00+00:00 Mock User created variable X29 on environment main 100% complete success
127+
act28 2014-04-01T10:27:00+00:00 Mock User created variable X28 on environment main 100% complete success
128+
act27 2014-04-01T10:26:00+00:00 Mock User created variable X27 on environment main 100% complete success
129+
act26 2014-04-01T10:25:00+00:00 Mock User created variable X26 on environment main 100% complete success
130+
act25 2014-04-01T10:24:00+00:00 Mock User created variable X25 on environment main 100% complete success
131+
act24 2014-04-01T10:23:00+00:00 Mock User created variable X24 on environment main 100% complete success
132+
act23 2014-04-01T10:22:00+00:00 Mock User created variable X23 on environment main 100% complete success
133+
act22 2014-04-01T10:21:00+00:00 Mock User created variable X22 on environment main 100% complete success
134+
act21 2014-04-01T10:20:00+00:00 Mock User created variable X21 on environment main 100% complete success
135+
act20 2014-04-01T10:19:00+00:00 Mock User created variable X20 on environment main 100% complete success
136+
act19 2014-04-01T10:18:00+00:00 Mock User created variable X19 on environment main 100% complete success`,
137+
f.Run("act", "-p", projectID, "-e", ".", "--format", "plain", "--limit", "12"))
90138
}

src/Command/Activity/ActivityCancelCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
5959
$activity = $this->getSelectedProject()
6060
->getActivity($id);
6161
if (!$activity) {
62-
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, 10, [Activity::STATE_PENDING, Activity::STATE_IN_PROGRESS], 'cancel') ?: [], 'Activity');
62+
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, self::DEFAULT_FIND_LIMIT, [Activity::STATE_PENDING, Activity::STATE_IN_PROGRESS], 'cancel') ?: [], 'Activity');
6363
if (!$activity) {
6464
$this->stdErr->writeln("Activity not found: <error>$id</error>");
6565

6666
return 1;
6767
}
6868
}
6969
} else {
70-
$activities = $loader->loadFromInput($apiResource, $input, 10, [Activity::STATE_PENDING, Activity::STATE_IN_PROGRESS], 'cancel');
70+
$activities = $loader->loadFromInput($apiResource, $input, self::DEFAULT_FIND_LIMIT, [Activity::STATE_PENDING, Activity::STATE_IN_PROGRESS], 'cancel');
7171
if (\count($activities) === 0) {
7272
$this->stdErr->writeln('No cancellable activities found');
7373

src/Command/Activity/ActivityCommandBase.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
class ActivityCommandBase extends CommandBase implements CompletionAwareInterface
1111
{
12+
const DEFAULT_LIST_LIMIT = 10; // Display a digestible number of activities by default.
13+
const DEFAULT_FIND_LIMIT = 25; // This is the current limit per page of results.
14+
1215
public function completeOptionValues($optionName, CompletionContext $context)
1316
{
1417
switch ($optionName) {

src/Command/Activity/ActivityGetCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6666
$activity = $this->getSelectedProject()
6767
->getActivity($id);
6868
if (!$activity) {
69-
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, 10) ?: [], 'Activity');
69+
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, self::DEFAULT_FIND_LIMIT) ?: [], 'Activity');
7070
if (!$activity) {
7171
$this->stdErr->writeln("Activity not found: <error>$id</error>");
7272

src/Command/Activity/ActivityListCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function configure()
5656
. "\nThe % or * characters can be used as a wildcard to exclude types."
5757
);
5858

59-
$this->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Limit the number of results displayed', 10)
59+
$this->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Limit the number of results displayed', self::DEFAULT_LIST_LIMIT)
6060
->addOption('start', null, InputOption::VALUE_REQUIRED, 'Only activities created before this date will be listed')
6161
->addOption('state', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter activities by state: in_progress, pending, complete, or cancelled.' . "\n" . ArrayArgument::SPLIT_HELP)
6262
->addOption('result', null, InputOption::VALUE_REQUIRED, 'Filter activities by result: success or failure')
@@ -151,7 +151,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
151151
if (!$table->formatIsMachineReadable()) {
152152
$executable = $this->config()->get('application.executable');
153153

154-
$max = $input->getOption('limit') ? (int) $input->getOption('limit') : 10;
154+
// TODO make this more deterministic by fetching limit+1 activities
155+
$max = ((int) $input->getOption('limit') ?: self::DEFAULT_LIST_LIMIT);
155156
$maybeMoreAvailable = count($activities) === $max;
156157
if ($maybeMoreAvailable) {
157158
$this->stdErr->writeln('');

src/Command/Activity/ActivityLogCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7171
$activity = $this->getSelectedProject()
7272
->getActivity($id);
7373
if (!$activity) {
74-
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, 10) ?: [], 'Activity');
74+
$activity = $this->api()->matchPartialId($id, $loader->loadFromInput($apiResource, $input, self::DEFAULT_FIND_LIMIT) ?: [], 'Activity');
7575
if (!$activity) {
7676
$this->stdErr->writeln("Activity not found: <error>$id</error>");
7777

src/Command/Integration/Activity/IntegrationActivityListCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Platformsh\Cli\Command\Integration\Activity;
44

5+
use Platformsh\Cli\Command\Activity\ActivityCommandBase;
56
use Platformsh\Cli\Command\Integration\IntegrationCommandBase;
67
use Platformsh\Cli\Console\AdaptiveTableCell;
78
use Platformsh\Cli\Console\ArrayArgument;
@@ -50,7 +51,7 @@ protected function configure()
5051
. "\n" . ArrayArgument::SPLIT_HELP
5152
. "\nThe % or * characters can be used as a wildcard to exclude types."
5253
)
53-
->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Limit the number of results displayed', 10)
54+
->addOption('limit', null, InputOption::VALUE_REQUIRED, 'Limit the number of results displayed', ActivityCommandBase::DEFAULT_LIST_LIMIT)
5455
->addOption('start', null, InputOption::VALUE_REQUIRED, 'Only activities created before this date will be listed')
5556
->addOption('state', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Filter activities by state.' . "\n" . ArrayArgument::SPLIT_HELP)
5657
->addOption('result', null, InputOption::VALUE_REQUIRED, 'Filter activities by result')
@@ -123,7 +124,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
123124
if (!$table->formatIsMachineReadable()) {
124125
$executable = $this->config()->get('application.executable');
125126

126-
$max = $input->getOption('limit') ? (int) $input->getOption('limit') : 10;
127+
$max = $input->getOption('limit') ? (int) $input->getOption('limit') : ActivityCommandBase::DEFAULT_LIST_LIMIT;
127128
$maybeMoreAvailable = count($activities) === $max;
128129
if ($maybeMoreAvailable) {
129130
$this->stdErr->writeln('');

0 commit comments

Comments
 (0)