codegen: Unify string conversion style

This commit is contained in:
Taiki Endo
2024-06-20 04:32:58 +09:00
parent 4222c00e29
commit e2ceb8a503
2 changed files with 14 additions and 14 deletions

View File

@@ -172,7 +172,7 @@ fn main() -> Result<()> {
if let Some(license) = detail.license { if let Some(license) = detail.license {
eprintln!("Trying to using license '{license}' from crates.io ..."); eprintln!("Trying to using license '{license}' from crates.io ...");
if let Some(license_markdown) = if let Some(license_markdown) =
get_license_markdown(&license, &repo.to_string(), &repo_info.default_branch) get_license_markdown(&license, repo, &repo_info.default_branch)
{ {
manifests.license_markdown = license_markdown; manifests.license_markdown = license_markdown;
} }
@@ -181,7 +181,7 @@ fn main() -> Result<()> {
if let Some(license) = license.spdx_id { if let Some(license) = license.spdx_id {
eprintln!("Trying to using license '{license}' from github.com ..."); eprintln!("Trying to using license '{license}' from github.com ...");
if let Some(license_markdown) = if let Some(license_markdown) =
get_license_markdown(&license, &repo.to_string(), &repo_info.default_branch) get_license_markdown(&license, repo, &repo_info.default_branch)
{ {
manifests.license_markdown = license_markdown; manifests.license_markdown = license_markdown;
} }
@@ -687,16 +687,16 @@ pub fn download(url: &str) -> Result<ureq::Response> {
} }
#[must_use] #[must_use]
fn create_github_raw_link(repository: &String, branch: &String, filename: &String) -> String { fn create_github_raw_link(repository: &str, branch: &str, filename: &str) -> String {
format!("https://raw.githubusercontent.com/{repository}/{branch}/{filename}") format!("https://raw.githubusercontent.com/{repository}/{branch}/{filename}")
} }
#[must_use] #[must_use]
fn create_github_link(repository: &String, branch: &String, filename: &String) -> String { fn create_github_link(repository: &str, branch: &str, filename: &str) -> String {
format!("https://github.com/{repository}/blob/{branch}/{filename}") format!("https://github.com/{repository}/blob/{branch}/{filename}")
} }
#[must_use] #[must_use]
fn get_license_markdown(spdx_expr: &str, repo: &String, default_branch: &String) -> Option<String> { fn get_license_markdown(spdx_expr: &str, repo: &str, default_branch: &str) -> Option<String> {
// TODO: use https://docs.rs/spdx/latest/spdx/expression/struct.Expression.html#method.canonicalize ? // TODO: use https://docs.rs/spdx/latest/spdx/expression/struct.Expression.html#method.canonicalize ?
let expr = spdx::Expression::parse_mode(spdx_expr, spdx::ParseMode::LAX).unwrap(); let expr = spdx::Expression::parse_mode(spdx_expr, spdx::ParseMode::LAX).unwrap();
@@ -740,14 +740,14 @@ fn get_license_markdown(spdx_expr: &str, repo: &String, default_branch: &String)
let license_name = if let Some(exception_id) = exception_id { let license_name = if let Some(exception_id) = exception_id {
format!("{} WITH {}", license_id.name, exception_id.name) format!("{} WITH {}", license_id.name, exception_id.name)
} else { } else {
license_id.name.to_string() license_id.name.to_owned()
}; };
let name = license_id.name.split('-').next().unwrap().to_ascii_uppercase(); let name = license_id.name.split('-').next().unwrap().to_ascii_uppercase();
for filename in [ for filename in [
"LICENSE".to_string(), "LICENSE".to_owned(),
format!("LICENSE-{name}"), format!("LICENSE-{name}"),
"LICENSE.md".to_string(), "LICENSE.md".to_owned(),
"COPYING".to_string(), "COPYING".to_owned(),
] { ] {
let url = create_github_raw_link(repo, default_branch, &filename); let url = create_github_raw_link(repo, default_branch, &filename);
if github_head(&url).is_ok() { if github_head(&url).is_ok() {
@@ -765,7 +765,7 @@ fn get_license_markdown(spdx_expr: &str, repo: &String, default_branch: &String)
let license_name = if let Some(exception_id) = exception_id { let license_name = if let Some(exception_id) = exception_id {
format!("{} WITH {}", license_id.name, exception_id.name) format!("{} WITH {}", license_id.name, exception_id.name)
} else { } else {
license_id.name.to_string() license_id.name.to_owned()
}; };
if github_head(&url).is_ok() { if github_head(&url).is_ok() {
let url = create_github_link(repo, default_branch, &filename); let url = create_github_link(repo, default_branch, &filename);

View File

@@ -46,16 +46,16 @@ fn main() -> Result<()> {
paths.sort_by_key(fs_err::DirEntry::path); paths.sort_by_key(fs_err::DirEntry::path);
let mut tools = vec![MarkdownEntry { let mut tools = vec![MarkdownEntry {
name: "valgrind".to_string(), name: "valgrind".to_owned(),
alias: None, alias: None,
website: "https://valgrind.org/".to_string(), website: "https://valgrind.org/".to_owned(),
installed_to: InstalledTo::Snap, installed_to: InstalledTo::Snap,
installed_from: InstalledFrom::Snap, installed_from: InstalledFrom::Snap,
platforms: Platforms { linux: true, ..Default::default() }, platforms: Platforms { linux: true, ..Default::default() },
repository: "https://sourceware.org/git/valgrind.git".to_string(), repository: "https://sourceware.org/git/valgrind.git".to_owned(),
license_markdown: license_markdown:
"[GPL-2.0](https://sourceware.org/git/?p=valgrind.git;a=blob;f=COPYING;hb=HEAD)" "[GPL-2.0](https://sourceware.org/git/?p=valgrind.git;a=blob;f=COPYING;hb=HEAD)"
.to_string(), .to_owned(),
}]; }];
for path in paths { for path in paths {