From 6cd7582070b0a07ee04ae8f765d9646c41282a90 Mon Sep 17 00:00:00 2001 From: Shivakumar Date: Mon, 3 Aug 2026 16:07:28 +0530 Subject: [PATCH 01/22] feat(github): add issue body/labels/updated_at, comment id, filtered issue list --- src/github/issues.rs | 58 ++++++++++++++++++++++++++++++++++++++++++- src/github/models.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/github/issues.rs b/src/github/issues.rs index 0720c7367..27bb287ae 100644 --- a/src/github/issues.rs +++ b/src/github/issues.rs @@ -54,6 +54,33 @@ pub fn list(client: &Client, repo: &RepoId, state: &str) -> Result, G serde_json::from_value(json).map_err(|e| GitHubError::Parse(e.to_string())) } +/// Like [`list`], plus GitHub's server-side `labels` and `since` filters. +/// `since` is an ISO8601 timestamp matching `updated_at`, which keeps each +/// bridge poll cheap. +#[allow(dead_code)] +pub fn list_filtered( + client: &Client, + repo: &RepoId, + state: &str, + labels: Option<&str>, + since: Option<&str>, +) -> Result, GitHubError> { + let mut path = format!( + "/repos/{}/{}/issues?state={}", + repo.owner, + repo.repo, + crate::github::encode_query(state) + ); + if let Some(l) = labels { + path.push_str(&format!("&labels={}", crate::github::encode_query(l))); + } + if let Some(s) = since { + path.push_str(&format!("&since={}", crate::github::encode_query(s))); + } + let json = client.get_paginated(&path, crate::github::client::as_array)?; + serde_json::from_value(json).map_err(|e| GitHubError::Parse(e.to_string())) +} + pub fn get(client: &Client, repo: &RepoId, number: u64) -> Result { let path = format!("/repos/{}/{}/issues/{number}", repo.owner, repo.repo); let json = client.request("GET", &path, None)?; @@ -199,7 +226,7 @@ mod tests { fn list_comments_fetches_and_parses() { let server = MockServer::start(vec![MockResponse::json( 200, - r#"[{"user":{"login":"coderabbitai[bot]"},"body":"walkthrough...","created_at":"2026-07-19T00:00:00Z"}]"#, + r#"[{"id":1,"user":{"login":"coderabbitai[bot]"},"body":"walkthrough...","created_at":"2026-07-19T00:00:00Z"}]"#, )]); let client = server.client(None); let comments = list_comments(&client, &repo(), 4, None).unwrap(); @@ -247,4 +274,33 @@ mod tests { let sent: serde_json::Value = serde_json::from_str(&reqs[0].body).unwrap(); assert_eq!(sent["labels"][1], "b"); } + + #[test] + fn list_filtered_encodes_labels_and_since() { + let server = MockServer::start(vec![MockResponse::json(200, "[]")]); + let client = server.client(None); + list_filtered( + &client, + &repo(), + "open", + Some("agentflare"), + Some("2026-08-03T00:00:00Z"), + ) + .unwrap(); + assert_eq!( + server.requests()[0].path, + "/repos/o/r/issues?state=open&labels=agentflare&since=2026-08-03T00%3A00%3A00Z&per_page=100&page=1" + ); + } + + #[test] + fn list_filtered_omits_absent_filters() { + let server = MockServer::start(vec![MockResponse::json(200, "[]")]); + let client = server.client(None); + list_filtered(&client, &repo(), "open", None, None).unwrap(); + assert_eq!( + server.requests()[0].path, + "/repos/o/r/issues?state=open&per_page=100&page=1" + ); + } } diff --git a/src/github/models.rs b/src/github/models.rs index e8147f7ed..60e0c3a15 100644 --- a/src/github/models.rs +++ b/src/github/models.rs @@ -38,12 +38,27 @@ pub struct PullRequest { pub base: Option, } +#[derive(Debug, Clone, Deserialize)] +pub struct Label { + #[allow(dead_code)] + pub name: String, +} + #[derive(Debug, Clone, Deserialize)] pub struct Issue { pub number: u64, pub html_url: String, pub state: String, pub title: String, + #[serde(default)] + #[allow(dead_code)] + pub body: Option, + #[serde(default)] + #[allow(dead_code)] + pub labels: Vec