@@ -32,11 +32,19 @@ const RawUserSchema = Schema.Struct({
3232} ) ;
3333
3434const RawPipelineSchema = Schema . Struct ( {
35+ id : Schema . optional ( Schema . NullOr ( Schema . Int ) ) ,
36+ project_id : Schema . optional ( Schema . NullOr ( Schema . Int ) ) ,
3537 status : Schema . optional ( Schema . NullOr ( Schema . String ) ) ,
3638 web_url : Schema . optional ( Schema . NullOr ( Schema . String ) ) ,
3739 source : Schema . optional ( Schema . NullOr ( Schema . String ) ) ,
3840} ) ;
3941
42+ const RawTriggerJobSchema = Schema . Struct ( {
43+ name : Schema . String ,
44+ allow_failure : Schema . optional ( Schema . NullOr ( Schema . Boolean ) ) ,
45+ downstream_pipeline : Schema . optional ( Schema . NullOr ( RawPipelineSchema ) ) ,
46+ } ) ;
47+
4048const RawMergeRequestSchema = Schema . Struct ( {
4149 iid : Schema . Int ,
4250 title : Schema . String ,
@@ -198,6 +206,8 @@ export interface GitLabMergeRequestDetail extends GitLabMergeRequestListItem {
198206 /** Absent means not counted, not up to date. */
199207 readonly divergedCommits ?: number ;
200208 readonly headSha ?: string ;
209+ /** On a fork the pipeline often belongs to the source project, not the target. */
210+ readonly headPipeline ?: { readonly id : number ; readonly projectId : number } ;
201211}
202212
203213function toActor ( raw : Schema . Schema . Type < typeof RawUserSchema > | null | undefined ) {
@@ -331,12 +341,16 @@ function toDetail(raw: Schema.Schema.Type<typeof RawMergeRequestSchema>): GitLab
331341 : { } ) ,
332342 ...( raw . diverged_commits_count == null ? { } : { divergedCommits : raw . diverged_commits_count } ) ,
333343 ...( headSha === null ? { } : { headSha } ) ,
344+ ...( raw . head_pipeline ?. id == null || raw . head_pipeline . project_id == null
345+ ? { }
346+ : { headPipeline : { id : raw . head_pipeline . id , projectId : raw . head_pipeline . project_id } } ) ,
334347 } ;
335348}
336349
337350const decodeUnknownList = decodeJsonResult ( Schema . Array ( Schema . Unknown ) ) ;
338351const decodeMergeRequestEntry = Schema . decodeUnknownExit ( RawMergeRequestSchema ) ;
339352const decodeMergeRequest = decodeJsonResult ( RawMergeRequestSchema ) ;
353+ const decodeTriggerJobEntry = Schema . decodeUnknownExit ( RawTriggerJobSchema ) ;
340354const decodeNoteEntry = Schema . decodeUnknownExit ( RawNoteSchema ) ;
341355const decodeUserEntry = Schema . decodeUnknownExit ( RawUserSchema ) ;
342356const decodeCommitEntry = Schema . decodeUnknownExit ( RawCommitSchema ) ;
@@ -396,6 +410,42 @@ export function decodeMergeRequestDetailJson(
396410 : Result . fail ( decoded . failure ) ;
397411}
398412
413+ export interface GitLabTriggerJobChecks {
414+ readonly checks : ReadonlyArray < PullRequestCheck > ;
415+ readonly rawCount : number ;
416+ }
417+
418+ /**
419+ * Without `strategy: depend` a trigger job succeeds as soon as it starts its downstream
420+ * pipeline, so the head pipeline stays green when that pipeline fails. Each row carries the
421+ * downstream pipeline's own status instead of the trigger job's.
422+ */
423+ export function decodeTriggerJobChecksJson (
424+ raw : string ,
425+ ) : Result . Result < GitLabTriggerJobChecks , DecodeFailure > {
426+ const decoded = decodeUnknownList ( raw ) ;
427+ if ( ! Result . isSuccess ( decoded ) ) {
428+ return Result . fail ( decoded . failure ) ;
429+ }
430+ const checks : PullRequestCheck [ ] = [ ] ;
431+ for ( const entry of decoded . success ) {
432+ const job = decodeTriggerJobEntry ( entry ) ;
433+ if ( Exit . isFailure ( job ) ) continue ;
434+ const name = trimmed ( job . value . name ) ;
435+ const downstream = job . value . downstream_pipeline ;
436+ if ( name === null || ! downstream ) continue ;
437+ const status = toPipelineStatus ( downstream . status ) ;
438+ checks . push ( {
439+ name,
440+ // The same reading as `manual`: GitLab was told this failure does not fail the pipeline.
441+ status : status === "failure" && job . value . allow_failure === true ? "neutral" : status ,
442+ description : "Downstream pipeline" ,
443+ url : trimmed ( downstream . web_url ) ,
444+ } ) ;
445+ }
446+ return Result . succeed ( { checks, rawCount : decoded . success . length } ) ;
447+ }
448+
399449export function decodeViewerJson ( raw : string ) : Result . Result < string | null , DecodeFailure > {
400450 const decoded = decodeViewer ( raw ) ;
401451 return Result . isSuccess ( decoded )
0 commit comments