Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: git_forge read handlers take a forge-only sub-state

This commit is contained in:
atlas 2026-11-29 13:33:00 +01:00 • committed by mara
commit 52bfca85ad
4 changed files with 37 additions and 10 deletions

View file

@ -13,7 +13,8 @@ use axum::{
};
use crate::forge;
use crate::routes::{AppState, StatusUnavailable, error_problem};
use crate::git_forge::GitForgeState;
use crate::routes::{StatusUnavailable, error_problem};
/// The 503 detail when the forge did not answer within
/// [`forge::FORGE_DEADLINE`].
@ -35,7 +36,7 @@ const DEADLINE_DETAIL: &str = "the forge did not answer within the deadline";
tag = "repos"
)]
pub async fn get_repos(
State(state): State<AppState>,
State(state): State<GitForgeState>,
) -> Result<Json<Vec<String>>, StatusUnavailable> {
let Some(client) = state.forge.get() else {
return Err(StatusUnavailable(
@ -71,7 +72,7 @@ pub async fn get_repos(
tag = "repos"
)]
pub async fn get_issue_report_all(
State(state): State<AppState>,
State(state): State<GitForgeState>,
) -> Result<Json<Vec<forge::IssueReportRow>>, StatusUnavailable> {
let Some(client) = state.forge.get() else {
return Err(StatusUnavailable(
@ -119,7 +120,7 @@ pub async fn get_issue_report_all(
tag = "repos"
)]
pub async fn get_issue_report(
State(state): State<AppState>,
State(state): State<GitForgeState>,
Path((org, repo)): Path<(String, String)>,
) -> Result<Json<Vec<forge::IssueReportRow>>, problem_details::ProblemDetails> {
let Some(client) = state.forge.get() else {

View file

@ -9,3 +9,27 @@ pub(crate) mod pr_conflicts;
pub(crate) mod pr_report;
pub(crate) mod pulls;
pub(crate) mod webhook;
use std::sync::Arc;
use axum::extract::FromRef;
use crate::jobq::Late;
use crate::routes::AppState;
/// What the forge read routes may reach of [`AppState`]: the forge client.
///
/// Derived per request from [`AppState`] (`FromRef`), so the field is a clone
/// of the same `Arc` and nothing is held twice.
#[derive(Clone)]
pub(crate) struct GitForgeState {
pub(crate) forge: Late<Arc<forge::Client>>,
}
impl FromRef<AppState> for GitForgeState {
fn from_ref(state: &AppState) -> Self {
Self {
forge: Arc::clone(&state.forge),
}
}
}

View file

@ -10,8 +10,9 @@ use axum::{
};
use crate::forge;
use crate::git_forge::GitForgeState;
use crate::issue_report::issue_report_error_status;
use crate::routes::{AppState, error_problem};
use crate::routes::error_problem;
/// The 503 detail when the forge did not answer within
/// [`forge::FORGE_DEADLINE`].
@ -28,7 +29,7 @@ const DEADLINE_DETAIL: &str = "the forge did not answer within the deadline";
tag = "pulls"
)]
pub async fn get_pr_report_all(
State(state): State<AppState>,
State(state): State<GitForgeState>,
) -> Result<Json<Vec<forge::pr_report::PrReportRow>>, problem_details::ProblemDetails> {
let Some(client) = state.forge.get() else {
return Err(error_problem(
@ -74,7 +75,7 @@ pub async fn get_pr_report_all(
tag = "pulls"
)]
pub async fn get_pr_report(
State(state): State<AppState>,
State(state): State<GitForgeState>,
Path((org, repo)): Path<(String, String)>,
) -> Result<Json<Vec<forge::pr_report::PrReportRow>>, problem_details::ProblemDetails> {
let Some(client) = state.forge.get() else {

View file

@ -13,9 +13,10 @@ use serde::Deserialize;
use utoipa::IntoParams;
use crate::forge::{self, OpenPull};
use crate::git_forge::GitForgeState;
use crate::issue_report::issue_report_error_status;
use crate::review_classifier::split_repo;
use crate::routes::{AppState, error_problem};
use crate::routes::error_problem;
/// Whose open pull requests to list.
#[derive(Debug, Deserialize, IntoParams)]
@ -36,7 +37,7 @@ pub(crate) struct PullsQuery {
tag = "pulls"
)]
pub(crate) async fn get_pull_repos(
State(state): State<AppState>,
State(state): State<GitForgeState>,
) -> Result<Json<Vec<String>>, ProblemDetails> {
let Some(client) = state.forge.get() else {
return Err(no_forge());
@ -61,7 +62,7 @@ pub(crate) async fn get_pull_repos(
tag = "pulls"
)]
pub(crate) async fn get_pulls(
State(state): State<AppState>,
State(state): State<GitForgeState>,
query: Result<Query<PullsQuery>, QueryRejection>,
) -> Result<Json<Vec<OpenPull>>, ProblemDetails> {
let Query(query) = query.map_err(|e| error_problem(StatusCode::BAD_REQUEST, &e.body_text()))?;