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

feat: include CR envs enabled on creation in event and update validation #6931

Merged
merged 14 commits into from
Apr 26, 2024

Conversation

thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Apr 25, 2024

This PR improves the handling of change request enables on project creation in two ways:

  1. We now verify that the envs you try to enable CRs for exist before passing them on to the enterprise functionality.
  2. We include data about environments and change request environments in the project created events.

Copy link

vercel bot commented Apr 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 5:18am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ⬜️ Ignored (Inspect) Visit Preview Apr 26, 2024 5:18am

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

src/lib/features/project/project-service.ts Show resolved Hide resolved
src/lib/features/project/project-service.ts Show resolved Hide resolved
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Comment on lines +21 to +27
environments: joi.array().items(joi.string()),
changeRequestEnvironments: joi.array().items(
joi.object({
name: joi.string(),
requiredApprovals: joi.number(),
}),
),
Copy link
Contributor Author

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.

src/lib/features/project/project-service.ts Outdated Show resolved Hide resolved
Comment on lines 323 to 341
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 = [];
}
}
Copy link
Contributor Author

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:

  1. Only call this method if we're on enterprise (and if the flag is enabled)
  2. 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.
  3. Assume that the function will return the list of environments and their required approvals.
  4. 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.

@thomasheartman thomasheartman changed the title chore: throw if invalid envs are specified for cr envs feat: include CR envs enabled on creation in event and update validation Apr 25, 2024
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Data is typed as `any` which is *not good* and made one of the
function calls be invalid
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Copy link
Member

@Tymek Tymek left a 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

@thomasheartman
Copy link
Contributor Author

Right! Can you explain what the case is; I'm not sure I understand. No environments or no change request environments?

@Tymek
Copy link
Member

Tymek commented Apr 25, 2024

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

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

@thomasheartman thomasheartman merged commit 3fb5373 into main Apr 26, 2024
8 checks passed
@thomasheartman thomasheartman deleted the chore/add-more-validation-to-cr-enablement branch April 26, 2024 05:21
@thomasheartman
Copy link
Contributor Author

Okay! Are you asking about missing environments or an empty list? Either way, I'm pretty sure they're covered in the e2e tests in enterprise.

thomasheartman added a commit that referenced this pull request Apr 29, 2024
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;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants