fix(#2327): handle dismissed reviews like stale (superseded helper)

This commit is contained in:
damocles 2026-07-10 15:15:05 +02:00 committed by mara
commit ce909a00a2
3 changed files with 38 additions and 16 deletions

View file

@ -121,17 +121,30 @@ pub(crate) fn pct_encode(s: &str) -> String {
out
}
/// One reviewer's latest verdict on a PR, plus forgejo's `stale` bit.
/// One reviewer's latest verdict on a PR, plus forgejo's `stale` /
/// `dismissed` bits.
///
/// `stale` is set by forgejo when the PR head commit changed after this
/// review was submitted — branch protection then wants a fresh review, so
/// a `stale` APPROVED no longer satisfies the merge gate even though its
/// `state` string still reads `APPROVED`. Surfacing it stops the CLI from
/// reporting a stale-but-technically-approved review as still-good.
/// review was submitted (branch protection then wants a fresh review);
/// `dismissed` is set when the review was explicitly dismissed. Either way
/// the review no longer applies to the current head even though its `state`
/// string still reads `APPROVED` / `REQUEST_CHANGES` — so surfacing them
/// stops the CLI from reporting a no-longer-valid review as still-good, and
/// [`ReviewInfo::superseded`] rolls both into one "doesn't count" check.
pub(crate) struct ReviewInfo {
pub login: String,
pub state: String,
pub stale: bool,
pub dismissed: bool,
}
impl ReviewInfo {
/// True when the review no longer applies to the current head — stale
/// (head moved) or dismissed. Such a verdict neither blocks a merge nor
/// counts as a fresh approval.
pub(crate) fn superseded(&self) -> bool {
self.stale || self.dismissed
}
}
/// Latest non-comment review per reviewer on a PR. Reviews come
@ -173,14 +186,17 @@ pub(crate) fn latest_reviews(client: &Client, repo: &str, pr: u64) -> Result<Vec
continue;
}
let stale = r.stale.unwrap_or(false);
let dismissed = r.dismissed.unwrap_or(false);
if let Some(slot) = latest.iter_mut().find(|info| info.login == login) {
st.clone_into(&mut slot.state);
slot.stale = stale;
slot.dismissed = dismissed;
} else {
latest.push(ReviewInfo {
login: login.to_owned(),
state: st.to_owned(),
stale,
dismissed,
});
}
}