also looking at this
fix(gitlab): read a job trace as text, so ciLogs is not a lie
#1421
2 files
+56
-4
| @@ -204,9 +204,9 @@ export class GitLabProvider implements GitProvider { | ||
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** A request whose 404 is an answer rather than an error. */ |
| 207 | private async optional<T>(method: string, path: string): Promise<T | null> { | |
| 207 | private async optional<T>(method: string, path: string, options: { raw?: boolean } = {}): Promise<T | null> { | |
| 208 | 208 | try { |
| 209 | return await this.request<T>(method, path) | |
| 209 | return await this.request<T>(method, path, undefined, options) | |
| 210 | 210 | } |
| 211 | 211 | catch (error) { |
| 212 | 212 | if (String(error).includes('404')) |
| @@ -651,8 +651,15 @@ export class GitLabProvider implements GitProvider { | ||
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | async getWorkflowRunLogs(runId: number): Promise<string | null> { |
| 654 | return this.optional<string>('GET', `/projects/${this.projectId}/jobs/${runId}/trace`) | |
| 655 | .catch(() => null) | |
| 654 | // `raw`, because a job trace is plain text. Without it the transport ran | |
| 655 | // `JSON.parse` over the log, threw on the first line that was not JSON — | |
| 656 | // which is every line — and the catch below reported that as "no logs". | |
| 657 | // GitLab declared `ciLogs: true` and could not return one. | |
| 658 | return this.optional<string>('GET', `/projects/${this.projectId}/jobs/${runId}/trace`, { raw: true }) | |
| 659 | .catch((error) => { | |
| 660 | this.logger.debug(`Could not read the trace for job ${runId}: ${formatError(error)}`) | |
| 661 | return null | |
| 662 | }) | |
| 656 | 663 | } |
| 657 | 664 | |
| 658 | 665 | /** |