Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(3235): Fetch parentEvent meta when create Event #3256

Merged
merged 4 commits into from
Dec 20, 2024
Merged

Conversation

kumada626
Copy link
Contributor

@kumada626 kumada626 commented Dec 17, 2024

Context

When restart build was failed in sd-setup-init step and restart build from that build, meta is missing at that time.
So we fix this behavior by fetching parent event meta when creating event.

Objective

Fetch parent event meta when creating event.

References

#3225

License

I confirm that this contribution is made under a BSD license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

@coveralls
Copy link

coveralls commented Dec 17, 2024

Coverage Status

coverage: 95.329% (+0.008%) from 95.321%
when pulling 065df39 on fetch-parent-meta
into 7c71738 on master.

y-oksaku
y-oksaku previously approved these changes Dec 17, 2024
Comment on lines 227 to 241
let mergedParameters = {};

payload.baseBranch = parentEvent.baseBranch || null;

if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
payload.meta.parameters = parentEvent.meta.parameters;
mergedParameters = parentEvent.meta.parameters;
}

if (Object.keys(payload.meta).length === 0) {
payload.meta = { ...parentEvent.meta };
}

if (Object.keys(mergedParameters).length > 0) {
payload.meta.parameters = mergedParameters;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about make this more simplified?

Suggested change
let mergedParameters = {};
payload.baseBranch = parentEvent.baseBranch || null;
if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
payload.meta.parameters = parentEvent.meta.parameters;
mergedParameters = parentEvent.meta.parameters;
}
if (Object.keys(payload.meta).length === 0) {
payload.meta = { ...parentEvent.meta };
}
if (Object.keys(mergedParameters).length > 0) {
payload.meta.parameters = mergedParameters;
}
// Merge parameters if they exist in the parent event and not in the payload
if (!payload.meta.parameters && parentEvent.meta && parentEvent.meta.parameters) {
payload.meta.parameters = parentEvent.meta.parameters;
}
// Copy meta from parent event if payload.meta is empty
if (Object.keys(payload.meta).length === 0) {
payload.meta = { ...parentEvent.meta };
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If payload(RestartedEevnt) only has parameters in meta, I think your suggested method will not fetch parentEvent meta (and neither will my method).
I will have fixed this bug.

Copy link
Member

@VonnyJap VonnyJap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check my suggestion

@VonnyJap
Copy link
Member

@kumada626 - can you also add couple of functional tests
https://github.com/screwdriver-cd/screwdriver/blob/master/features/metadata.feature
Changes to metadata behavior can be crucial and we should add some functional tests to make sure that it is working as intended if possible.

@kumada626
Copy link
Contributor Author

@VonnyJap Since this change does not alter normal behavior, it would be difficult to add it as a functional test.
This change is to fix the case of a restart from a build that failed in setup-init of a build due to some temporary environmental factors, so if we can guarantee that the normal behavior has not changed, there should be no problem.

@VonnyJap VonnyJap merged commit 696ce8c into master Dec 20, 2024
2 checks passed
@VonnyJap VonnyJap deleted the fetch-parent-meta branch December 20, 2024 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants