Skip to content

Commit 0690275

Browse files
committed
Fix runner command lint
1 parent f3d8c5b commit 0690275

4 files changed

Lines changed: 33 additions & 32 deletions

File tree

inc/Abilities/WorkspaceAbilities.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,7 +3070,7 @@ public static function publishRunnerWorkspace( array $input ): array|\WP_Error {
30703070
* @return array<string,mixed>|\WP_Error
30713071
*/
30723072
public static function runRunnerWorkspaceCommand( array $input ): array|\WP_Error {
3073-
$handle = trim( (string) ( $input['workspace_handle'] ?? $input['name'] ?? $input['repo'] ?? '' ) );
3073+
$handle = trim( (string) ( $input['workspace_handle'] ?? $input['name'] ?? $input['repo'] ?? '' ) );
30743074
$command = trim( (string) ( $input['command'] ?? '' ) );
30753075
$timeout = isset($input['timeout']) ? (int) $input['timeout'] : (int) ( $input['timeout_seconds'] ?? 300 );
30763076
$env = isset($input['env']) && is_array($input['env']) ? $input['env'] : array();
@@ -3158,22 +3158,22 @@ private static function runnerWorkspaceCommandOutputSchema(): array {
31583158
return array(
31593159
'type' => 'object',
31603160
'properties' => array(
3161-
'success' => array( 'type' => 'boolean' ),
3162-
'kind' => array( 'type' => 'string' ),
3163-
'backend' => array( 'type' => 'string' ),
3164-
'failure_type' => array( 'type' => array( 'string', 'null' ) ),
3165-
'name' => array( 'type' => 'string' ),
3166-
'repo' => array( 'type' => 'string' ),
3167-
'path' => array( 'type' => array( 'string', 'null' ) ),
3168-
'command' => array( 'type' => 'string' ),
3169-
'description' => array( 'type' => 'string' ),
3170-
'exit_code' => array( 'type' => array( 'integer', 'null' ) ),
3171-
'stdout' => array( 'type' => 'string' ),
3172-
'stderr' => array( 'type' => 'string' ),
3173-
'elapsed_ms' => array( 'type' => 'integer' ),
3174-
'timed_out' => array( 'type' => 'boolean' ),
3175-
'workspace' => array( 'type' => 'object' ),
3176-
'message' => array( 'type' => 'string' ),
3161+
'success' => array( 'type' => 'boolean' ),
3162+
'kind' => array( 'type' => 'string' ),
3163+
'backend' => array( 'type' => 'string' ),
3164+
'failure_type' => array( 'type' => array( 'string', 'null' ) ),
3165+
'name' => array( 'type' => 'string' ),
3166+
'repo' => array( 'type' => 'string' ),
3167+
'path' => array( 'type' => array( 'string', 'null' ) ),
3168+
'command' => array( 'type' => 'string' ),
3169+
'description' => array( 'type' => 'string' ),
3170+
'exit_code' => array( 'type' => array( 'integer', 'null' ) ),
3171+
'stdout' => array( 'type' => 'string' ),
3172+
'stderr' => array( 'type' => 'string' ),
3173+
'elapsed_ms' => array( 'type' => 'integer' ),
3174+
'timed_out' => array( 'type' => 'boolean' ),
3175+
'workspace' => array( 'type' => 'object' ),
3176+
'message' => array( 'type' => 'string' ),
31773177
),
31783178
);
31793179
}

inc/Support/ProcessRunner.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class ProcessRunner {
2626
*
2727
* @param string $command Shell command to execute.
2828
* @param array<string,mixed> $options Execution options.
29-
* @return array{success: bool, output: string, exit_code: int}|\WP_Error
29+
* @return array<string,mixed>|\WP_Error
3030
*/
3131
public static function run( string $command, array $options = array() ): array|\WP_Error {
3232
$timeout_seconds = max(0, (int) ( $options['timeout_seconds'] ?? 0 ));
@@ -53,7 +53,7 @@ public static function run( string $command, array $options = array() ): array|\
5353

5454
/**
5555
* @param array<string,mixed> $options
56-
* @return array{success: bool, output: string, exit_code: int}|\WP_Error
56+
* @return array<string,mixed>|\WP_Error
5757
*/
5858
private static function run_via_exec( string $command, array $options, int $output_cap ): array|\WP_Error {
5959
$shell = RuntimeCapabilities::shell_diagnostic();
@@ -87,7 +87,7 @@ private static function run_via_exec( string $command, array $options, int $outp
8787
* @param array<string,mixed> $options
8888
* @param callable|null $on_output
8989
* @param array<string,mixed>|null $env
90-
* @return array{success: bool, output: string, exit_code: int}|\WP_Error
90+
* @return array<string,mixed>|\WP_Error
9191
*/
9292
private static function run_via_proc_open( string $command, array $options, int $timeout_seconds, int $output_cap, ?callable $on_output, ?string $cwd, ?array $env ): array|\WP_Error {
9393
$descriptor_spec = array(
@@ -108,8 +108,8 @@ private static function run_via_proc_open( string $command, array $options, int
108108
$stdout = '';
109109
$stderr = '';
110110
$output = '';
111-
$deadline = $timeout_seconds > 0 ? microtime(true) + $timeout_seconds : null;
112-
$exit_code = null;
111+
$deadline = $timeout_seconds > 0 ? microtime(true) + $timeout_seconds : null;
112+
$exit_code = 0;
113113

114114
while ( true ) {
115115
$stdout_chunk = (string) stream_get_contents($pipes[1]);
@@ -126,7 +126,7 @@ private static function run_via_proc_open( string $command, array $options, int
126126

127127
$status = proc_get_status($process);
128128
if ( empty($status['running']) ) {
129-
$exit_code = isset($status['exitcode']) ? (int) $status['exitcode'] : null;
129+
$exit_code = (int) $status['exitcode'];
130130
break;
131131
}
132132

@@ -158,7 +158,7 @@ private static function run_via_proc_open( string $command, array $options, int
158158
}
159159

160160
$close_code = proc_close($process);
161-
if ( null === $exit_code ) {
161+
if ( -1 === $exit_code ) {
162162
$exit_code = $close_code;
163163
}
164164

@@ -236,6 +236,7 @@ private static function cap_output( string $output, int $output_cap ): string {
236236
/**
237237
* @param array<string,mixed> $options
238238
* @param array<string,mixed> $data
239+
* @return array<string,mixed>|\WP_Error
239240
*/
240241
private static function error( array $options, string $message, array $data = array() ): array|\WP_Error {
241242
if ( ! empty($options['error_as_result']) ) {

inc/Workspace/RemoteWorkspaceBackend.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,12 @@ public function run_command( string $handle, string $command, string $descriptio
689689
'elapsed_ms' => 0,
690690
'timed_out' => false,
691691
'workspace' => array(
692-
'handle' => $handle,
693-
'repo' => $context['repo_name'],
694-
'github_repo'=> $context['repo'],
695-
'branch' => $context['branch'],
696-
'backend' => 'github_api',
697-
'is_context' => ! empty($context['read_only_context']),
692+
'handle' => $handle,
693+
'repo' => $context['repo_name'],
694+
'github_repo' => $context['repo'],
695+
'branch' => $context['branch'],
696+
'backend' => 'github_api',
697+
'is_context' => ! empty($context['read_only_context']),
698698
),
699699
'message' => 'Runner workspace command execution is unavailable for GitHub API remote workspaces; use a local runner workspace backend for shell commands.',
700700
);

inc/Workspace/WorkspaceGitOperations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function run_runner_workspace_command( string $handle, string $command, s
182182
$base_env = $_ENV;
183183
}
184184

185-
$result = ProcessRunner::run(
185+
$result = ProcessRunner::run(
186186
$command,
187187
array(
188188
'cwd' => $workdir,
@@ -193,7 +193,7 @@ public function run_runner_workspace_command( string $handle, string $command, s
193193
'separate_streams' => true,
194194
)
195195
);
196-
$elapsed_ms = max(0, (int) round(( microtime(true) - $started ) * 1000));
196+
$elapsed_ms = max(0, (int) round(( microtime(true) - $started ) * 1000));
197197

198198
if ( is_wp_error($result) ) {
199199
return $result;

0 commit comments

Comments
 (0)