-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): add options
add-links
and git-url
`add-links`: Add links to commits/issues/pr with specified url format (github/gitlab...). `git-url`: The git url of the project. Should be a url using http protocol for links.
- Loading branch information
Showing
6 changed files
with
127 additions
and
14 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
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,3 +1,5 @@ | ||
use crate::format::FormatOptions; | ||
|
||
pub trait Markdown { | ||
fn markdown(&self) -> String; | ||
fn markdown(&self, opts: &FormatOptions) -> String; | ||
} |
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 |
---|---|---|
|
@@ -109,6 +109,18 @@ impl Git { | |
.into_error()?; | ||
Ok(res) | ||
} | ||
|
||
pub fn url(&self) -> Result<String, Error> { | ||
let config = self.repository()?.config()?; | ||
|
||
for entry in &config.entries(Some("url"))? { | ||
let entry = entry?; | ||
if let Some(url) = entry.value() { | ||
return Ok(format!("{}", format_git_url(url))); | ||
} | ||
} | ||
Err(Error::new("URL for your project not found.")) | ||
} | ||
} | ||
|
||
fn remove_ref_tags(name: &[u8]) -> String { | ||
|
@@ -118,3 +130,36 @@ fn remove_ref_tags(name: &[u8]) -> String { | |
.skip(10) | ||
.collect::<String>() | ||
} | ||
|
||
fn format_git_url<S: std::string::ToString>(url: S) -> String { | ||
let url = url.to_string(); | ||
let url = url.strip_suffix(".git").unwrap_or(&url).to_string(); | ||
if url.starts_with("git@") { | ||
url.replacen(":", "/", 1).replacen("git@", "https://", 1) | ||
} else { | ||
url | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
pub fn format_git_url() { | ||
assert_eq!( | ||
super::format_git_url("https://example.com/user/project"), | ||
"https://example.com/user/project" | ||
); | ||
assert_eq!( | ||
super::format_git_url("https://example.com/user/project.git"), | ||
"https://example.com/user/project" | ||
); | ||
assert_eq!( | ||
super::format_git_url("[email protected]:user/project"), | ||
"https://example.com/user/project" | ||
); | ||
assert_eq!( | ||
super::format_git_url("[email protected]:user/project.git"), | ||
"https://example.com/user/project" | ||
); | ||
} | ||
} |
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