Loading src/desktop/gitlab/get_pipeline_and_mr_for_branch.test.ts +30 −3 Original line number Diff line number Diff line Loading @@ -19,16 +19,43 @@ describe('getPipelineAndMrForBranch', () => { { request: getPipelinesForMr(mr), response: [ { ...pipeline, iid: 1 }, { ...pipeline, iid: 2 }, { ...pipeline, iid: 4 }, { ...pipeline, iid: 5 }, ], }, { request: getPipelinesForRef(project, branchName), response: [{ ...pipeline, iid: 1 }], }, ), ); const { pipeline: p } = await getPipelineAndMrForBranch(fakeService, project, branchName); expect(p?.iid).toBe(5); }); it('returns branch pipeline if MR pipeline is outdated', async () => { const fakeService = new GitLabService({ instanceUrl: '', token: '' }); const branchName = 'branch-name'; jest.spyOn(fakeService, 'fetchFromApi').mockImplementation( createFakeFetchFromApi( { request: getMergeRequestsForBranch(project, branchName), response: [mr] }, { request: getPipelinesForMr(mr), response: [{ ...pipeline, iid: 2 }], }, { request: getPipelinesForRef(project, branchName), response: [{ ...pipeline, iid: 3 }], }, ), ); const { pipeline: p } = await getPipelineAndMrForBranch(fakeService, project, branchName); expect(p?.iid).toBe(2); expect(p?.iid).toBe(3); }); }); Loading src/desktop/gitlab/get_pipeline_and_mr_for_branch.ts +8 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ export const getPipelineAndMrForBranch = async ( }> => { // Use centralized MR lookup helper (handles normalization, selection, error handling) let mr: RestMr | undefined; let mrPipeline: RestPipeline | undefined; try { mr = (await findOpenMrForCurrentBranch(gitlabService, project, trackingBranchName)) || undefined; Loading @@ -39,8 +40,7 @@ export const getPipelineAndMrForBranch = async ( try { const pipelines = await gitlabService.fetchFromApi(getPipelinesForMr(mr)); if (pipelines && pipelines.length > 0) { const pipeline = sort(pipelines, (p1, p2) => p2.iid - p1.iid)[0]; return { mr, pipeline }; [mrPipeline] = sort(pipelines, (p1, p2) => p2.iid - p1.iid); } } catch (e) { handleApiError(e, `Failed to fetch pipelines for MR !${mr.iid}`); Loading @@ -52,9 +52,13 @@ export const getPipelineAndMrForBranch = async ( const pipelines = await gitlabService.fetchFromApi( getPipelinesForRef(project, trackingBranchName), ); return { mr, pipeline: pipelines?.[0] }; const branchPipeline = pipelines?.[0]; const pipeline = (mrPipeline?.iid ?? 0) > (branchPipeline?.iid ?? 0) ? mrPipeline : branchPipeline; return { mr, pipeline }; } catch (e) { handleApiError(e, `Failed to fetch pipelines for ref "${trackingBranchName}"`); return { mr }; return { mr, pipeline: mrPipeline }; } }; Loading
src/desktop/gitlab/get_pipeline_and_mr_for_branch.test.ts +30 −3 Original line number Diff line number Diff line Loading @@ -19,16 +19,43 @@ describe('getPipelineAndMrForBranch', () => { { request: getPipelinesForMr(mr), response: [ { ...pipeline, iid: 1 }, { ...pipeline, iid: 2 }, { ...pipeline, iid: 4 }, { ...pipeline, iid: 5 }, ], }, { request: getPipelinesForRef(project, branchName), response: [{ ...pipeline, iid: 1 }], }, ), ); const { pipeline: p } = await getPipelineAndMrForBranch(fakeService, project, branchName); expect(p?.iid).toBe(5); }); it('returns branch pipeline if MR pipeline is outdated', async () => { const fakeService = new GitLabService({ instanceUrl: '', token: '' }); const branchName = 'branch-name'; jest.spyOn(fakeService, 'fetchFromApi').mockImplementation( createFakeFetchFromApi( { request: getMergeRequestsForBranch(project, branchName), response: [mr] }, { request: getPipelinesForMr(mr), response: [{ ...pipeline, iid: 2 }], }, { request: getPipelinesForRef(project, branchName), response: [{ ...pipeline, iid: 3 }], }, ), ); const { pipeline: p } = await getPipelineAndMrForBranch(fakeService, project, branchName); expect(p?.iid).toBe(2); expect(p?.iid).toBe(3); }); }); Loading
src/desktop/gitlab/get_pipeline_and_mr_for_branch.ts +8 −4 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ export const getPipelineAndMrForBranch = async ( }> => { // Use centralized MR lookup helper (handles normalization, selection, error handling) let mr: RestMr | undefined; let mrPipeline: RestPipeline | undefined; try { mr = (await findOpenMrForCurrentBranch(gitlabService, project, trackingBranchName)) || undefined; Loading @@ -39,8 +40,7 @@ export const getPipelineAndMrForBranch = async ( try { const pipelines = await gitlabService.fetchFromApi(getPipelinesForMr(mr)); if (pipelines && pipelines.length > 0) { const pipeline = sort(pipelines, (p1, p2) => p2.iid - p1.iid)[0]; return { mr, pipeline }; [mrPipeline] = sort(pipelines, (p1, p2) => p2.iid - p1.iid); } } catch (e) { handleApiError(e, `Failed to fetch pipelines for MR !${mr.iid}`); Loading @@ -52,9 +52,13 @@ export const getPipelineAndMrForBranch = async ( const pipelines = await gitlabService.fetchFromApi( getPipelinesForRef(project, trackingBranchName), ); return { mr, pipeline: pipelines?.[0] }; const branchPipeline = pipelines?.[0]; const pipeline = (mrPipeline?.iid ?? 0) > (branchPipeline?.iid ?? 0) ? mrPipeline : branchPipeline; return { mr, pipeline }; } catch (e) { handleApiError(e, `Failed to fetch pipelines for ref "${trackingBranchName}"`); return { mr }; return { mr, pipeline: mrPipeline }; } };