Skip to content

Commit

Permalink
fix fetch logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kumada626 committed Dec 19, 2024
1 parent 2aca07b commit c7f6c8d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion plugins/events/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,17 @@ module.exports = () => ({
// Skip PR, for PR builds, we should always start from latest commit
if (payload.parentEventId) {
const parentEvent = await eventFactory.get(parentEventId);
let mergedParameters = {};
let mergedParameters = payload.meta.parameters || {};

payload.baseBranch = parentEvent.baseBranch || null;

// Merge parameters if they exist in the parent event and not in the payload
if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
mergedParameters = parentEvent.meta.parameters;
}
delete payload.meta.parameters;

// Copy meta from parent event if payload.meta is empty except for the parameters
if (Object.keys(payload.meta).length === 0) {
payload.meta = { ...parentEvent.meta };
}
Expand Down
12 changes: 8 additions & 4 deletions test/plugins/events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,18 @@ describe('event plugin test', () => {
one: 1
};
eventConfig.configPipelineSha = 'configPipelineSha';
eventConfig.meta.parameters = {
user: { value: 'klu' },
eventConfig.meta = {
parameters: {
user: { value: 'klu' }
},
foo: 'bar',
one: 1
};
options.payload.parentEventId = parentEventId;
options.payload.meta.parameters = {
user: { value: 'klu' }
options.payload.meta = {
parameters: {
user: { value: 'klu' }
}
};
eventFactoryMock.get.withArgs(parentEventId).resolves(getEventMock(testEvent));

Expand Down

0 comments on commit c7f6c8d

Please sign in to comment.