-
-
Notifications
You must be signed in to change notification settings - Fork 662
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
feat: include CR envs enabled on creation in event and update validation #6931
feat: include CR envs enabled on creation in event and update validation #6931
Conversation
This propagates those properties to the event etc.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
environments: joi.array().items(joi.string()), | ||
changeRequestEnvironments: joi.array().items( | ||
joi.object({ | ||
name: joi.string(), | ||
requiredApprovals: joi.number(), | ||
}), | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make sure this data is propagated to the event store.
if ( | ||
this.isEnterprise && | ||
this.flagResolver.isEnabled('createProjectWithEnvironmentConfig') | ||
) { | ||
if (data.changeRequestEnvironments) { | ||
await this.validateEnvironmentsExist( | ||
data.changeRequestEnvironments, | ||
); | ||
const changeRequestEnvironments = | ||
await enableChangeRequestsForSpecifiedEnvironments( | ||
data.changeRequestEnvironments, | ||
); | ||
|
||
data.changeRequestEnvironments = | ||
changeRequestEnvironments ?? []; | ||
} else { | ||
data.changeRequestEnvironments = []; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the meat of the change. I've done a few things here:
- Only call this method if we're on enterprise (and if the flag is enabled)
- Validate the data in OSS before passing it to the function. That keeps all validation in one place and we can safely assume that all envs passed into the function are valid.
- Assume that the function will return the list of environments and their required approvals.
- If we're on enterprise and you didn't provide any change request environments, then we'll return an empty list to indicate that no envs were set up.
This means that when we call this in enterprise, there's less worrying about logic and that the data is valid. Instead, it's a function that takes an input and yields an output. In addition to putting all the heavy logic in one place, it also makes it easier to test all of this in one spot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
Data is typed as `any` which is *not good* and made one of the function calls be invalid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I didn't see a test for trying to add a project with no environments, but I'm not sure if we need it
Right! Can you explain what the case is; I'm not sure I understand. No environments or no change request environments? |
No environments. Not related directly to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
Okay! Are you asking about missing |
This PR removes the workaround introduced in #6931. After ivarconr/unleash-enterprise#1268 has been merged, this should be safe to apply. Notably, this PR: - tightens up the type for the enable change request function, so we can use that to inform the code - skips trying to do anything with an empty array The last point is less important than it might seem because both the env validation and the current implementation of the callback is essentially a no-op when there are no envs. However, that's hard to enforce. If we just exit out early, then at least we know nothing happens. Optionally, we could do something like this instead, but I'm not sure it's better or worse. Happy to take input. ```ts const crEnvs = newProject.changeRequestEnvironments ?? [] await this.validateEnvironmentsExist(crEnvs.map((env) => env.name)); const changeRequestEnvironments = await enableChangeRequestsForSpecifiedEnvironments(crEnvs,); data.changeRequestEnvironments = changeRequestEnvironments; ```
This PR improves the handling of change request enables on project creation in two ways: