Watch
0
0
Fork
You've already forked hyperhive
0

approve a requested review when the repo has no review rules

On deploy: a review requested of the review classifier on a PR whose repo
holds neither .hyperhive/review-classifier.yml nor .json on its default
branch now posts an APPROVED review at once, saying no review rules are
configured for the repo and it was approved without checks. No model call
is made. Before, that case posted a "No verdict" comment. A rules file that
exists but fails to load or parse still posts no verdict. The rule model is
unchanged and instance-wide: every repo without a rules file is approved.
This commit is contained in:
atlas 2026-10-24 17:23:27 +02:00
commit 26c4ff89d5

View file

@ -468,6 +468,34 @@ async fn rules(
owner: &str,
name: &str,
) -> Result<Json<Rules>, ProblemDetails> {
match load_rules(files, owner, name).await? {
Loaded::Rules(rules) => Ok(Json(rules)),
Loaded::Absent { branch } => {
let [yml, json] = RULES_PATHS;
Err(error_problem(
StatusCode::NOT_FOUND,
&format!("{owner}/{name}'s default branch {branch} holds neither {yml} nor {json}"),
))
}
}
}
/// What the default branch holds of a repo's rules.
enum Loaded {
Rules(Rules),
/// Neither rules file exists on `branch`.
Absent {
branch: String,
},
}
/// Read the rules file of `owner/name` and parse it; a repo whose default
/// branch holds no rules file is [`Loaded::Absent`], not an error.
async fn load_rules(
files: &impl FileSource,
owner: &str,
name: &str,
) -> Result<Loaded, ProblemDetails> {
let repo = format!("{owner}/{name}");
let read = forge::within_forge_deadline(
"review rules",
@ -490,13 +518,9 @@ async fn rules(
let [yml, json] = RULES_PATHS;
let (path, bytes) = match read.files.as_slice() {
[] => {
return Err(error_problem(
StatusCode::NOT_FOUND,
&format!(
"{repo}'s default branch {} holds neither {yml} nor {json}",
read.branch
),
));
return Ok(Loaded::Absent {
branch: read.branch,
});
}
[file] => (&file.path, &file.bytes),
_ => {
@ -512,7 +536,7 @@ async fn rules(
let classifications = parse_rules(path, bytes)
.map_err(|d| error_problem(StatusCode::UNPROCESSABLE_ENTITY, &d))?;
tracing::info!(%repo, branch = %read.branch, commit = %read.commit, %path, "review rules read");
Ok(Json(Rules {
Ok(Loaded::Rules(Rules {
path: path.clone(),
branch: read.branch,
commit: read.commit,