Skip to content

Commit

Permalink
Rework get_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoverbear committed Feb 20, 2024
1 parent daa7d45 commit 5699eb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ impl clap::builder::TypedValueParser for U64ToNoneParser {
}

impl FlakeHubPushCli {
#[tracing::instrument(skip_all)]
pub(crate) fn populate_missing_from_github(&mut self) {
if self.git_root.0.is_none() {
let env_key = "GITHUB_WORKSPACE";
Expand Down
21 changes: 11 additions & 10 deletions src/release_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use color_eyre::eyre::{eyre, WrapErr};
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::Visibility;

Expand Down Expand Up @@ -124,13 +124,13 @@ impl ReleaseMetadata {
None
};

let readme = get_readme(flake_store_path).await?;
if readme.is_some() {
span.record(
"readme",
tracing::field::display(flake_store_path.join("README.md").display()),
);
}
let readme_path = get_readme(flake_store_path).await?;
let readme = if let Some(readme_path) = readme_path {
span.record("readme", tracing::field::display(readme_path.display()));
Some(tokio::fs::read_to_string(&readme_path).await?)
} else {
None
};

tracing::trace!("Collected ReleaseMetadata information");

Expand Down Expand Up @@ -186,12 +186,13 @@ where
}
}

async fn get_readme(readme_dir: &Path) -> color_eyre::Result<Option<String>> {
#[tracing::instrument(skip_all, fields(readme_dir))]
async fn get_readme(readme_dir: &Path) -> color_eyre::Result<Option<PathBuf>> {
let mut read_dir = tokio::fs::read_dir(readme_dir).await?;

while let Some(entry) = read_dir.next_entry().await? {
if entry.file_name().to_ascii_lowercase() == README_FILENAME_LOWERCASE {
return Ok(Some(tokio::fs::read_to_string(entry.path()).await?));
return Ok(Some(entry.path()));
}
}

Expand Down

0 comments on commit 5699eb4

Please sign in to comment.