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

Improve URL normalization in bin.ts #42

Merged
merged 1 commit into from
Nov 18, 2023

Conversation

trivialkettle
Copy link
Contributor

The original implementation did not handle https URLs. If one cloned a repository via https://github.com/my/project.git the URL in CHANGELOG.md still contained the .git suffix. This is only a issue if a new CHANGELOG.md file is created by --init, otherwise the correct URL is taken from existing tag / compare entries.

Also the remoteUrls protocol does not need to be set by hand, since new URL() seems to parse the correct protocol from the URL.

I tested the implementation with these inputs:

    console.log(normalizeUrl("git@github.com:my/proj.git", true).href == "https://github.com/my/proj")
    console.log(normalizeUrl("git@github.com:my/proj", true).href == "https://github.com/my/proj")
    console.log(normalizeUrl("https://github.com/my/proj.git", true).href == "https://github.com/my/proj")
    console.log(normalizeUrl("https://github.com/my/proj", true).href == "https://github.com/my/proj")
    console.log(normalizeUrl("https://gitlab.example.com/my/proj.git", true).href == "https://gitlab.example.com/my/proj")
    console.log(normalizeUrl("https://gitlab.example.com/my/proj", true).href == "https://gitlab.example.com/my/proj")
    console.log(normalizeUrl("git@gitlab.example.com:my/proj.git", true).href == "https://gitlab.example.com/my/proj")
    console.log(normalizeUrl("git@gitlab.example.com:my/proj", true).href == "https://gitlab.example.com/my/proj")
    console.log(normalizeUrl("git@gitlab.example.com:my/proj", false).href == "http://gitlab.example.com/my/proj")

I think it would be a good idea to move normalizeUrl into the library code and add some unit tests, but I am not sure if you want this since this is only used in bin.ts

The original implementation did not handle https URLs. If one cloned a repository via https://github.com/my/project.git the URL in CHANGELOG.md still contained the .git suffix.

Also the remoteUrls protocol does not need to be set by hand, since new URL() seems to parse the correct protocol from the URL.
@oscarotero oscarotero merged commit 3fe3643 into oscarotero:master Nov 18, 2023
@oscarotero
Copy link
Owner

thank you!

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.

2 participants