Skip to content

Commit

Permalink
fix: Cannot fetch builds based on pipelineId (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi authored Apr 2, 2024
1 parent 8a2f1af commit b45ad82
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
14 changes: 12 additions & 2 deletions test/lib/pipeline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 => {
Expand All @@ -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 => {
Expand All @@ -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
Expand Down

0 comments on commit b45ad82

Please sign in to comment.