From b45ad82bac9589e31056a73b8973ed4a4ce553f0 Mon Sep 17 00:00:00 2001 From: Tiffany K Date: Tue, 2 Apr 2024 10:43:51 -0700 Subject: [PATCH] fix: Cannot fetch builds based on pipelineId (#621) --- lib/pipeline.js | 11 ++++++++++- test/lib/pipeline.test.js | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/pipeline.js b/lib/pipeline.js index af65d910..0adb2afe 100644 --- a/lib/pipeline.js +++ b/lib/pipeline.js @@ -1715,9 +1715,18 @@ class PipelineModel extends BaseModel { delete config.params.latest; } + // Fetch jobs for this pipeline + const jobs = await this.getJobs({ + params: { + pipelineId: this.id, + archived: false + } + }); + const jobIds = jobs.map(j => j.id); + // Fetch builds for this pipeline with default count and page (implicitly set to 1) const defaultConfig = { - params: { pipelineId: this.id }, + params: { jobId: jobIds }, paginate: { count: DEFAULT_COUNT }, diff --git a/test/lib/pipeline.test.js b/test/lib/pipeline.test.js index 22078c6a..9a849ca6 100644 --- a/test/lib/pipeline.test.js +++ b/test/lib/pipeline.test.js @@ -2618,6 +2618,13 @@ describe('Pipeline Model', () => { ]; const groupEventId = 999; + beforeEach(() => { + getUserPermissionMocks({ username: 'janedoe', push: true }); + getUserPermissionMocks({ username: 'johnsmith', push: true }); + pipeline.admins = { janedoe: true, johnsmith: true }; + scmMock.getOpenedPRs.resolves([pr3Info, pr10Info]); + }); + it('gets a list of builds by groupEventId', () => { const expected = { params: { groupEventId } @@ -2667,11 +2674,12 @@ describe('Pipeline Model', () => { it('gets a list of builds with default pagination', () => { const expected = { - params: { pipelineId: 123 }, + params: { jobId: [99999, 99998, 99996, 99997] }, paginate: { count: 10 }, sort: 'descending' }; + jobFactoryMock.list.resolves([publishJob, mainJob, pr10, pr3]); buildFactoryMock.list.resolves(builds); return pipeline.getBuilds({}).then(result => { @@ -2682,11 +2690,12 @@ describe('Pipeline Model', () => { it('gets a list of builds and does not pass through latest when groupEventId not set', () => { const expected = { - params: { pipelineId: 123 }, + params: { jobId: [99999, 99998, 99996, 99997] }, paginate: { count: 300, page: 2 }, sort: 'descending' }; + jobFactoryMock.list.resolves([publishJob, mainJob, pr10, pr3]); buildFactoryMock.list.resolves(builds); return pipeline.getBuilds({ params: { latest: true }, paginate: { count: 300, page: 2 } }).then(result => { @@ -2696,6 +2705,7 @@ describe('Pipeline Model', () => { }); it('rejects with errors', () => { + jobFactoryMock.list.resolves([publishJob, mainJob, pr10, pr3]); buildFactoryMock.list.rejects(new Error('cannotgetit')); return pipeline