fix(issues): a null Gitea timeline page ends the list (#995)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m58s
CI / Check (pull_request) Failing after 10m17s

Gitea answers an issue's timeline with `null` instead of `[]`, which
failed the whole issue poll of that Prüfobjekt at every run. A `null`
page now ends a list like an empty one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-14 10:40:58 +01:00
1 parent deda6d4867
commit 9255aa54e1
1 file changed
+76 -4
+76 -4
View File
@@ -114,7 +114,9 @@ impl GiteaTracker {
/// Every page of a list endpoint, `path` being the URL without `page` and
/// `limit`. Only an empty page ends the list: an instance may cap the page
/// size below ours (`[api] MAX_RESPONSE_ITEMS`).
/// size below ours (`[api] MAX_RESPONSE_ITEMS`). Gitea answers some lists
/// past their end with `null` instead of `[]` (an issue's timeline does),
/// which ends the list the same way.
///
/// # Errors
///
@@ -133,10 +135,11 @@ impl GiteaTracker {
let url = self.api_url(&format!(
"{path}{separator}page={page}&limit={LIST_PAGE_SIZE}"
));
let batch: Vec<T> = self.send_json(what, self.http.get(&url)).await?;
if batch.is_empty() {
// `Option` takes the `null` page; serde reads it as `None`.
let batch: Option<Vec<T>> = self.send_json(what, self.http.get(&url)).await?;
let Some(batch) = batch.filter(|b| !b.is_empty()) else {
return Ok(all);
}
};
all.extend(batch);
}
Err(CoreError::IssueTracker(format!(
@@ -800,6 +803,75 @@ mod tests {
assert_eq!(seen.lock().unwrap().len(), 4);
}
/// A fake Gitea whose issue timeline has one page of `entries`, then
/// answers `null` as Gitea does past the end of a timeline.
async fn fake_timeline(entries: serde_json::Value) -> String {
let app = Router::new()
.route(
"/api/v1/repos/{owner}/{repo}/issues/{number}/timeline",
get(
|axum::extract::Query(params): axum::extract::Query<
HashMap<String, String>,
>,
State(entries): State<serde_json::Value>| async move {
if params["page"] == "1" {
Json(entries)
} else {
Json(serde_json::Value::Null)
}
},
),
)
.with_state(entries);
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
format!("http://{addr}")
}
#[tokio::test]
async fn a_null_timeline_page_ends_the_list() {
let base = fake_timeline(serde_json::json!([])).await;
let tracker =
GiteaTracker::new(base, SecretString::from("t"), NetGuard::allow_private()).unwrap();
let entries: Vec<serde_json::Value> = tracker
.list_all("issue timeline", "/repos/o/r/issues/1/timeline", 3)
.await
.unwrap();
assert!(entries.is_empty());
let base = fake_timeline(serde_json::json!([{ "id": 1 }, { "id": 2 }])).await;
let tracker =
GiteaTracker::new(base, SecretString::from("t"), NetGuard::allow_private()).unwrap();
let entries: Vec<serde_json::Value> = tracker
.list_all("issue timeline", "/repos/o/r/issues/1/timeline", 3)
.await
.unwrap();
assert_eq!(entries.len(), 2, "the page before the null one counts");
}
#[tokio::test]
async fn a_null_first_timeline_page_is_an_empty_timeline() {
let app = Router::new().route(
"/api/v1/repos/{owner}/{repo}/issues/{number}/timeline",
get(|| async { Json(serde_json::Value::Null) }),
);
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
tokio::spawn(async move { axum::serve(listener, app).await.unwrap() });
let tracker = GiteaTracker::new(
format!("http://{addr}"),
SecretString::from("t"),
NetGuard::allow_private(),
)
.unwrap();
let entries: Vec<serde_json::Value> = tracker
.list_all("issue timeline", "/repos/o/r/issues/1/timeline", 3)
.await
.unwrap();
assert!(entries.is_empty());
}
#[tokio::test]
async fn a_failed_listing_is_an_error_not_an_empty_list() {
let app = Router::new().route(