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

chore: remove workaround #6942

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/lib/features/project/project-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ describe('enterprise extension: enable change requests', () => {
const project = await service.projectStore.get(projectId);

expect(project).toBeTruthy();

return [];
},
);
});
Expand Down Expand Up @@ -130,9 +132,7 @@ describe('enterprise extension: enable change requests', () => {
isAPI: false,
},
TEST_AUDIT_USER,
async () => {
[];
},
async () => [],
);
});

Expand Down Expand Up @@ -215,9 +215,7 @@ describe('enterprise extension: enable change requests', () => {
isAPI: false,
},
TEST_AUDIT_USER,
async () => {
return;
},
async () => [],
);

expect(result.changeRequestEnvironments).toStrictEqual([]);
Expand Down Expand Up @@ -245,9 +243,7 @@ describe('enterprise extension: enable change requests', () => {
isAPI: false,
},
TEST_AUDIT_USER,
async () => {
crEnvs;
},
async () => crEnvs,
);

expect('changeRequestEnvironments' in result).toBeFalsy();
Expand Down
28 changes: 15 additions & 13 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ export default class ProjectService {
enableChangeRequestsForSpecifiedEnvironments: (
environments: CreateProject['changeRequestEnvironments'],
) => Promise<
void | ProjectCreated['changeRequestEnvironments']
ProjectCreated['changeRequestEnvironments']
> = async () => {
return;
return [];
},
): Promise<ProjectCreated> {
await this.validateProjectEnvironments(newProject.environments);
Expand Down Expand Up @@ -324,17 +324,19 @@ export default class ProjectService {
this.isEnterprise &&
this.flagResolver.isEnabled('createProjectWithEnvironmentConfig')
) {
// todo: this is a workaround for backwards compatibility
// (i.e. not breaking enterprise tests) that we can change
// once these changes have been merged and enterprise
// updated. Instead, we can exit early if there are no cr
// envs
const crEnvs = newProject.changeRequestEnvironments || [];
await this.validateEnvironmentsExist(crEnvs.map((env) => env.name));
const changeRequestEnvironments =
await enableChangeRequestsForSpecifiedEnvironments(crEnvs);

data.changeRequestEnvironments = changeRequestEnvironments ?? [];
if (newProject.changeRequestEnvironments) {
await this.validateEnvironmentsExist(
newProject.changeRequestEnvironments.map((env) => env.name),
);
const changeRequestEnvironments =
await enableChangeRequestsForSpecifiedEnvironments(
newProject.changeRequestEnvironments,
);

data.changeRequestEnvironments = changeRequestEnvironments;
} else {
data.changeRequestEnvironments = [];
}
Comment on lines +327 to +339
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the description, this could be this instead (essentially the same as before, but without the comment and without extra set of ??s. Happy to hear your thoughts.

Suggested change
if (newProject.changeRequestEnvironments) {
await this.validateEnvironmentsExist(
newProject.changeRequestEnvironments.map((env) => env.name),
);
const changeRequestEnvironments =
await enableChangeRequestsForSpecifiedEnvironments(
newProject.changeRequestEnvironments,
);
data.changeRequestEnvironments = changeRequestEnvironments;
} else {
data.changeRequestEnvironments = [];
}
const crEnvs = newProject.changeRequestEnvironments ?? []
await this.validateEnvironmentsExist(crEnvs.map((env) => env.name));
const changeRequestEnvironments =
await enableChangeRequestsForSpecifiedEnvironments(crEnvs,);
data.changeRequestEnvironments = changeRequestEnvironments;

I kinda like this version, because it avoids all the nesting and it reads cleaner to me 🤷🏼

Copy link
Member

Choose a reason for hiding this comment

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

More verbose version looks more readable

}

await this.accessService.createDefaultProjectRoles(user, data.id);
Expand Down