Skip to content

Commit ccb0e8e

Browse files
committed
refactor: createCheckRun for initial status only, conclusion via updateCheckRun; add actions param
1 parent 49dc894 commit ccb0e8e

3 files changed

Lines changed: 23 additions & 27 deletions

File tree

src/VCS/Adapter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,12 @@ abstract public function updateCommitStatus(string $repositoryName, string $SHA,
237237

238238
/**
239239
* Creates a check run for a commit.
240-
* status can be one of: queued, in_progress, completed
241-
* conclusion (required when status=completed) can be one of: action_required, cancelled, failure, neutral, success, skipped, timed_out
240+
* status can be one of: queued, in_progress
241+
* Use updateCheckRun() to set conclusion and mark the run as completed.
242242
*
243243
* @param array<mixed> $annotations
244244
* @param array<mixed> $images
245+
* @param array<mixed> $actions
245246
* @return array<mixed>
246247
*/
247248
public function createCheckRun(
@@ -250,16 +251,15 @@ public function createCheckRun(
250251
string $headSha,
251252
string $name,
252253
string $status = 'queued',
253-
string $conclusion = '',
254254
string $title = '',
255255
string $summary = '',
256256
string $text = '',
257257
array $annotations = [],
258258
array $images = [],
259+
array $actions = [],
259260
string $detailsUrl = '',
260261
string $externalId = '',
261262
string $startedAt = '',
262-
string $completedAt = '',
263263
): array {
264264
throw new \Exception('createCheckRun() is not implemented for ' . $this->getName());
265265
}
@@ -281,6 +281,7 @@ public function getCheckRun(string $owner, string $repositoryName, int $checkRun
281281
*
282282
* @param array<mixed> $annotations
283283
* @param array<mixed> $images
284+
* @param array<mixed> $actions
284285
* @return array<mixed>
285286
*/
286287
public function updateCheckRun(
@@ -295,6 +296,7 @@ public function updateCheckRun(
295296
string $text = '',
296297
array $annotations = [],
297298
array $images = [],
299+
array $actions = [],
298300
string $detailsUrl = '',
299301
string $externalId = '',
300302
string $startedAt = '',

src/VCS/Adapter/Git/GitHub.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -874,11 +874,12 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
874874

875875
/**
876876
* Creates a check run for a commit.
877-
* status can be one of: queued, in_progress, completed
878-
* conclusion (required when status=completed) can be one of: action_required, cancelled, failure, neutral, success, skipped, timed_out
877+
* status can be one of: queued, in_progress
878+
* Use updateCheckRun() to set conclusion and mark the run as completed.
879879
*
880880
* @param array<mixed> $annotations
881881
* @param array<mixed> $images
882+
* @param array<mixed> $actions
882883
* @return array<mixed>
883884
*/
884885
public function createCheckRun(
@@ -887,27 +888,18 @@ public function createCheckRun(
887888
string $headSha,
888889
string $name,
889890
string $status = 'queued',
890-
string $conclusion = '',
891891
string $title = '',
892892
string $summary = '',
893893
string $text = '',
894894
array $annotations = [],
895895
array $images = [],
896+
array $actions = [],
896897
string $detailsUrl = '',
897898
string $externalId = '',
898899
string $startedAt = '',
899-
string $completedAt = '',
900900
): array {
901901
$url = "/repos/$owner/$repositoryName/check-runs";
902902

903-
// Conclusion requires status=completed; auto-set completed_at if not provided.
904-
if (!empty($conclusion)) {
905-
$status = 'completed';
906-
if (empty($completedAt)) {
907-
$completedAt = gmdate('Y-m-d\TH:i:s\Z');
908-
}
909-
}
910-
911903
$body = array_merge(
912904
[
913905
'name' => $name,
@@ -918,8 +910,6 @@ public function createCheckRun(
918910
'details_url' => $detailsUrl,
919911
'external_id' => $externalId,
920912
'started_at' => $startedAt,
921-
'conclusion' => $conclusion,
922-
'completed_at' => $completedAt,
923913
], fn ($value) => !empty($value))
924914
);
925915

@@ -935,6 +925,10 @@ public function createCheckRun(
935925
$body['output'] = $output;
936926
}
937927

928+
if (!empty($actions)) {
929+
$body['actions'] = $actions;
930+
}
931+
938932
$response = $this->call(self::METHOD_POST, $url, ['Authorization' => "Bearer $this->accessToken"], $body);
939933

940934
return $response['body'] ?? [];
@@ -975,6 +969,7 @@ public function updateCheckRun(
975969
string $text = '',
976970
array $annotations = [],
977971
array $images = [],
972+
array $actions = [],
978973
string $detailsUrl = '',
979974
string $externalId = '',
980975
string $startedAt = '',
@@ -1012,6 +1007,10 @@ public function updateCheckRun(
10121007
$body['output'] = $output;
10131008
}
10141009

1010+
if (!empty($actions)) {
1011+
$body['actions'] = $actions;
1012+
}
1013+
10151014
$response = $this->call(self::METHOD_PATCH, $url, ['Authorization' => "Bearer $this->accessToken"], $body);
10161015

10171016
return $response['body'] ?? [];

tests/VCS/Adapter/GitHubTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,22 +664,17 @@ public function testCreateCheckRun(): void
664664
repositoryName: $repositoryName,
665665
headSha: $commitHash,
666666
name: 'ci/build',
667-
status: 'completed',
668-
conclusion: 'neutral',
669-
title: 'Deployment skipped',
670-
summary: 'Deployment skipped because the commit message contains a skip pattern.',
671-
completedAt: gmdate('Y-m-d\TH:i:s\Z'),
667+
status: 'in_progress',
668+
startedAt: gmdate('Y-m-d\TH:i:s\Z'),
672669
);
673670

674671
$this->assertArrayHasKey('id', $checkRun);
675-
$this->assertEquals('completed', $checkRun['status']);
676-
$this->assertEquals('neutral', $checkRun['conclusion']);
672+
$this->assertEquals('in_progress', $checkRun['status']);
677673
$this->assertEquals('ci/build', $checkRun['name']);
678674

679675
$fetched = $this->vcsAdapter->getCheckRun(static::$owner, $repositoryName, $checkRun['id']);
680676
$this->assertEquals($checkRun['id'], $fetched['id']);
681-
$this->assertEquals('neutral', $fetched['conclusion']);
682-
$this->assertEquals('completed', $fetched['status']);
677+
$this->assertEquals('in_progress', $fetched['status']);
683678
} finally {
684679
$this->vcsAdapter->deleteRepository(static::$owner, $repositoryName);
685680
}

0 commit comments

Comments
 (0)