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
48 self.inner.host.as_ref().map(|h| h == "github.com").unwrap_or(false)48 self.inner.host.as_ref().map(|h| h == "github.com").unwrap_or(false)
49 }49 }
50 50
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
51 pub fn github_https(&self) -> Option<String> {56 pub fn github_https(&self) -> Option<String> {
52 match &self.inner.host {57 match &self.inner.host {
53 Some(host) if host == "github.com" => match self.inner.scheme {58 Some(host) if host == "github.com" => match self.inner.scheme {
54 Scheme::Http | Scheme::Https | Scheme::Git => {59 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()
56 }61 }
57 Scheme::Ssh => self62 Scheme::Ssh => self
58 .inner63 .inner
59 .user64 .user
60 .as_ref()65 .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())),
62 Scheme::Radicle | Scheme::File => None,67 Scheme::Radicle | Scheme::File => None,
63 },68 },
64 None | Some(_) => None,69 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
53 for link_mode in &[53 for link_mode in &[
54 changelog::write::Linkables::AsText,54 changelog::write::Linkables::AsText,
55 changelog::write::Linkables::AsLinks {55 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(),
57 },57 },
58 ] {58 ] {
59 let log = log.clone();59 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