Skip to content

Commit 96d6560

Browse files
author
l
committed
use guards instead of matches where appropriate
1 parent 9649cff commit 96d6560

1 file changed

Lines changed: 21 additions & 10 deletions

File tree

src/bin/pr-metadata-validator.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,32 @@ async fn check_pr_file_changes(
284284
task_issue_number: u64,
285285
) -> Result<Option<ValidationResult>, Error> {
286286
// Get the Sprint Task's description of expected changes
287-
let task_issue = match octocrab
287+
let Ok(task_issue) = octocrab
288288
.issues(org_name, module_name)
289289
.get(task_issue_number)
290290
.await
291-
{
292-
Ok(iss) => iss,
293-
Err(_) => return Ok(Some(ValidationResult::CouldNotMatch)), // Failed to find the right task
291+
else {
292+
return Ok(Some(ValidationResult::CouldNotMatch)); // Failed to find the right task
294293
};
294+
295295
let task_issue_body = task_issue.body.unwrap_or_default();
296+
296297
let directory_description =
297298
Regex::new("CHANGE_DIR=(.+)\\n").expect("Known good regex failed to compile");
298-
let directory_description_regex = match directory_description.captures(&task_issue_body) {
299-
Some(capts) => capts
300-
.get(1)
301-
.expect("Regex capture failed to return string match")
302-
.as_str(), // Only allows a single directory for now
303-
None => return Ok(None), // There is no match defined for this task, don't do any more checks
299+
let Some(directory_regex_captures) = directory_description.captures(&task_issue_body) else {
300+
return Ok(None); // There is no match defined for this task, don't do any more checks
304301
};
302+
let directory_description_regex = directory_regex_captures
303+
.get(1)
304+
.with_context(|| {
305+
format!(
306+
"Check CHANGE_DIR declaration in issue {}",
307+
task_issue.html_url
308+
)
309+
})
310+
.expect("Regex capture failed to return string match")
311+
.as_str(); // Only allows a single directory for now
312+
305313
let directory_matcher = Regex::new(directory_description_regex)
306314
.with_context(|| {
307315
format!(
@@ -310,6 +318,7 @@ async fn check_pr_file_changes(
310318
)
311319
})
312320
.expect("Failed to compile regex");
321+
313322
// Get all of the changed files
314323
let pr_files = all_pages("changed files in pull request", octocrab, async || {
315324
octocrab
@@ -321,6 +330,7 @@ async fn check_pr_file_changes(
321330
if pr_files.is_empty() {
322331
return Ok(Some(ValidationResult::NoFiles)); // no files committed
323332
}
333+
324334
// check each file and error if one is in unexpected place
325335
for pr_file in pr_files {
326336
if !directory_matcher.is_match(&pr_file.filename) {
@@ -329,6 +339,7 @@ async fn check_pr_file_changes(
329339
}));
330340
}
331341
}
342+
332343
Ok(None)
333344
}
334345

0 commit comments

Comments
 (0)