Skip to content

Commit

Permalink
Printing PR number for invalid prdoc files in scan
Browse files Browse the repository at this point in the history
Before this change, prdoc scan --all would return "n/a" for PR numbers
of invalid files, even if file was named correctly, like
`prdoc/pr_1946.prdoc`.
This removes the requirement for file to be valid in order to get PR
number from filename.
  • Loading branch information
mutantcornholio committed Jun 27, 2024
1 parent e3c8ecb commit 3e9ac65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions prdoclib/src/commands/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl LoadCmd {
let yaml = self.schema.load(&file);

if let Ok(value) = yaml {
Some(DocFileWrapper::new(file, filename, value))
Some(DocFileWrapper::new(file, filename, Some(value)))
} else {
global_result &= false;
None
Expand All @@ -74,7 +74,7 @@ impl LoadCmd {
/// Load one file and returns a wrapper
pub fn load_file(&self, file: &PathBuf) -> Result<DocFileWrapper> {
let filename = DocFileName::try_from(file)?;
let value = self.schema.load(&file)?;
let value = self.schema.load(&file).ok();
let wrapper = DocFileWrapper::new(file.clone(), filename, value);
Ok(wrapper)
}
Expand Down Expand Up @@ -103,7 +103,7 @@ impl LoadCmd {
if let Ok(filename) = filename_maybe {
let yaml = self.schema.load(&file);
if let Ok(value) = yaml {
let wrapper = DocFileWrapper::new(file.clone(), filename, value);
let wrapper = DocFileWrapper::new(file.clone(), filename, Some(value));

global_result &= true;
log::debug!("OK {}", file.display());
Expand Down
4 changes: 2 additions & 2 deletions prdoclib/src/docfile_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ pub struct DocFileWrapper {
pub doc_filename: DocFileName,

/// The content of the PRDoc
pub content: Value,
pub content: Option<Value>,
}

impl DocFileWrapper {
/// Create a new wrapper
pub fn new(file: PathBuf, filename: DocFileName, content: Value) -> Self {
pub fn new(file: PathBuf, filename: DocFileName, content: Option<Value>) -> Self {
let file = file.canonicalize().expect("Canonicalize works");
Self { file, doc_filename: filename, content }
}
Expand Down

0 comments on commit 3e9ac65

Please sign in to comment.