oscarotero / keep-a-changelog

Node & Deno package to parse and generate changelogs
MIT License
61 stars 20 forks source link

Improve URL normalization in bin.ts #42

Closed trivialkettle closed 11 months ago

trivialkettle commented 11 months ago

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

oscarotero commented 11 months ago

thank you!