Skip to content

Commit deaf558

Browse files
committed
Add more protection against manually edited labels
1 parent 6c5b3a9 commit deaf558

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/handlers/major_change.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ enum SecondedLogicError {
449449
draft: bool,
450450
open: bool,
451451
},
452-
ConcernsLabelSet,
452+
NotAMajorChange,
453+
SecondLabelAbsent,
454+
ConcernsLabelPresent,
453455
NoMajorChangeConfig,
454456
}
455457

@@ -464,7 +466,9 @@ impl Display for SecondedLogicError {
464466
SecondedLogicError::IssueNotReady { draft, open } => {
465467
write!(f, "issue is not ready (draft: {draft}; open: {open})")
466468
}
467-
SecondedLogicError::ConcernsLabelSet => write!(f, "concerns label set"),
469+
SecondedLogicError::NotAMajorChange => write!(f, "not a major change"),
470+
SecondedLogicError::SecondLabelAbsent => write!(f, "second label is absent"),
471+
SecondedLogicError::ConcernsLabelPresent => write!(f, "concerns label set"),
468472
SecondedLogicError::NoMajorChangeConfig => write!(f, "no `[major_change]` config"),
469473
}
470474
}
@@ -557,12 +561,17 @@ async fn process_seconded(
557561
.await
558562
.context("unable to get the associated issue")?;
559563

560-
if issue
561-
.labels
562-
.iter()
563-
.any(|l| Some(&l.name) == config.concerns_label.as_ref())
564-
{
565-
anyhow::bail!(SecondedLogicError::ConcernsLabelSet);
564+
if !issue.labels.iter().any(|l| l.name == config.enabling_label) {
565+
anyhow::bail!(SecondedLogicError::NotAMajorChange);
566+
}
567+
568+
if !issue.labels.iter().any(|l| l.name == config.second_label) {
569+
anyhow::bail!(SecondedLogicError::SecondLabelAbsent);
570+
}
571+
572+
let concerns_label = config.concerns_label.as_ref();
573+
if issue.labels.iter().any(|l| Some(&l.name) == concerns_label) {
574+
anyhow::bail!(SecondedLogicError::ConcernsLabelPresent);
566575
}
567576

568577
if !issue.is_open() || issue.draft {

0 commit comments

Comments
 (0)