Skip to content

Commit

Permalink
fix: Assure git@github.com/user/repo urls transform into https urls…
Browse files Browse the repository at this point in the history
… correctly. (#512)
  • Loading branch information
Byron committed Aug 30, 2022
1 parent 239cb8a commit fcbea05
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cargo-smart-release/src/changelog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub mod init;
mod merge;
mod parse;
pub mod section;
#[cfg(test)]
mod tests;
pub mod write;

pub const DEFAULT_HEADING_LEVEL: usize = 2;
Expand Down
22 changes: 22 additions & 0 deletions cargo-smart-release/src/changelog/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
mod repository_url {
use crate::changelog::write::RepositoryUrl;
use git_repository as git;

#[test]
fn github_https_url() {
for input in [
"https://github.com/byron/gitoxide",
"https://github.com/byron/gitoxide.git",
"git://github.com/byron/gitoxide",
"git://github.com/byron/gitoxide.git",
"git@github.com:byron/gitoxide.git",
"git@github.com:byron/gitoxide",
] {
let url = RepositoryUrl::from(git::url::parse(input.into()).unwrap());
assert_eq!(
url.github_https().expect("possible"),
"https://github.com/byron/gitoxide"
)
}
}
}
5 changes: 3 additions & 2 deletions cargo-smart-release/src/changelog/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ impl RepositoryUrl {
Scheme::Ssh => self
.inner
.user()
.map(|user| format!("https://github.com{}/{}", user, self.cleaned_path())),
Scheme::Radicle | Scheme::File => None,
.filter(|user| *user == "git")
.map(|_git| format!("https://github.com{}", self.cleaned_path())),
_ => None,
},
None | Some(_) => None,
}
Expand Down

0 comments on commit fcbea05

Please sign in to comment.