History

fix: strip `.git` suffix from repository paths when using it in urls

Sebastian Thiel committed 5 years ago

Commit a3aaa3e1 parent 53ee1a72 files · +8 −3Browse files

Unified · Split

2 files
  1. cargo-smart-release/src/changelog/write.rs +7 −2
  2. cargo-smart-release/tests/changelog/write_and_parse/mod.rs +1 −1
cargo-smart-release/src/changelog/write.rs+7−2
@@ -48,17 +48,22 @@ impl RepositoryUrl { · 47 unmodified lines
4848 self.inner.host.as_ref().map(|h| h == "github.com").unwrap_or(false)
4949 }
5050
51+ fn cleaned_path(&self) -> String {
52+ let path = self.inner.path.to_str_lossy().into_owned();
53+ path.strip_suffix(".git").map(ToOwned::to_owned).unwrap_or(path)
54+ }
55+
5156 pub fn github_https(&self) -> Option<String> {
5257 match &self.inner.host {
5358 Some(host) if host == "github.com" => match self.inner.scheme {
5459 Scheme::Http | Scheme::Https | Scheme::Git => {
55− format!("https://github.com{}", self.inner.path.to_str_lossy()).into()
60+ format!("https://github.com{}", self.cleaned_path()).into()
5661 }
5762 Scheme::Ssh => self
5863 .inner
5964 .user
6065 .as_ref()
61− .map(|user| format!("https://github.com{}/{}", user, self.inner.path.to_str_lossy())),
66+ .map(|user| format!("https://github.com{}/{}", user, self.cleaned_path())),
6267 Scheme::Radicle | Scheme::File => None,
6368 },
6469 None | Some(_) => None,
cargo-smart-release/tests/changelog/write_and_parse/mod.rs+1−1
@@ -53,7 +53,7 @@ fn conventional_write_empty_messages() -> Result { · 52 unmodified lines
5353 for link_mode in &[
5454 changelog::write::Linkables::AsText,
5555 changelog::write::Linkables::AsLinks {
56− repository_url: git_repository::Url::try_from(b"https://github.com/user/repo".as_bytes())?.into(),
56+ repository_url: git_repository::Url::try_from(b"https://github.com/user/repo.git".as_bytes())?.into(),
5757 },
5858 ] {
5959 let log = log.clone();

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t