ReviewOS

also looking at this

stacks/buddy

fix(gitlab): read a job trace as text, so ciLogs is not a lie

#1421
Merged glennmichael123 wants to merge fix/gitlab-job-trace into main
2 files +56 -4
src/git/gitlab-provider.tsmodified+11-4
Changes to src/git/gitlab-provider.ts
@@ -204,9 +204,9 @@ export class GitLabProvider implements GitProvider {
204204 }
205205
206206 /** 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> {
208208 try {
209 return await this.request<T>(method, path)
209 return await this.request<T>(method, path, undefined, options)
210210 }
211211 catch (error) {
212212 if (String(error).includes('404'))
@@ -651,8 +651,15 @@ export class GitLabProvider implements GitProvider {
651651 }
652652
653653 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 })
656663 }
657664
658665 /**