Skip to content

Commit aff7dcf

Browse files
author
l
committed
use option instead of default 0 for issue ids
1 parent 5111e98 commit aff7dcf

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/bin/pr-metadata-validator.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,10 @@ async fn validate_pr(
251251
return Ok(ValidationResult::BodyTemplateNotFilledOut);
252252
}
253253

254-
let pr_assignment_descriptor_id = get_descriptor_id_for_pr(matched.sprints, pr_number);
254+
let pr_assignment_descriptor_id =
255+
get_descriptor_id_for_pr(matched.sprints, pr_number).expect("This PR does not exist");
256+
// This should never error, as a PR by this point in code must have been matched
257+
// with an assignment, and PR assignments must have an associated issue descriptor
255258

256259
match check_pr_file_changes(
257260
octocrab,
@@ -300,7 +303,12 @@ async fn check_pr_file_changes(
300303
None => return Ok(None), // There is no match defined for this task, don't do any more checks
301304
};
302305
let directory_matcher = Regex::new(directory_description_regex)
303-
.with_context(|| format!("Check CHANGE_DIR declaration in issue {}", task_issue.html_url))
306+
.with_context(|| {
307+
format!(
308+
"Check CHANGE_DIR declaration in issue {}",
309+
task_issue.html_url
310+
)
311+
})
304312
.expect("Failed to compile regex");
305313
// Get all of the changed files
306314
let pr_files = all_pages("changed files in pull request", octocrab, async || {

src/course.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub enum Assignment {
314314
ExpectedPullRequest {
315315
title: String,
316316
html_url: Url,
317-
assignment_descriptor_id: u64,
317+
assignment_issue_id: u64,
318318
optionality: AssignmentOptionality,
319319
},
320320
}
@@ -543,7 +543,7 @@ pub enum Submission {
543543
PullRequest {
544544
pull_request: Pr,
545545
optionality: AssignmentOptionality,
546-
assignment_descriptor: u64,
546+
assignment_issue_id: u64,
547547
},
548548
}
549549

@@ -944,6 +944,7 @@ fn match_pr_to_assignment(
944944
sprint_index: usize,
945945
assignment_index: usize,
946946
optionality: AssignmentOptionality,
947+
assignment_issue_id: u64,
947948
}
948949

949950
let mut best_match: Option<Match> = None;
@@ -964,6 +965,7 @@ fn match_pr_to_assignment(
964965
Assignment::ExpectedPullRequest {
965966
title: expected_title,
966967
optionality,
968+
assignment_issue_id,
967969
..
968970
} => {
969971
let mut assignment_title_words = make_title_more_matchable(expected_title);
@@ -988,6 +990,7 @@ fn match_pr_to_assignment(
988990
sprint_index,
989991
assignment_index,
990992
optionality: optionality.clone(),
993+
assignment_issue_id: *assignment_issue_id,
991994
});
992995
}
993996
}
@@ -1000,22 +1003,15 @@ fn match_pr_to_assignment(
10001003
sprint_index,
10011004
assignment_index,
10021005
optionality,
1006+
assignment_issue_id,
10031007
..
10041008
}) = best_match
10051009
{
1006-
let pr_assignment_descriptor_id: u64 =
1007-
match assignments[sprint_index].assignments[assignment_index] {
1008-
Assignment::ExpectedPullRequest {
1009-
assignment_descriptor_id,
1010-
..
1011-
} => assignment_descriptor_id,
1012-
_ => 0,
1013-
};
10141010
submissions[sprint_index].submissions[assignment_index] =
10151011
SubmissionState::Some(Submission::PullRequest {
10161012
pull_request: pr,
10171013
optionality,
1018-
assignment_descriptor: pr_assignment_descriptor_id,
1014+
assignment_issue_id: assignment_issue_id,
10191015
});
10201016
} else if !pr.is_closed {
10211017
unknown_prs.push(pr);
@@ -1024,7 +1020,10 @@ fn match_pr_to_assignment(
10241020

10251021
// Given a vector of sprints, and a target pr number, for a given person
10261022
// return the issue ID for the associated assignment descriptor
1027-
pub fn get_descriptor_id_for_pr(sprints: Vec<SprintWithSubmissions>, target_pr_number: u64) -> u64 {
1023+
pub fn get_descriptor_id_for_pr(
1024+
sprints: Vec<SprintWithSubmissions>,
1025+
target_pr_number: u64,
1026+
) -> Option<u64> {
10281027
match sprints
10291028
.iter()
10301029
.flat_map(|sprint_with_subs| sprint_with_subs.submissions.clone())
@@ -1037,10 +1036,10 @@ pub fn get_descriptor_id_for_pr(sprints: Vec<SprintWithSubmissions>, target_pr_n
10371036
_ => false,
10381037
}) {
10391038
Some(Submission::PullRequest {
1040-
assignment_descriptor,
1039+
assignment_issue_id,
10411040
..
1042-
}) => assignment_descriptor,
1043-
_ => 0,
1041+
}) => Some(assignment_issue_id),
1042+
_ => None, // Was called with a nonexistent PR number, can't find an associated assignment
10441043
}
10451044
}
10461045

0 commit comments

Comments
 (0)