Skip to content

Commit

Permalink
Merge pull request #70 from DeterminateSystems/lucperkins/ds-1194-mak…
Browse files Browse the repository at this point in the history
…e-readme-detection-case-insensitive

Allow for case-insensitive README names
  • Loading branch information
grahamc authored Aug 30, 2023
2 parents abb112e + bc9b55b commit e974b13
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/release_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use color_eyre::eyre::{eyre, WrapErr};
use std::{collections::HashSet, path::Path};
use std::{
collections::HashSet,
path::{Path, PathBuf},
};

use crate::{
graphql::{GithubGraphqlDataResult, MAX_LABEL_LENGTH, MAX_NUM_TOTAL_LABELS},
Visibility,
};

const README_FILENAME_LOWERCASE: &str = "readme.md";

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub(crate) struct ReleaseMetadata {
pub(crate) commit_count: i64,
Expand Down Expand Up @@ -135,12 +140,8 @@ impl ReleaseMetadata {
None
};

let readme_path = flake_root.join(subdir).join("README.md");
let readme = if readme_path.exists() {
Some(tokio::fs::read_to_string(readme_path).await?)
} else {
None
};
let readme_dir = flake_root.join(subdir);
let readme = get_readme(readme_dir).await?;

let spdx_identifier = if spdx_expression.is_some() {
spdx_expression
Expand Down Expand Up @@ -225,3 +226,15 @@ where
serializer.serialize_none()
}
}

async fn get_readme(readme_dir: PathBuf) -> color_eyre::Result<Option<String>> {
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.file_name()).await?));
}
}

Ok(None)
}

0 comments on commit e974b13

Please sign in to comment.