@@ -112,22 +112,37 @@ public function filesModified() : int {
112
112
return $ this ->stats ()['changed_files ' ];
113
113
}
114
114
115
- public function failedCIjobs () : array {
115
+ public function failedCIjobs (string $ hash ) : array {
116
116
[$ 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 ();
119
120
120
121
$ failed = [];
121
122
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
+ }
131
146
}
132
147
}
133
148
}
0 commit comments