-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Ensure repository slug parsing works correctly. (#596)
* Enable debugging. * Bump CI. * Fix creds. * Bump version.
- Loading branch information
Showing
5 changed files
with
72 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Trigger CI: 9 | ||
# Trigger CI: 10 | ||
|
||
$schema: '../website/static/schemas/workspace.json' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
releases: | ||
"@moonrepo/cli": patch | ||
"@moonrepo/core-linux-arm64-gnu": patch | ||
"@moonrepo/core-linux-arm64-musl": patch | ||
"@moonrepo/core-linux-x64-gnu": patch | ||
"@moonrepo/core-linux-x64-musl": patch | ||
"@moonrepo/core-macos-arm64": patch | ||
"@moonrepo/core-macos-x64": patch | ||
"@moonrepo/core-windows-x64-msvc": patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,30 @@ impl Git { | |
}) | ||
} | ||
|
||
pub fn extract_slug_from_remote(output: String) -> Result<String, VcsError> { | ||
// [email protected]:moonrepo/moon.git | ||
let remote = if output.starts_with("git@") { | ||
format!("https://{}", output.replace(':', "/")) | ||
// https://github.com/moonrepo/moon | ||
} else { | ||
output | ||
}; | ||
|
||
let url = url::Url::parse(&remote) | ||
.map_err(|e| VcsError::FailedToParseGitRemote(e.to_string()))?; | ||
let mut slug = url.path(); | ||
|
||
if slug.starts_with('/') { | ||
slug = &slug[1..]; | ||
} | ||
|
||
if slug.ends_with(".git") { | ||
slug = &slug[0..(slug.len() - 4)]; | ||
} | ||
|
||
Ok(slug.to_owned()) | ||
} | ||
|
||
async fn get_merge_base(&self, base: &str, head: &str) -> VcsResult<String> { | ||
let mut args = string_vec!["merge-base", head]; | ||
let mut candidates = string_vec![base.to_owned()]; | ||
|
@@ -240,27 +264,7 @@ impl Vcs for Git { | |
) | ||
.await?; | ||
|
||
// [email protected]:moonrepo/moon.git | ||
let remote = if output.starts_with("git@") { | ||
format!("https://{}", output.replace(':', "/")) | ||
// https://github.com/moonrepo/moon | ||
} else { | ||
output | ||
}; | ||
|
||
let url = url::Url::parse(&remote) | ||
.map_err(|e| VcsError::FailedToParseGitRemote(e.to_string()))?; | ||
let mut slug = url.path(); | ||
|
||
if slug.starts_with('/') { | ||
slug = &slug[1..]; | ||
} | ||
|
||
if slug.ends_with(".git") { | ||
slug = &slug[0..(slug.len() - 4)]; | ||
} | ||
|
||
Ok(slug.to_owned()) | ||
Self::extract_slug_from_remote(output) | ||
} | ||
|
||
// https://git-scm.com/docs/git-status#_short_format | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,3 +463,39 @@ mod touched_files_via_diff { | |
); | ||
} | ||
} | ||
|
||
mod slug_parsing { | ||
use super::*; | ||
|
||
#[test] | ||
fn supports_http() { | ||
assert_eq!( | ||
Git::extract_slug_from_remote("http://github.com/moonrepo/moon".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
assert_eq!( | ||
Git::extract_slug_from_remote("http://github.com/moonrepo/moon.git".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
assert_eq!( | ||
Git::extract_slug_from_remote("https://github.com/moonrepo/moon".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
assert_eq!( | ||
Git::extract_slug_from_remote("https://github.com/moonrepo/moon.git".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
} | ||
|
||
#[test] | ||
fn supports_git() { | ||
assert_eq!( | ||
Git::extract_slug_from_remote("[email protected]:moonrepo/moon".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
assert_eq!( | ||
Git::extract_slug_from_remote("[email protected]:moonrepo/moon.git".into()).unwrap(), | ||
"moonrepo/moon" | ||
); | ||
} | ||
} |