Skip to content

Commit 6f027a3

Browse files
committed
more work towards #33 to track CI failures
1 parent 4dd058e commit 6f027a3

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

entities/GitHub/GitHubPullRequest.php

+27-12
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,37 @@ public function filesModified() : int {
112112
return $this->stats()['changed_files'];
113113
}
114114

115-
public function failedCIjobs() : array {
115+
public function failedCIjobs(string $hash) : array {
116116
[$org, $repo] = GitHubRepository::getRepo($this->repository->name());
117-
$pr = $GLOBALS['github_client']->api('pr');
118-
$checks = $GLOBALS['github_client']->api('repo')->checkRuns();
117+
$status = $GLOBALS['github_client']->api('repo')->statuses();
118+
$actions = $GLOBALS['github_client']->api('repo')->workflowRuns();
119+
$jobs = $GLOBALS['github_client']->api('repo')->workflowJobs();
119120

120121
$failed = [];
121122

122-
foreach ($pr->commits($org, $repo, $this->number) as $commit) {
123-
$cks = $checks->allForReference($org, $repo, $commit['sha']);
124-
foreach ($cks['check_runs'] as $check) {
125-
if ($check['conclusion'] == 'failure') {
126-
$failed[] = [
127-
'name' => $check['name'],
128-
'commit' => $commit['sha'],
129-
'time' => github_parse_date($check['completed_at'])
130-
];
123+
// get status of 3rd-party checks
124+
foreach ($status->combined($org, $repo, $hash)['statuses'] as $check) {
125+
if ($check['state'] == 'failure') {
126+
$failed[] = [
127+
'name' => $check['context'],
128+
'time' => github_parse_date($check['updated_at'])
129+
];
130+
}
131+
}
132+
133+
// get status of GitHub Actions checks
134+
$runs = $actions->all($org, $repo, ['head_sha' => $hash]);
135+
foreach ($runs['workflow_runs'] as $check) {
136+
if ($check['conclusion'] == 'failure') {
137+
// Each action can have multiple jobs
138+
// Fetch the names of the specific jobs that failed
139+
foreach ($jobs->all($org, $repo, $check['id'])['jobs'] as $job) {
140+
if ($job['conclusion'] == 'failure') {
141+
$failed[] = [
142+
'name' => $job['name'],
143+
'time' => github_parse_date($job['completed_at'])
144+
];
145+
}
131146
}
132147
}
133148
}

entities/PullRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ abstract public function mergeDate() : \DateTimeImmutable;
1616
abstract public function linesAdded() : int;
1717
abstract public function linesDeleted() : int;
1818
abstract public function filesModified() : int;
19-
abstract public function failedCIjobs() : array; // [name, time]
19+
abstract public function failedCIjobs(string $hash) : array; // [name, time]
2020
abstract public function __toString();
2121
}

0 commit comments

Comments
 (0)