@@ -286,7 +286,7 @@ export class GitLab extends AbstractSCM implements SourceControlManagement {
286286 * @param mergeRequestIId The merge request IID. Can be found in the URL to a pipeline
287287 */
288288 @func ( )
289- async getLatestMergeRequestPipeline ( gitlabProjectId : string | number , mergeRequestIId : number ) : Promise < PipelineWithJobs | null > {
289+ async getMergeRequestLatestPipeline ( gitlabProjectId : string | number , mergeRequestIId : number ) : Promise < PipelineWithJobs | null > {
290290 // allPipelines<E extends boolean = false>(projectId: string | number, mergerequestIId: number, options?: Sudo & ShowExpanded<E>): Promise<GitlabAPIResponse<Pick<PipelineSchema, 'id' | 'sha' | 'ref' | 'status'>[], C, E, void>>;
291291 const pipelines = await this . api ( ) . MergeRequests . allPipelines ( gitlabProjectId , mergeRequestIId ) ;
292292 if ( pipelines . length === 0 ) return null ;
@@ -330,28 +330,23 @@ export class GitLab extends AbstractSCM implements SourceControlManagement {
330330 /**
331331 * Gets the logs from the jobs which have failed in a pipeline
332332 * @param gitlabProjectId GitLab project full path or the numeric id
333- * @param mergeRequestIId The merge request IID . Can get this from the URL of the merge request . https://<gitlab-host>/<group>/[<sub-group>/]<project>/-/merge_requests/<mergeRequestIId >
333+ * @param pipelineId The pipelineId . Can be determined from the URL of a pipeline . https://<gitlab-host>/<group>/[<sub-group>/]<project>/-/pipelines/<pipelineId >
334334 * @returns A Record with the job name as the key and the logs as the value.
335335 */
336336 @func ( )
337- async getMergeRequestPipelineFailedJobLogs ( gitlabProjectId : string | number , mergeRequestIId : number ) : Promise < string > {
338- logger . info ( { gitlabProjectId, mergeRequestIId } , 'Getting pipelines' ) ;
339- const pipelines = await this . api ( ) . MergeRequests . allPipelines ( gitlabProjectId , mergeRequestIId ) ;
340- if ( pipelines . length === 0 ) throw new Error ( 'No pipelines for the merge request' ) ;
337+ async getPipelineFailedJobLogs ( gitlabProjectId : string | number , pipelineId : number ) : Promise < string > {
338+ logger . info ( { gitlabProjectId, pipelineId } , 'Getting pipeline' ) ;
339+ const pipeline = await this . api ( ) . Pipelines . show ( gitlabProjectId , pipelineId ) ;
341340
342- // pipelines.sort((a, b) => (Date.parse(a.created_at) < Date.parse(b.created_at) ? 1 : -1));
343- const latestPipeline = pipelines . at ( 0 ) ;
344- if ( ! latestPipeline ) throw new Error ( 'No pipelines for the merge request' ) ;
345-
346- if ( latestPipeline . status !== 'failed' && latestPipeline . status !== 'blocked' ) throw new Error ( 'Pipeline is not failed or blocked' ) ;
341+ if ( pipeline . status !== 'failed' && pipeline . status !== 'blocked' ) throw new Error ( `Pipeline status is not failed or blocked. Status: ${ pipeline . status } ` ) ;
347342
348- logger . info ( { gitlabProjectId, pipelineId : latestPipeline . id } , 'Getting jobs' ) ;
349- const jobs : JobSchema [ ] = await this . api ( ) . Jobs . all ( gitlabProjectId , { pipelineId : latestPipeline . id } ) ;
343+ logger . info ( { gitlabProjectId, pipelineId : pipeline . id } , 'Getting jobs' ) ;
344+ const jobs : JobSchema [ ] = await this . api ( ) . Jobs . all ( gitlabProjectId , { pipelineId : pipeline . id } ) ;
350345 const failedJobs = jobs . filter ( ( job ) => job . status === 'failed' && job . allow_failure === false ) ;
351346
352347 let jobLogs = '' ;
353348 for ( const job of failedJobs ) {
354- logger . info ( { gitlabProjectId, pipelineId : latestPipeline . id , jobId : job . id } , 'Getting job logs' ) ;
349+ logger . info ( { gitlabProjectId, pipelineId : pipeline . id , jobId : job . id } , 'Getting job logs' ) ;
355350 let logs = await this . getJobLogs ( gitlabProjectId , job . id . toString ( ) ) ;
356351
357352 // If the logs are longer than ~12,000 tokens, truncate them.
@@ -365,6 +360,25 @@ export class GitLab extends AbstractSCM implements SourceControlManagement {
365360 return jobLogs ;
366361 }
367362
363+ /**
364+ * Gets the logs from the jobs which have failed in the latest pipeline of a merge request
365+ * @param gitlabProjectId GitLab project full path or the numeric id
366+ * @param mergeRequestIId The merge request IID. Can get this from the URL of the merge request. https://<gitlab-host>/<group>/[<sub-group>/]<project>/-/merge_requests/<mergeRequestIId>
367+ * @returns A Record with the job name as the key and the logs as the value.
368+ */
369+ @func ( )
370+ async getMergeRequestPipelineFailedJobLogs ( gitlabProjectId : string | number , mergeRequestIId : number ) : Promise < string > {
371+ logger . info ( { gitlabProjectId, mergeRequestIId } , 'Getting pipelines' ) ;
372+ const pipelines = await this . api ( ) . MergeRequests . allPipelines ( gitlabProjectId , mergeRequestIId ) ;
373+ if ( pipelines . length === 0 ) throw new Error ( 'No pipelines for the merge request' ) ;
374+
375+ // pipelines.sort((a, b) => (Date.parse(a.created_at) < Date.parse(b.created_at) ? 1 : -1));
376+ const latestPipeline = pipelines . at ( 0 ) ;
377+ if ( ! latestPipeline ) throw new Error ( 'No pipelines for the merge request' ) ;
378+
379+ return this . getPipelineFailedJobLogs ( gitlabProjectId , latestPipeline . id ) ;
380+ }
381+
368382 /**
369383 * @returns the diffs for a merge request
370384 */
0 commit comments