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

DYN-5791 Fixing Renaming Tool #14812

Merged
merged 2 commits into from
Jan 10, 2024
Merged

DYN-5791 Fixing Renaming Tool #14812

merged 2 commits into from
Jan 10, 2024

Conversation

RobertGlobant20
Copy link
Contributor

Purpose

Renaming tool failing to rename the hashed name inside the md file content when the file name has empty spaces (%20).
If the md file name contains empty spaces then the img file name will also contain %20 instead of empty space so in this way will be loaded by DocumentationBrowser correctly. So my fix is to remove the %20 when renaming the files and the md file content so matches the expected hashed img name.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

Renaming tool failing to rename the hashed name inside the md file content when the file name has empty spaces (%20).

Reviewers

@QilongTang

FYIs

@reddyashish

If the md file name contains empty spaces then the img file name will also contain %20 instead of empty space so in this way will be loaded by DocumentationBrowser correctly.
So my fix is to remove the %20 when renaming the files and the md file content so matches the expected hashed img name.
@RobertGlobant20
Copy link
Contributor Author

GIF showing that the renaming tool is working as expected when the file name has empty spaces.
cXPV038uub

Copy link

github-actions bot commented Jan 4, 2024

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@mjkkirschner
Copy link
Member

you should add a test for this change.

@@ -61,7 +61,7 @@ private static void RenameFile(string file)

private static void RenameFile(string file, string baseName, string shortName)
{
var content = File.ReadAllText(file);
var content = HttpUtility.UrlDecode(File.ReadAllText(file));
Copy link
Member

@mjkkirschner mjkkirschner Jan 5, 2024

Choose a reason for hiding this comment

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

why have you only modified this overload of RenameFile / Directory - now the others are inconsistent in behavior? Is there a good reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is only happening when is trying to replace the image name inside the .md file with the hashed file name and this RenameFile(string file, string baseName, string shortName) method is doing that task,

e.g. for ByOriginVectors node the next values will be replaced.
baseName = "Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis)"
shortName = "KLFVJ5DI7APVNODARMSE3JM5C27DG62OXUUQRS3HCDTZYO6IBOZA"

The other RenameFile(string file) function is calling RenameFile(string file, string baseName, string shortName), then I don't understand what you mean by "inconsistent in behavior".

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation- that makes sense, so now all replace methods will eventually call down to this one and have the same behavior with decoding?

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 with "now all replace methods" you refer to calling "string.Replace", this line updated just applies to the case of replacing the md file content, there are other calls to "string.Replace" that won't need to use HttpUtility.UrlDecode (like the image below) due that is replacing the file name and file names doesn't have the "%20" char.

There are two test cases for using "NodeDocumentationMarkdownGenerator rename" command, one is when renaming just a file and the other when renaming all the files in a folder. If you have a specific case in mind in which this code could not work, please let me know and I can test it. Thanks

image

Copy link
Member

@mjkkirschner mjkkirschner Jan 9, 2024

Choose a reason for hiding this comment

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

Sorry, typo, I meant Rename not replace.
RenameFile
RenameDirectory

I want to understand if this tool will now always do this decoding whenever it replaces the content inside a file while renaming no matter what code path is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it will do the decoding whenever replaces the content inside a md file.
Here you can see a flow diagram showing that when using "rename" option in both cases will be decoding, I hope this diagram shows the behavior in a more clear way:
image

@RobertGlobant20
Copy link
Contributor Author

you should add a test for this change.

Ok, I will add a test for this case

Adding unit test that will validate that the files are correctly renamed in a folder and that the md file content is updated correctly.
@RobertGlobant20
Copy link
Contributor Author

you should add a test for this change.

A unit test that will validate the rename of files inside a folder was added
a0fe205

Copy link

github-actions bot commented Jan 8, 2024

UI Smoke Tests

Test: success. 2 passed, 0 failed.
TestComplete Test Result
Workflow Run: UI Smoke Tests
Check: UI Smoke Tests - net8.0

@RobertGlobant20
Copy link
Contributor Author

any more comment or suggestion in this PR?

@QilongTang QilongTang added this to the 3.1 milestone Jan 10, 2024
@QilongTang QilongTang merged commit 3ee9c88 into DynamoDS:master Jan 10, 2024
20 of 21 checks passed
@QilongTang
Copy link
Contributor

hi @RobertGlobant20 Do we need to rerun the updated tool to the md files before removing the duplicates?

@RobertGlobant20
Copy link
Contributor Author

hi @RobertGlobant20 Do we need to rerun the updated tool to the md files before removing the duplicates?

@QilongTang we will need to delete the rename_log.txt file, delete the new files (the hashed name ones) and also get the original md/jpg/dyn files (the original files are copied to the en-US\fallback_docs when the Dynamo solution is rebuild), then I guess the renaming tool was executed automatically by a job, or how did you execute the renaming tool?.

For example if before running the tool (without my fix) we had the next files:

  • Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis).md
  • Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis).dyn
  • Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(origin, xAxis, yAxis, zAxis)_img.jpg

After running the tool (without my fix) we will have the next files (the md file content is wrong):

  • KLFVJ5DI7APVNODARMSE3JM5C27DG62OXUUQRS3HCDTZYO6IBOZA.md
  • KLFVJ5DI7APVNODARMSE3JM5C27DG62OXUUQRS3HCDTZYO6IBOZA.dyn
  • KLFVJ5DI7APVNODARMSE3JM5C27DG62OXUUQRS3HCDTZYO6IBOZA_img.jpg

Then if we want to run the tool (WITH my fix), then we need the original files and delete all the KLFVJ5DI7APVNODARMSE3JM5C27DG62OXUUQRS3HCDTZYO6IBOZA* files otherwise will throw exceptions.

@QilongTang
Copy link
Contributor

HI @RobertGlobant20 I think @sm6srw would know because he developed and ran the tool before, not me.

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.

4 participants