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

updated regex for resource name validation and convert to kebabCase if name is not valid #9373

Merged
merged 1 commit into from Jul 1, 2021

Conversation

invincibleJai
Copy link
Member

@invincibleJai invincibleJai commented Jun 29, 2021

Fixes:
https://issues.redhat.com/browse/ODC-6043

Analysis / Root cause:

  • even if the name was valid still was getting converted to kebabCase

Solution Description:

  • convert the name to kebabCase if the name is not valid and refactored utils

Screen shots / Gifs for design review:

Unit test coverage report:

  • added / updated tests for utils

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

@openshift-ci openshift-ci bot added the component/dev-console Related to dev-console label Jun 29, 2021
@openshift-ci openshift-ci bot requested review from sahil143 and zherman0 June 29, 2021 14:49
@openshift-ci openshift-ci bot added component/shared Related to console-shared approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 29, 2021
Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

I like the function wrapping improvements 👍

@@ -46,12 +46,13 @@ describe('ValidationUtils', () => {

describe('createComponentName', () => {
const invalidConvertedtoValidNamePair: { [key: string]: string } = {
'0name': 'ocp-0name',
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to bring this back (in some fashion) I think because you undid your regex changes.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yes, if the source name starts with a number (i.e repo name)

Copy link
Member Author

Choose a reason for hiding this comment

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

Have handled it, thanks.


return _.kebabCase(url.split('/').pop());
const kebabCaseStr = _.kebabCase(nameString);
return nameString.match(/^\d/) ? `ocp-${kebabCaseStr}` : kebabCaseStr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nameString.match(/^\d/) ? `ocp-${kebabCaseStr}` : kebabCaseStr;
return nameString.match(/^\d/) || kebabCaseStr.match(/^\d/) ? `ocp-${kebabCaseStr}` : kebabCaseStr;

Technically, a github reposistory name can start with a hypen in the begining.
image

So if you call the createComponentName('-2dotnetcore') it returns back 2-dotnetcore which is invalid name, so we need to consider the kebabCaseStr string as well, so that the output becomes ocp-2-donetcore

'invalid-Name': 'ocp-invalid-name',
'0name': 'ocp-0-name',
Name: 'name',
'-name': 'name',
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the previouse comment, you could add the following test data to this list as well.
-2name': 'ocp-2-name,

@karthikjeeyar
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 1, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 1, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: invincibleJai, karthikjeeyar

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 6666571 into openshift:master Jul 1, 2021
@spadgett spadgett added this to the v4.9 milestone Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console component/shared Related to console-shared lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants