Changesets · Branches · Tags · Compare
| Changeset | a892c1a2d1de11318f3bba5a817a9bf039439846768fe60439f01e6d38d28626 |
|---|---|
| Author | WaylandYang <145302500+WaylandYang@users.noreply.github.com> · 2026-08-31 08:51 +08:00 |
| Committer | GitHub <noreply@github.com> · 2026-08-31 08:51 +08:00 |
| Parents | 81eda771c931 |
10 files changed
modified crates/utopia-server/src/ingest_sources.rs +79 −1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | //! 来源同步任务:url(网页抓取)/ rss(订阅,pubDate → doc_time)/ |
| 2 | -//! github_issues(工单,updated_at → doc_time,正文里带状态变更史)。 | |
| 2 | +//! github_issues / jira_issues(工单,更新时刻 → doc_time,正文里带状态变更史)。 | |
| 3 | 3 | //! 全部走 sha256 去重(重复内容静默跳过),新文档进标准摄入管道(process_document)。 |
| 4 | 4 | //! folder 是纯容器(上传入内),api 是推送型——两者无拉取语义。 |
| 5 | 5 | |
| @@ -52,6 +52,7 @@ | ||
| 52 | 52 | "rss" => sync_rss(state, &source).await, |
| 53 | 53 | "custom" => sync_custom(state, &source).await, |
| 54 | 54 | "github_issues" => sync_github_issues(state, &source).await, |
| 55 | + "jira_issues" => sync_jira_issues(state, &source).await, | |
| 55 | 56 | // folder / api 无拉取语义 |
| 56 | 57 | _ => Ok(SyncStats::default()), |
| 57 | 58 | }; |
| @@ -549,6 +550,83 @@ | ||
| 549 | 550 | Ok(stats) |
| 550 | 551 | } |
| 551 | 552 | |
| 553 | +/// Jira 工单:一张工单一篇文档,正文里带**字段级**的变更史。 | |
| 554 | +/// | |
| 555 | +/// 比 GitHub 那条路省:`search?expand=changelog` 一次调用就带回工单本体、 | |
| 556 | +/// 完整变更史与评论,**没有 N+1**。增量靠 JQL 的 `updated >= …` 表达, | |
| 557 | +/// 因为 Jira 没有 `since` 参数。详见 [`crate::jira_issues`]。 | |
| 558 | +/// | |
| 559 | +/// `doc_time` 取 `updated`,与 github_issues 同一口径:每次同步捕获的是 | |
| 560 | +/// "此刻这张工单是什么样",认知时间该说这个状态何时成立。 | |
| 561 | +async fn sync_jira_issues(state: &AppState, source: &Source) -> anyhow::Result<SyncStats> { | |
| 562 | + let base_url = source.config["base_url"] | |
| 563 | + .as_str() | |
| 564 | + .map(str::trim) | |
| 565 | + .filter(|s| !s.is_empty()) | |
| 566 | + .ok_or_else(|| anyhow::anyhow!("jira_issues source is missing config.base_url"))?; | |
| 567 | + let project = source.config["project"] | |
| 568 | + .as_str() | |
| 569 | + .map(str::trim) | |
| 570 | + .filter(|s| !s.is_empty()) | |
| 571 | + .ok_or_else(|| anyhow::anyhow!("jira_issues source is missing config.project"))?; | |
| 572 | + // 项目 key 直接拼进 JQL,所以不能是任意字符串。Jira 的 key 本身就限定 | |
| 573 | + // 字母数字加下划线——挡住它顺带挡住了 JQL 注入 | |
| 574 | + if !project.chars().all(|c| c.is_alphanumeric() || c == '_') { | |
| 575 | + anyhow::bail!("config.project should be a Jira project key, got {project:?}"); | |
| 576 | + } | |
| 577 | + let auth = source.config["auth_header"] | |
| 578 | + .as_str() | |
| 579 | + .map(str::trim) | |
| 580 | + .filter(|s| !s.is_empty()); | |
| 581 | + | |
| 582 | + let http = reqwest::Client::builder() | |
| 583 | + .timeout(std::time::Duration::from_secs(45)) | |
| 584 | + .user_agent(UA) | |
| 585 | + .build()?; | |
| 586 | + | |
| 587 | + let jql = crate::jira_issues::jql(project, source.last_sync_at); | |
| 588 | + let (issues, total) = crate::jira_issues::fetch_all(&http, base_url, &jql, auth).await?; | |
| 589 | + // **截断了就说出来。** 一个跑了多年的项目动辄上万张工单,翻页上限意味着 | |
| 590 | + // 这一轮只覆盖了一段;不报的话界面上"同步完成"就是一句误导 | |
| 591 | + if total > issues.len() as i64 { | |
| 592 | + tracing::warn!( | |
| 593 | + source_id = %source.id, | |
| 594 | + fetched = issues.len(), | |
| 595 | + total, | |
| 596 | + "Jira 结果被翻页上限截断,本轮只覆盖了一部分;下一轮的 JQL 窗口会接上" | |
| 597 | + ); | |
| 598 | + } | |
| 599 | + | |
| 600 | + let mut stats = SyncStats::default(); | |
| 601 | + for issue in issues.iter().take(MAX_NEW_PER_SYNC) { | |
| 602 | + let body = crate::jira_issues::render(issue); | |
| 603 | + // 逻辑身份带上站点:一个知识库接两个 Jira 时,PROJ-1 不会互相覆盖 | |
| 604 | + let host = reqwest::Url::parse(base_url) | |
| 605 | + .ok() | |
| 606 | + .and_then(|u| u.host_str().map(str::to_string)) | |
| 607 | + .unwrap_or_else(|| "jira".into()); | |
| 608 | + let key = format!("jira:{host}/{}", issue.key); | |
| 609 | + let filename = format!( | |
| 610 | + "{}-{}.md", | |
| 611 | + issue.key, | |
| 612 | + slugify(issue.fields.summary.as_deref().unwrap_or("")) | |
| 613 | + ); | |
| 614 | + let action = ingest_item( | |
| 615 | + state, | |
| 616 | + source.kb_id, | |
| 617 | + source.id, | |
| 618 | + &key, | |
| 619 | + &filename, | |
| 620 | + "text/markdown", | |
| 621 | + body.as_bytes(), | |
| 622 | + issue.fields.updated.map(|t| t.0), | |
| 623 | + ) | |
| 624 | + .await?; | |
| 625 | + stats.absorb(action); | |
| 626 | + } | |
| 627 | + Ok(stats) | |
| 628 | +} | |
| 629 | + | |
| 552 | 630 | /// 标题 → 文件名安全的片段。与 RSS 那条路同一个口径(非字母数字换成 -,截断)。 |
| 553 | 631 | fn slugify(title: &str) -> String { |
| 554 | 632 | let mut s: String = title |
added crates/utopia-server/src/jira_issues.rs +415 −0
| @@ -0,0 +1,415 @@ | ||
| 1 | +//! Jira 工单来源:一张工单 = 一篇文档,正文里带**字段级的变更史**。 | |
| 2 | +//! | |
| 3 | +//! 与 [`crate::github_issues`] 是同一个判断(别取现在,取变化),但 Jira 给的 | |
| 4 | +//! 原料更强,取法也更省: | |
| 5 | +//! | |
| 6 | +//! ## 一次调用就够 | |
| 7 | +//! | |
| 8 | +//! GitHub 那边要三次拉取,事件还被迫走逐工单(`issues/events` 不支持 `since`, | |
| 9 | +//! 且会被 PR 事件淹没)。Jira 的 `search` 一次就能带回全部: | |
| 10 | +//! | |
| 11 | +//! ```text | |
| 12 | +//! GET /rest/api/2/search?jql=…&expand=changelog&fields=…,comment | |
| 13 | +//! ``` | |
| 14 | +//! | |
| 15 | +//! 工单本体、完整变更史、评论一并返回,**没有 N+1**。 | |
| 16 | +//! | |
| 17 | +//! ## 变更史是字段级的 from → to | |
| 18 | +//! | |
| 19 | +//! GitHub 的事件只说"发生了 labeled",Jira 直接说"哪个字段从什么变成什么": | |
| 20 | +//! | |
| 21 | +//! ```text | |
| 22 | +//! 2026-08-24 Mickael Maison Version: (空) → 4.1.0 | |
| 23 | +//! 2026-08-24 Luke Chen status: Patch Available → Resolved | |
| 24 | +//! ``` | |
| 25 | +//! | |
| 26 | +//! 对账本来说这是更好的原料——`from`/`to` 本身就是一次认知变更的两端。 | |
| 27 | +//! | |
| 28 | +//! ## 增量靠 JQL,不靠 since 参数 | |
| 29 | +//! | |
| 30 | +//! Jira 没有 `since`,但 JQL 能表达:`updated >= "2026-08-30 12:00"`。 | |
| 31 | +//! 时间格式必须是 Jira 认的那种(不是 RFC3339),且**要带引号**—— | |
| 32 | +//! 这两点写错的症状都是 400,而不是"查不到"。 | |
| 33 | +//! | |
| 34 | +//! ## Server/DC 与 Cloud 的差别 | |
| 35 | +//! | |
| 36 | +//! 本模块按 **API v2**(Jira Server/DC)写。Cloud 的 v3 把 `description` 与 | |
| 37 | +//! 评论正文换成了 ADF(一棵 JSON 树而非字符串)——那需要一个渲染器,是另一件事。 | |
| 38 | +//! v2 在 Cloud 上通常仍可用且返回字符串,所以先只做 v2;真遇到只有 v3 的实例 | |
| 39 | +//! 再补,那时才知道 ADF 的哪些节点是必须处理的。 | |
| 40 | + | |
| 41 | +use chrono::{DateTime, Utc}; | |
| 42 | +use serde::Deserialize; | |
| 43 | + | |
| 44 | +/// 一次同步最多翻多少页。Jira 的 `total` 常常是几万,全量拉回来没有意义—— | |
| 45 | +/// 增量窗口之外的等下一次 JQL 取。 | |
| 46 | +const MAX_PAGES: u32 = 10; | |
| 47 | +const PAGE_SIZE: u32 = 50; | |
| 48 | + | |
| 49 | +/// 想要的字段。**必须显式列**:不列 `comment` 就不返回评论, | |
| 50 | +/// 而默认返回全部字段会把响应撑到几百 KB 一条。 | |
| 51 | +const FIELDS: &str = "summary,status,issuetype,priority,created,updated,resolutiondate,\ | |
| 52 | + labels,assignee,reporter,description,comment"; | |
| 53 | + | |
| 54 | +#[derive(Debug, Deserialize)] | |
| 55 | +pub struct SearchPage { | |
| 56 | + #[serde(default)] | |
| 57 | + pub issues: Vec<Issue>, | |
| 58 | + #[serde(default)] | |
| 59 | + pub total: i64, | |
| 60 | +} | |
| 61 | + | |
| 62 | +#[derive(Debug, Deserialize)] | |
| 63 | +pub struct Issue { | |
| 64 | + pub key: String, | |
| 65 | + pub fields: Fields, | |
| 66 | + /// 只有 `expand=changelog` 时才有 | |
| 67 | + #[serde(default)] | |
| 68 | + pub changelog: Option<Changelog>, | |
| 69 | +} | |
| 70 | + | |
| 71 | +#[derive(Debug, Deserialize)] | |
| 72 | +pub struct Fields { | |
| 73 | + pub summary: Option<String>, | |
| 74 | + pub description: Option<String>, | |
| 75 | + pub created: Option<JiraTime>, | |
| 76 | + pub updated: Option<JiraTime>, | |
| 77 | + pub resolutiondate: Option<JiraTime>, | |
| 78 | + pub status: Option<Named>, | |
| 79 | + pub issuetype: Option<Named>, | |
| 80 | + pub priority: Option<Named>, | |
| 81 | + pub assignee: Option<User>, | |
| 82 | + pub reporter: Option<User>, | |
| 83 | + #[serde(default)] | |
| 84 | + pub labels: Vec<String>, | |
| 85 | + pub comment: Option<Comments>, | |
| 86 | +} | |
| 87 | + | |
| 88 | +/// Jira 的时间戳是 `2026-08-24T11:11:52.944+0000`——**没有冒号的时区偏移**, | |
| 89 | +/// 不是 RFC3339。chrono 的 `DateTime<Utc>` 默认解不了它。 | |
| 90 | +#[derive(Debug, Clone, Copy)] | |
| 91 | +pub struct JiraTime(pub DateTime<Utc>); | |
| 92 | + | |
| 93 | +impl<'de> Deserialize<'de> for JiraTime { | |
| 94 | + fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> { | |
| 95 | + let s = String::deserialize(d)?; | |
| 96 | + DateTime::parse_from_str(&s, "%Y-%m-%dT%H:%M:%S%.3f%z") | |
| 97 | + .or_else(|_| DateTime::parse_from_rfc3339(&s)) | |
| 98 | + .map(|t| JiraTime(t.with_timezone(&Utc))) | |
| 99 | + .map_err(serde::de::Error::custom) | |
| 100 | + } | |
| 101 | +} | |
| 102 | + | |
| 103 | +#[derive(Debug, Deserialize)] | |
| 104 | +pub struct Named { | |
| 105 | + pub name: Option<String>, | |
| 106 | +} | |
| 107 | + | |
| 108 | +#[derive(Debug, Deserialize)] | |
| 109 | +pub struct User { | |
| 110 | + #[serde(alias = "displayName")] | |
| 111 | + pub display_name: Option<String>, | |
| 112 | +} | |
| 113 | + | |
| 114 | +#[derive(Debug, Deserialize)] | |
| 115 | +pub struct Comments { | |
| 116 | + #[serde(default)] | |
| 117 | + pub comments: Vec<Comment>, | |
| 118 | +} | |
| 119 | + | |
| 120 | +#[derive(Debug, Deserialize)] | |
| 121 | +pub struct Comment { | |
| 122 | + pub author: Option<User>, | |
| 123 | + pub created: Option<JiraTime>, | |
| 124 | + pub body: Option<String>, | |
| 125 | +} | |
| 126 | + | |
| 127 | +#[derive(Debug, Deserialize)] | |
| 128 | +pub struct Changelog { | |
| 129 | + #[serde(default)] | |
| 130 | + pub histories: Vec<History>, | |
| 131 | +} | |
| 132 | + | |
| 133 | +#[derive(Debug, Deserialize)] | |
| 134 | +pub struct History { | |
| 135 | + pub created: Option<JiraTime>, | |
| 136 | + pub author: Option<User>, | |
| 137 | + #[serde(default)] | |
| 138 | + pub items: Vec<ChangeItem>, | |
| 139 | +} | |
| 140 | + | |
| 141 | +#[derive(Debug, Deserialize)] | |
| 142 | +pub struct ChangeItem { | |
| 143 | + pub field: Option<String>, | |
| 144 | + #[serde(alias = "fromString")] | |
| 145 | + pub from_string: Option<String>, | |
| 146 | + #[serde(alias = "toString")] | |
| 147 | + pub to_string: Option<String>, | |
| 148 | +} | |
| 149 | + | |
| 150 | +fn name(n: &Option<Named>) -> Option<&str> { | |
| 151 | + n.as_ref()?.name.as_deref() | |
| 152 | +} | |
| 153 | +fn who(u: &Option<User>) -> &str { | |
| 154 | + u.as_ref() | |
| 155 | + .and_then(|x| x.display_name.as_deref()) | |
| 156 | + .unwrap_or("?") | |
| 157 | +} | |
| 158 | + | |
| 159 | +/// 把一张工单排成一篇文档。**纯函数,不联网**——取回与组织分开,组织这一半测得动。 | |
| 160 | +pub fn render(issue: &Issue) -> String { | |
| 161 | + let f = &issue.fields; | |
| 162 | + let mut out = String::new(); | |
| 163 | + out.push_str(&format!( | |
| 164 | + "# {} {}\n\n", | |
| 165 | + issue.key, | |
| 166 | + f.summary.as_deref().unwrap_or("") | |
| 167 | + )); | |
| 168 | + | |
| 169 | + // 抬头写成带日期的陈述句,不是键值对:抽取器读的是句子, | |
| 170 | + // "Reported by X on 2026-08-24" 能抽出带 valid_from 的事实 | |
| 171 | + if let (Some(r), Some(c)) = (&f.reporter, &f.created) { | |
| 172 | + out.push_str(&format!( | |
| 173 | + "Reported by {} on {}.\n", | |
| 174 | + who(&Some(User { | |
| 175 | + display_name: r.display_name.clone() | |
| 176 | + })), | |
| 177 | + c.0.format("%Y-%m-%d") | |
| 178 | + )); | |
| 179 | + } | |
| 180 | + if let Some(t) = name(&f.issuetype) { | |
| 181 | + out.push_str(&format!("Type {t}.\n")); | |
| 182 | + } | |
| 183 | + if let Some(s) = name(&f.status) { | |
| 184 | + out.push_str(&format!("Currently {s}.\n")); | |
| 185 | + } | |
| 186 | + if let Some(p) = name(&f.priority) { | |
| 187 | + out.push_str(&format!("Priority {p}.\n")); | |
| 188 | + } | |
| 189 | + if let Some(a) = &f.assignee { | |
| 190 | + out.push_str(&format!( | |
| 191 | + "Assigned to {}.\n", | |
| 192 | + a.display_name.as_deref().unwrap_or("?") | |
| 193 | + )); | |
| 194 | + } | |
| 195 | + if let Some(r) = &f.resolutiondate { | |
| 196 | + out.push_str(&format!("Resolved on {}.\n", r.0.format("%Y-%m-%d"))); | |
| 197 | + } | |
| 198 | + if !f.labels.is_empty() { | |
| 199 | + out.push_str(&format!("Labelled {}.\n", f.labels.join(", "))); | |
| 200 | + } | |
| 201 | + | |
| 202 | + if let Some(d) = f | |
| 203 | + .description | |
| 204 | + .as_deref() | |
| 205 | + .map(str::trim) | |
| 206 | + .filter(|d| !d.is_empty()) | |
| 207 | + { | |
| 208 | + out.push_str("\n## Description\n\n"); | |
| 209 | + out.push_str(d); | |
| 210 | + out.push('\n'); | |
| 211 | + } | |
| 212 | + | |
| 213 | + // **字段级变更史。** Jira 比 GitHub 多给的正是这个:不只是"发生了什么事件", | |
| 214 | + // 而是"哪个字段从什么变成了什么"——from/to 本身就是一次认知变更的两端 | |
| 215 | + let mut lines: Vec<(DateTime<Utc>, String)> = Vec::new(); | |
| 216 | + for h in issue.changelog.iter().flat_map(|c| c.histories.iter()) { | |
| 217 | + let Some(at) = h.created else { continue }; | |
| 218 | + for item in &h.items { | |
| 219 | + let Some(field) = item.field.as_deref() else { | |
| 220 | + continue; | |
| 221 | + }; | |
| 222 | + let from = item.from_string.as_deref().unwrap_or("(empty)"); | |
| 223 | + let to = item.to_string.as_deref().unwrap_or("(empty)"); | |
| 224 | + lines.push(( | |
| 225 | + at.0, | |
| 226 | + format!( | |
| 227 | + "- {} — {} changed {field}: {from} → {to}\n", | |
| 228 | + at.0.format("%Y-%m-%d"), | |
| 229 | + who(&h.author), | |
| 230 | + ), | |
| 231 | + )); | |
| 232 | + } | |
| 233 | + } | |
| 234 | + if !lines.is_empty() { | |
| 235 | + // 端点的顺序不是契约,排序自己做——排错了的后果是历史倒着讲 | |
| 236 | + lines.sort_by_key(|(t, _)| *t); | |
| 237 | + out.push_str("\n## History\n\n"); | |
| 238 | + for (_, l) in &lines { | |
| 239 | + out.push_str(l); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + | |
| 243 | + let comments: Vec<&Comment> = f | |
| 244 | + .comment | |
| 245 | + .as_ref() | |
| 246 | + .map(|c| c.comments.iter().collect()) | |
| 247 | + .unwrap_or_default(); | |
| 248 | + if !comments.is_empty() { | |
| 249 | + out.push_str("\n## Comments\n\n"); | |
| 250 | + for c in comments { | |
| 251 | + let body = c.body.as_deref().unwrap_or("").trim(); | |
| 252 | + if body.is_empty() { | |
| 253 | + continue; | |
| 254 | + } | |
| 255 | + let at = c | |
| 256 | + .created | |
| 257 | + .map(|t| t.0.format("%Y-%m-%d").to_string()) | |
| 258 | + .unwrap_or_else(|| "?".into()); | |
| 259 | + out.push_str(&format!("### {} on {}\n\n{}\n\n", who(&c.author), at, body)); | |
| 260 | + } | |
| 261 | + } | |
| 262 | + out | |
| 263 | +} | |
| 264 | + | |
| 265 | +/// 增量用的 JQL。**时间格式是 Jira 自己的**(`yyyy-MM-dd HH:mm`),不是 RFC3339, | |
| 266 | +/// 而且要带引号——两点写错的症状都是 400,不是"查不到"。 | |
| 267 | +pub fn jql(project: &str, since: Option<DateTime<Utc>>) -> String { | |
| 268 | + let mut q = format!("project = {project}"); | |
| 269 | + if let Some(t) = since { | |
| 270 | + q.push_str(&format!( | |
| 271 | + " AND updated >= \"{}\"", | |
| 272 | + t.format("%Y-%m-%d %H:%M") | |
| 273 | + )); | |
| 274 | + } | |
| 275 | + q.push_str(" ORDER BY updated ASC"); | |
| 276 | + q | |
| 277 | +} | |
| 278 | + | |
| 279 | +/// 分页取。Jira 用 `startAt`/`maxResults`,`total` 常常是几万—— | |
| 280 | +/// 靠 MAX_PAGES 封顶,剩下的等下一次增量窗口。 | |
| 281 | +/// | |
| 282 | +/// **把 `total` 一起返回**:截断了就得说出来。取回 500 条而服务端有 14506 条时, | |
| 283 | +/// 界面上"同步完成"是一句误导——真实情况是"这一轮只覆盖了一小段"。 | |
| 284 | +pub async fn fetch_all( | |
| 285 | + http: &reqwest::Client, | |
| 286 | + base_url: &str, | |
| 287 | + jql: &str, | |
| 288 | + auth: Option<&str>, | |
| 289 | +) -> anyhow::Result<(Vec<Issue>, i64)> { | |
| 290 | + let mut out = Vec::new(); | |
| 291 | + let mut total = 0i64; | |
| 292 | + for page in 0..MAX_PAGES { | |
| 293 | + let mut url = reqwest::Url::parse(&format!( | |
| 294 | + "{}/rest/api/2/search", | |
| 295 | + base_url.trim_end_matches('/') | |
| 296 | + ))?; | |
| 297 | + { | |
| 298 | + let mut q = url.query_pairs_mut(); | |
| 299 | + q.append_pair("jql", jql); | |
| 300 | + q.append_pair("expand", "changelog"); | |
| 301 | + q.append_pair("fields", FIELDS); | |
| 302 | + q.append_pair("maxResults", &PAGE_SIZE.to_string()); | |
| 303 | + q.append_pair("startAt", &(page * PAGE_SIZE).to_string()); | |
| 304 | + } | |
| 305 | + let mut req = http | |
| 306 | + .get(url) | |
| 307 | + .header(reqwest::header::ACCEPT, "application/json"); | |
| 308 | + if let Some(a) = auth { | |
| 309 | + req = req.header(reqwest::header::AUTHORIZATION, a); | |
| 310 | + } | |
| 311 | + let resp = req.send().await?; | |
| 312 | + let status = resp.status(); | |
| 313 | + if !status.is_success() { | |
| 314 | + // Jira 把 JQL 语法错误也报成 400,正文里才是原因。 | |
| 315 | + // 只说 "HTTP 400" 会让人去查网络,而真正该改的是 project key 或时间格式 | |
| 316 | + let detail = resp.text().await.unwrap_or_default(); | |
| 317 | + anyhow::bail!( | |
| 318 | + "HTTP {status} from Jira: {}", | |
| 319 | + detail.chars().take(200).collect::<String>() | |
| 320 | + ); | |
| 321 | + } | |
| 322 | + let page_data: SearchPage = resp.json().await?; | |
| 323 | + total = page_data.total; | |
| 324 | + let n = page_data.issues.len(); | |
| 325 | + out.extend(page_data.issues); | |
| 326 | + if n < PAGE_SIZE as usize { | |
| 327 | + break; | |
| 328 | + } | |
| 329 | + } | |
| 330 | + Ok((out, total)) | |
| 331 | +} | |
| 332 | + | |
| 333 | +#[cfg(test)] | |
| 334 | +mod tests { | |
| 335 | + use super::*; | |
| 336 | + | |
| 337 | + /// **Jira 的时间戳不是 RFC3339。** `+0000` 没有冒号,chrono 的默认实现解不了。 | |
| 338 | + /// 这一条是整个模块最容易悄悄坏掉的地方:解不出来就是整页工单丢掉。 | |
| 339 | + #[test] | |
| 340 | + fn jira_timestamps_are_not_rfc3339() { | |
| 341 | + let t: JiraTime = serde_json::from_str("\"2026-08-24T11:11:52.944+0000\"").unwrap(); | |
| 342 | + assert_eq!(t.0.format("%Y-%m-%d %H:%M").to_string(), "2026-08-24 11:11"); | |
| 343 | + // 真 RFC3339 也要能收(Cloud 某些端点会给这种) | |
| 344 | + let t2: JiraTime = serde_json::from_str("\"2026-08-24T11:11:52.944+00:00\"").unwrap(); | |
| 345 | + assert_eq!(t2.0.format("%Y-%m-%d").to_string(), "2026-08-24"); | |
| 346 | + } | |
| 347 | + | |
| 348 | + /// JQL 的时间格式与引号:两点写错都报 400,而不是"查不到"。 | |
| 349 | + #[test] | |
| 350 | + fn the_incremental_jql_uses_jiras_own_time_format() { | |
| 351 | + let t = DateTime::parse_from_rfc3339("2026-08-30T12:34:56Z") | |
| 352 | + .unwrap() | |
| 353 | + .with_timezone(&Utc); | |
| 354 | + let q = jql("KAFKA", Some(t)); | |
| 355 | + assert!(q.contains("project = KAFKA"), "{q}"); | |
| 356 | + assert!(q.contains("updated >= \"2026-08-30 12:34\""), "{q}"); | |
| 357 | + assert!(q.contains("ORDER BY updated ASC"), "{q}"); | |
| 358 | + // 没有 since 时不该带上 updated 子句。**查子句不查词**—— | |
| 359 | + // ORDER BY updated ASC 里也有 "updated",第一版断言就栽在这上面 | |
| 360 | + assert!(!jql("KAFKA", None).contains("updated >=")); | |
| 361 | + } | |
| 362 | + | |
| 363 | + /// **拿真实响应钉住字段形状。** | |
| 364 | + /// | |
| 365 | + /// 手写 JSON 只能证明"我以为的形状"。夹具取自 issues.apache.org(匿名可读), | |
| 366 | + /// 与 GitHub 那份同一个道理——而且这次它要钉的东西更多:Jira 的驼峰命名 | |
| 367 | + /// (`fromString`/`displayName`)、非 RFC3339 的时间、以及 changelog 的嵌套。 | |
| 368 | + #[test] | |
| 369 | + fn the_real_jira_shapes_still_parse() { | |
| 370 | + let raw = include_str!("../tests/fixtures/jira_issues.json"); | |
| 371 | + let page: SearchPage = serde_json::from_str(raw).expect("真实响应该解得出来"); | |
| 372 | + assert!(!page.issues.is_empty(), "夹具是空的,这条测试什么都没验"); | |
| 373 | + | |
| 374 | + for issue in &page.issues { | |
| 375 | + let doc = render(issue); | |
| 376 | + assert!(doc.starts_with(&format!("# {} ", issue.key)), "{doc}"); | |
| 377 | + } | |
| 378 | + | |
| 379 | + // 变更史是这个来源存在的理由。夹具里至少有一张带 changelog 的, | |
| 380 | + // 且必须排成"字段: 旧值 → 新值"——只写"发生了变更"等于没说 | |
| 381 | + let with_log = page | |
| 382 | + .issues | |
| 383 | + .iter() | |
| 384 | + .find(|i| { | |
| 385 | + i.changelog | |
| 386 | + .as_ref() | |
| 387 | + .is_some_and(|c| c.histories.iter().any(|h| !h.items.is_empty())) | |
| 388 | + }) | |
| 389 | + .expect("夹具里该有带 changelog 的工单"); | |
| 390 | + let doc = render(with_log); | |
| 391 | + assert!(doc.contains("## History"), "历史一节缺失:{doc}"); | |
| 392 | + assert!(doc.contains(" changed "), "变更行没写成字段级:{doc}"); | |
| 393 | + assert!(doc.contains(" → "), "缺少 from → to:{doc}"); | |
| 394 | + } | |
| 395 | + | |
| 396 | + /// 空评论不该留下一个只有标题的空节(与 GitHub 那边同一个口径)。 | |
| 397 | + #[test] | |
| 398 | + fn an_empty_comment_leaves_no_stub() { | |
| 399 | + let issue: Issue = serde_json::from_value(serde_json::json!({ | |
| 400 | + "key": "X-1", | |
| 401 | + "fields": { | |
| 402 | + "summary": "t", "description": null, "labels": [], | |
| 403 | + "created": "2026-01-01T00:00:00.000+0000", | |
| 404 | + "updated": "2026-01-01T00:00:00.000+0000", | |
| 405 | + "comment": {"comments": [ | |
| 406 | + {"author": {"displayName": "a"}, | |
| 407 | + "created": "2026-01-02T00:00:00.000+0000", "body": " "} | |
| 408 | + ]} | |
| 409 | + } | |
| 410 | + })) | |
| 411 | + .unwrap(); | |
| 412 | + let out = render(&issue); | |
| 413 | + assert!(!out.contains("### a"), "空评论不该留下小节:{out}"); | |
| 414 | + } | |
| 415 | +} |
modified crates/utopia-server/src/main.rs +1 −0
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | mod extraction; |
| 11 | 11 | mod github_issues; |
| 12 | 12 | mod ingest_sources; |
| 13 | +mod jira_issues; | |
| 13 | 14 | mod llm_util; |
| 14 | 15 | mod mappings; |
| 15 | 16 | mod ontology_index; |
added crates/utopia-server/tests/fixtures/jira_issues.json +372 −0
| @@ -0,0 +1,372 @@ | ||
| 1 | +{ | |
| 2 | + "note": "取自 issues.apache.org(匿名可读,Jira Server API v2),字段已裁到我们声明的那些。", | |
| 3 | + "total": 14506, | |
| 4 | + "issues": [ | |
| 5 | + { | |
| 6 | + "key": "KAFKA-20979", | |
| 7 | + "fields": { | |
| 8 | + "summary": "Potential data loss caused by time index truncation", | |
| 9 | + "description": "On broker startup, I see these lines for many partitions:\r\n\r\n{noformat}\r\n[LocalLog partition=TOPIC-0, dir=LOG_DIR/TOPIC-0] Rolled new log segment at offset 83461 in 0 ms.\r\n[UnifiedLog partition=TOPIC-0, dir=LOG_DIR] Incremented log start offset to 83461 due to segment deletion\r\n[UnifiedLog partition", | |
| 10 | + "created": "2026-08-24T10:49:20.000+0000", | |
| 11 | + "updated": "2026-08-29T01:42:46.000+0000", | |
| 12 | + "resolutiondate": "2026-08-28T10:45:31.000+0000", | |
| 13 | + "status": { | |
| 14 | + "name": "Resolved" | |
| 15 | + }, | |
| 16 | + "issuetype": { | |
| 17 | + "name": "Bug" | |
| 18 | + }, | |
| 19 | + "priority": { | |
| 20 | + "name": "Major" | |
| 21 | + }, | |
| 22 | + "assignee": { | |
| 23 | + "displayName": "Mickael Maison" | |
| 24 | + }, | |
| 25 | + "reporter": { | |
| 26 | + "displayName": "Mickael Maison" | |
| 27 | + }, | |
| 28 | + "labels": [], | |
| 29 | + "comment": { | |
| 30 | + "comments": [ | |
| 31 | + { | |
| 32 | + "author": { | |
| 33 | + "displayName": "Luke Chen" | |
| 34 | + }, | |
| 35 | + "created": "2026-08-24T11:00:50.520+0000", | |
| 36 | + "body": "Given this issue will cause data loss for the impacted partitions, I think we should include this fix in v4.4.0." | |
| 37 | + }, | |
| 38 | + { | |
| 39 | + "author": { | |
| 40 | + "displayName": "Gaurav Narula" | |
| 41 | + }, | |
| 42 | + "created": "2026-08-24T11:01:08.145+0000", | |
| 43 | + "body": "[~mimaison] Which version was this observed in? In the past, IOException emitted by {{TimeIndex#close}} were swallowed and this was fixed with KAFKA-19221\r\n\r\n \r\n\r\nI've also raised KAFKA-19200 before t" | |
| 44 | + } | |
| 45 | + ] | |
| 46 | + } | |
| 47 | + }, | |
| 48 | + "changelog": { | |
| 49 | + "histories": [ | |
| 50 | + { | |
| 51 | + "created": "2026-08-24T11:11:52.944+0000", | |
| 52 | + "author": { | |
| 53 | + "displayName": "Mickael Maison" | |
| 54 | + }, | |
| 55 | + "items": [ | |
| 56 | + { | |
| 57 | + "field": "Version", | |
| 58 | + "fromString": null, | |
| 59 | + "toString": "4.1.0" | |
| 60 | + } | |
| 61 | + ] | |
| 62 | + }, | |
| 63 | + { | |
| 64 | + "created": "2026-08-24T13:47:12.000+0000", | |
| 65 | + "author": { | |
| 66 | + "displayName": "ASF GitHub Bot" | |
| 67 | + }, | |
| 68 | + "items": [ | |
| 69 | + { | |
| 70 | + "field": "RemoteIssueLink", | |
| 71 | + "fromString": null, | |
| 72 | + "toString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"" | |
| 73 | + } | |
| 74 | + ] | |
| 75 | + }, | |
| 76 | + { | |
| 77 | + "created": "2026-08-24T19:52:18.531+0000", | |
| 78 | + "author": { | |
| 79 | + "displayName": "ASF GitHub Bot" | |
| 80 | + }, | |
| 81 | + "items": [ | |
| 82 | + { | |
| 83 | + "field": "RemoteIssueLink", | |
| 84 | + "fromString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"", | |
| 85 | + "toString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"" | |
| 86 | + } | |
| 87 | + ] | |
| 88 | + }, | |
| 89 | + { | |
| 90 | + "created": "2026-08-25T01:44:17.716+0000", | |
| 91 | + "author": { | |
| 92 | + "displayName": "ASF GitHub Bot" | |
| 93 | + }, | |
| 94 | + "items": [ | |
| 95 | + { | |
| 96 | + "field": "RemoteIssueLink", | |
| 97 | + "fromString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"", | |
| 98 | + "toString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"" | |
| 99 | + } | |
| 100 | + ] | |
| 101 | + }, | |
| 102 | + { | |
| 103 | + "created": "2026-08-26T09:16:22.571+0000", | |
| 104 | + "author": { | |
| 105 | + "displayName": "ASF GitHub Bot" | |
| 106 | + }, | |
| 107 | + "items": [ | |
| 108 | + { | |
| 109 | + "field": "RemoteIssueLink", | |
| 110 | + "fromString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"", | |
| 111 | + "toString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"" | |
| 112 | + } | |
| 113 | + ] | |
| 114 | + }, | |
| 115 | + { | |
| 116 | + "created": "2026-08-26T10:41:20.396+0000", | |
| 117 | + "author": { | |
| 118 | + "displayName": "ASF GitHub Bot" | |
| 119 | + }, | |
| 120 | + "items": [ | |
| 121 | + { | |
| 122 | + "field": "RemoteIssueLink", | |
| 123 | + "fromString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"", | |
| 124 | + "toString": "This issue links to \"GitHub Pull Request #23258 (Web Link)\"" | |
| 125 | + } | |
| 126 | + ] | |
| 127 | + } | |
| 128 | + ] | |
| 129 | + } | |
| 130 | + }, | |
| 131 | + { | |
| 132 | + "key": "KAFKA-20992", | |
| 133 | + "fields": { | |
| 134 | + "summary": "Remove hamcrest from org.apache.kafka.test package", | |
| 135 | + "description": "MockApiFixedKeyProcessor", | |
| 136 | + "created": "2026-08-26T16:07:58.000+0000", | |
| 137 | + "updated": "2026-08-28T19:46:33.000+0000", | |
| 138 | + "resolutiondate": "2026-08-28T19:46:33.000+0000", | |
| 139 | + "status": { | |
| 140 | + "name": "Resolved" | |
| 141 | + }, | |
| 142 | + "issuetype": { | |
| 143 | + "name": "Sub-task" | |
| 144 | + }, | |
| 145 | + "priority": { | |
| 146 | + "name": "Major" | |
| 147 | + }, | |
| 148 | + "assignee": { | |
| 149 | + "displayName": "Hung-Yau Su" | |
| 150 | + }, | |
| 151 | + "reporter": { | |
| 152 | + "displayName": "Chia-Ping Tsai" | |
| 153 | + }, | |
| 154 | + "labels": [], | |
| 155 | + "comment": { | |
| 156 | + "comments": [] | |
| 157 | + } | |
| 158 | + }, | |
| 159 | + "changelog": { | |
| 160 | + "histories": [ | |
| 161 | + { | |
| 162 | + "created": "2026-08-26T16:27:00.509+0000", | |
| 163 | + "author": { | |
| 164 | + "displayName": "Hung-Yau Su" | |
| 165 | + }, | |
| 166 | + "items": [ | |
| 167 | + { | |
| 168 | + "field": "assignee", | |
| 169 | + "fromString": "Chia-Ping Tsai", | |
| 170 | + "toString": "HungYau Su" | |
| 171 | + } | |
| 172 | + ] | |
| 173 | + }, | |
| 174 | + { | |
| 175 | + "created": "2026-08-26T21:02:35.220+0000", | |
| 176 | + "author": { | |
| 177 | + "displayName": "ASF GitHub Bot" | |
| 178 | + }, | |
| 179 | + "items": [ | |
| 180 | + { | |
| 181 | + "field": "RemoteIssueLink", | |
| 182 | + "fromString": null, | |
| 183 | + "toString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"" | |
| 184 | + } | |
| 185 | + ] | |
| 186 | + }, | |
| 187 | + { | |
| 188 | + "created": "2026-08-27T01:37:22.934+0000", | |
| 189 | + "author": { | |
| 190 | + "displayName": "ASF GitHub Bot" | |
| 191 | + }, | |
| 192 | + "items": [ | |
| 193 | + { | |
| 194 | + "field": "RemoteIssueLink", | |
| 195 | + "fromString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"", | |
| 196 | + "toString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"" | |
| 197 | + } | |
| 198 | + ] | |
| 199 | + }, | |
| 200 | + { | |
| 201 | + "created": "2026-08-27T01:59:34.817+0000", | |
| 202 | + "author": { | |
| 203 | + "displayName": "ASF GitHub Bot" | |
| 204 | + }, | |
| 205 | + "items": [ | |
| 206 | + { | |
| 207 | + "field": "RemoteIssueLink", | |
| 208 | + "fromString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"", | |
| 209 | + "toString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"" | |
| 210 | + } | |
| 211 | + ] | |
| 212 | + }, | |
| 213 | + { | |
| 214 | + "created": "2026-08-27T12:26:39.880+0000", | |
| 215 | + "author": { | |
| 216 | + "displayName": "ASF GitHub Bot" | |
| 217 | + }, | |
| 218 | + "items": [ | |
| 219 | + { | |
| 220 | + "field": "RemoteIssueLink", | |
| 221 | + "fromString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"", | |
| 222 | + "toString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"" | |
| 223 | + } | |
| 224 | + ] | |
| 225 | + }, | |
| 226 | + { | |
| 227 | + "created": "2026-08-27T18:21:14.861+0000", | |
| 228 | + "author": { | |
| 229 | + "displayName": "ASF GitHub Bot" | |
| 230 | + }, | |
| 231 | + "items": [ | |
| 232 | + { | |
| 233 | + "field": "RemoteIssueLink", | |
| 234 | + "fromString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"", | |
| 235 | + "toString": "This issue links to \"GitHub Pull Request #23287 (Web Link)\"" | |
| 236 | + } | |
| 237 | + ] | |
| 238 | + } | |
| 239 | + ] | |
| 240 | + } | |
| 241 | + }, | |
| 242 | + { | |
| 243 | + "key": "KAFKA-20920", | |
| 244 | + "fields": { | |
| 245 | + "summary": "Document new group coordinator executor metrics", | |
| 246 | + "description": "We forgot to update docs/operations/monitoring.md in KAFKA-20211.", | |
| 247 | + "created": "2026-08-11T05:45:35.000+0000", | |
| 248 | + "updated": "2026-08-28T16:31:21.000+0000", | |
| 249 | + "resolutiondate": "2026-08-28T16:31:21.000+0000", | |
| 250 | + "status": { | |
| 251 | + "name": "Resolved" | |
| 252 | + }, | |
| 253 | + "issuetype": { | |
| 254 | + "name": "Sub-task" | |
| 255 | + }, | |
| 256 | + "priority": { | |
| 257 | + "name": "Major" | |
| 258 | + }, | |
| 259 | + "assignee": { | |
| 260 | + "displayName": "Sean Quah" | |
| 261 | + }, | |
| 262 | + "reporter": { | |
| 263 | + "displayName": "Sean Quah" | |
| 264 | + }, | |
| 265 | + "labels": [], | |
| 266 | + "comment": { | |
| 267 | + "comments": [ | |
| 268 | + { | |
| 269 | + "author": { | |
| 270 | + "displayName": "Omnia Ibrahim" | |
| 271 | + }, | |
| 272 | + "created": "2026-08-13T14:31:26.632+0000", | |
| 273 | + "body": "Moving to 4.5 as we are now in 4.4.0 code freeze\r\n " | |
| 274 | + } | |
| 275 | + ] | |
| 276 | + } | |
| 277 | + }, | |
| 278 | + "changelog": { | |
| 279 | + "histories": [ | |
| 280 | + { | |
| 281 | + "created": "2026-08-11T05:46:35.379+0000", | |
| 282 | + "author": { | |
| 283 | + "displayName": "Sean Quah" | |
| 284 | + }, | |
| 285 | + "items": [ | |
| 286 | + { | |
| 287 | + "field": "Fix Version", | |
| 288 | + "fromString": null, | |
| 289 | + "toString": "4.4.0" | |
| 290 | + } | |
| 291 | + ] | |
| 292 | + }, | |
| 293 | + { | |
| 294 | + "created": "2026-08-11T05:46:45.890+0000", | |
| 295 | + "author": { | |
| 296 | + "displayName": "Sean Quah" | |
| 297 | + }, | |
| 298 | + "items": [ | |
| 299 | + { | |
| 300 | + "field": "Fix Version", | |
| 301 | + "fromString": null, | |
| 302 | + "toString": "4.3.2" | |
| 303 | + } | |
| 304 | + ] | |
| 305 | + }, | |
| 306 | + { | |
| 307 | + "created": "2026-08-11T06:08:10.727+0000", | |
| 308 | + "author": { | |
| 309 | + "displayName": "ASF GitHub Bot" | |
| 310 | + }, | |
| 311 | + "items": [ | |
| 312 | + { | |
| 313 | + "field": "RemoteIssueLink", | |
| 314 | + "fromString": null, | |
| 315 | + "toString": "This issue links to \"GitHub Pull Request #23127 (Web Link)\"" | |
| 316 | + } | |
| 317 | + ] | |
| 318 | + }, | |
| 319 | + { | |
| 320 | + "created": "2026-08-11T06:10:34.357+0000", | |
| 321 | + "author": { | |
| 322 | + "displayName": "ASF GitHub Bot" | |
| 323 | + }, | |
| 324 | + "items": [ | |
| 325 | + { | |
| 326 | + "field": "RemoteIssueLink", | |
| 327 | + "fromString": "This issue links to \"GitHub Pull Request #23127 (Web Link)\"", | |
| 328 | + "toString": "This issue links to \"GitHub Pull Request #23127 (Web Link)\"" | |
| 329 | + } | |
| 330 | + ] | |
| 331 | + }, | |
| 332 | + { | |
| 333 | + "created": "2026-08-11T06:37:48.208+0000", | |
| 334 | + "author": { | |
| 335 | + "displayName": "Sean Quah" | |
| 336 | + }, | |
| 337 | + "items": [ | |
| 338 | + { | |
| 339 | + "field": "assignee", | |
| 340 | + "fromString": null, | |
| 341 | + "toString": "Sean Quah" | |
| 342 | + } | |
| 343 | + ] | |
| 344 | + }, | |
| 345 | + { | |
| 346 | + "created": "2026-08-13T14:31:36.515+0000", | |
| 347 | + "author": { | |
| 348 | + "displayName": "Omnia Ibrahim" | |
| 349 | + }, | |
| 350 | + "items": [ | |
| 351 | + { | |
| 352 | + "field": "Fix Version", | |
| 353 | + "fromString": null, | |
| 354 | + "toString": "4.5.0" | |
| 355 | + }, | |
| 356 | + { | |
| 357 | + "field": "Fix Version", | |
| 358 | + "fromString": "4.4.0", | |
| 359 | + "toString": null | |
| 360 | + }, | |
| 361 | + { | |
| 362 | + "field": "Fix Version", | |
| 363 | + "fromString": "4.3.2", | |
| 364 | + "toString": null | |
| 365 | + } | |
| 366 | + ] | |
| 367 | + } | |
| 368 | + ] | |
| 369 | + } | |
| 370 | + } | |
| 371 | + ] | |
| 372 | +} | |
| No newline at the end of the file |
modified crates/utopia-store/src/sources.rs +10 −2
| @@ -10,12 +10,20 @@ | ||
| 10 | 10 | /// 本机目录监听(watch_folder)已否决——自部署用户看不到服务器磁盘; |
| 11 | 11 | /// 未来的 watch 形态是对象存储/网盘(P5 连接器,与 BlobStore 接缝配套)。 |
| 12 | 12 | /// custom = 自定义拉取器:任何实现 Utopia ingest 接口的 URL(返回 items JSON)即可定时摄取。 |
| 13 | -/// github_issues = 工单:一张工单连同它的状态变更史成为一篇文档。 | |
| 13 | +/// github_issues / jira_issues = 工单:一张工单连同它的状态变更史成为一篇文档。 | |
| 14 | 14 | /// |
| 15 | 15 | /// **改这里就得改前端那份清单**(`Library.tsx` 的建来源对话框与 `api.ts` 的 |
| 16 | 16 | /// `SourceView["kind"]`)。两处对不上时的症状是:界面上选得到、建的时候报 |
| 17 | 17 | /// 「kind must be one of…」——单元测试与 tsc 都看不见,只有端到端会撞上。 |
| 18 | -pub const KINDS: &[&str] = &["folder", "url", "rss", "api", "custom", "github_issues"]; | |
| 18 | +pub const KINDS: &[&str] = &[ | |
| 19 | + "folder", | |
| 20 | + "url", | |
| 21 | + "rss", | |
| 22 | + "api", | |
| 23 | + "custom", | |
| 24 | + "github_issues", | |
| 25 | + "jira_issues", | |
| 26 | +]; | |
| 19 | 27 | |
| 20 | 28 | /// 校验并规范化标准 5 段 cron 表达式(内部用 cron crate 的 6 段:补秒位)。 |
| 21 | 29 | pub fn validate_cron(expr: &str) -> AppResult<String> { |
modified web/src/api.ts +5 −0
| @@ -159,6 +159,7 @@ | ||
| 159 | 159 | | "api" |
| 160 | 160 | | "custom" |
| 161 | 161 | | "github_issues" |
| 162 | + | "jira_issues" | |
| 162 | 163 | | "memory" |
| 163 | 164 | | "upload"; |
| 164 | 165 | name: string; |
| @@ -170,6 +171,10 @@ | ||
| 170 | 171 | repo?: string; |
| 171 | 172 | /** github_issues:PR 在 GitHub 模型里也是工单,默认不收 */ |
| 172 | 173 | include_pull_requests?: boolean; |
| 174 | + /** jira_issues:站点地址,如 https://issues.apache.org/jira */ | |
| 175 | + base_url?: string; | |
| 176 | + /** jira_issues:项目 key,如 KAFKA */ | |
| 177 | + project?: string; | |
| 173 | 178 | } | null; |
| 174 | 179 | icon: string | null; |
| 175 | 180 | sync_interval_minutes: number | null; |
modified web/src/i18n/en.ts +7 −0
| @@ -371,12 +371,17 @@ | ||
| 371 | 371 | api: "API", |
| 372 | 372 | custom: "Custom", |
| 373 | 373 | github_issues: "GitHub issues", |
| 374 | + jira_issues: "Jira issues", | |
| 374 | 375 | }, |
| 375 | 376 | sourceKindHints: { |
| 376 | 377 | folder: |
| 377 | 378 | "A plain folder. Select it and upload (or drag) files straight into it — nothing is watched or synced.", |
| 378 | 379 | url: "Fetches the listed web pages; changed pages update the same document.", |
| 379 | 380 | rss: "Subscribes to a feed; each entry becomes a document dated by its publish time.", |
| 381 | + jira_issues: | |
| 382 | + "Syncs a Jira project's issues. **Each ticket, together with its field-level change " + | |
| 383 | + "history**, becomes one document — what changed from what to what, and when. " + | |
| 384 | + "One call fetches everything; no per-ticket round trips.", | |
| 380 | 385 | github_issues: |
| 381 | 386 | "Syncs a repository's issues. **Each ticket, together with its state history**, becomes " + |
| 382 | 387 | "one document — when it was opened, closed, relabelled, reassigned, all dated. " + |
| @@ -425,6 +430,8 @@ | ||
| 425 | 430 | urlsField: "Page URLs (one per line)", |
| 426 | 431 | feedUrl: "Feed URL", |
| 427 | 432 | repoField: "Repository (owner/name)", |
| 433 | + jiraUrlField: "Jira site URL", | |
| 434 | + jiraProjectField: "Project key", | |
| 428 | 435 | tokenField: "GitHub token (optional, never shown again)", |
| 429 | 436 | includePullRequests: "Treat pull requests as tickets too", |
| 430 | 437 | interval: "Sync schedule", |
modified web/src/i18n/zh.ts +6 −0
| @@ -344,12 +344,16 @@ | ||
| 344 | 344 | api: "API", |
| 345 | 345 | custom: "自定义", |
| 346 | 346 | github_issues: "GitHub 工单", |
| 347 | + jira_issues: "Jira 工单", | |
| 347 | 348 | }, |
| 348 | 349 | sourceKindHints: { |
| 349 | 350 | folder: |
| 350 | 351 | "一个普通文件夹。选中它,把文件直接上传(或拖)进去——不监听、不同步。", |
| 351 | 352 | url: "抓取所列的网页;内容变化时更新同一篇文档。", |
| 352 | 353 | rss: "订阅一个源;每条目成为一篇文档,日期取其发布时间。", |
| 354 | + jira_issues: | |
| 355 | + "同步一个 Jira 项目的工单。**每张工单连同它的字段级变更史**成为一篇文档——" + | |
| 356 | + "状态、负责人、优先级何时从什么变成什么,都带着日期。一次调用取全,不逐张翻。", | |
| 353 | 357 | github_issues: |
| 354 | 358 | "同步一个仓库的工单。**每张工单连同它的状态变更史**成为一篇文档——" + |
| 355 | 359 | "何时开出、何时关闭、标签与负责人怎么变的,都带着日期。未配令牌时" + |
| @@ -397,6 +401,8 @@ | ||
| 397 | 401 | urlsField: "网页地址(每行一个)", |
| 398 | 402 | feedUrl: "订阅地址", |
| 399 | 403 | repoField: "仓库(owner/name)", |
| 404 | + jiraUrlField: "Jira 地址", | |
| 405 | + jiraProjectField: "项目 key", | |
| 400 | 406 | tokenField: "GitHub 令牌(可选,不再显示)", |
| 401 | 407 | includePullRequests: "把 PR 也当工单收进来", |
| 402 | 408 | interval: "同步计划", |
modified web/src/pages/Library.tsx +64 −4
| @@ -1203,7 +1203,13 @@ | ||
| 1203 | 1203 | onDone: (id?: string, isApi?: boolean) => void; |
| 1204 | 1204 | }) { |
| 1205 | 1205 | const [kind, setKind] = useState< |
| 1206 | - "folder" | "url" | "rss" | "custom" | "api" | "github_issues" | |
| 1206 | + | "folder" | |
| 1207 | + | "url" | |
| 1208 | + | "rss" | |
| 1209 | + | "custom" | |
| 1210 | + | "api" | |
| 1211 | + | "github_issues" | |
| 1212 | + | "jira_issues" | |
| 1207 | 1213 | >("folder"); |
| 1208 | 1214 | const [name, setName] = useState(""); |
| 1209 | 1215 | const [icon, setIcon] = useState<string | null>(null); |
| @@ -1212,6 +1218,8 @@ | ||
| 1212 | 1218 | const [endpoint, setEndpoint] = useState(""); |
| 1213 | 1219 | const [authHeader, setAuthHeader] = useState(""); |
| 1214 | 1220 | const [repo, setRepo] = useState(""); |
| 1221 | + const [jiraUrl, setJiraUrl] = useState(""); | |
| 1222 | + const [jiraProject, setJiraProject] = useState(""); | |
| 1215 | 1223 | // PR 在 GitHub 的模型里也是工单。默认不收——问「工单」要的是工单; |
| 1216 | 1224 | // 但有些仓库的决策记录实际写在 PR 描述里,所以给个开关 |
| 1217 | 1225 | const [includePrs, setIncludePrs] = useState(false); |
| @@ -1221,7 +1229,11 @@ | ||
| 1221 | 1229 | }); |
| 1222 | 1230 | // folder = 纯容器、api = 推送型:都没有同步日程 |
| 1223 | 1231 | const syncing = |
| 1224 | - kind === "url" || kind === "rss" || kind === "custom" || kind === "github_issues"; | |
| 1232 | + kind === "url" || | |
| 1233 | + kind === "rss" || | |
| 1234 | + kind === "custom" || | |
| 1235 | + kind === "github_issues" || | |
| 1236 | + kind === "jira_issues"; | |
| 1225 | 1237 | |
| 1226 | 1238 | const create = useMutation({ |
| 1227 | 1239 | mutationFn: () => { |
| @@ -1241,7 +1253,13 @@ | ||
| 1241 | 1253 | ...(authHeader.trim() ? { auth_header: authHeader.trim() } : {}), |
| 1242 | 1254 | ...(includePrs ? { include_pull_requests: true } : {}), |
| 1243 | 1255 | } |
| 1244 | - : {}; | |
| 1256 | + : kind === "jira_issues" | |
| 1257 | + ? { | |
| 1258 | + base_url: jiraUrl.trim(), | |
| 1259 | + project: jiraProject.trim(), | |
| 1260 | + ...(authHeader.trim() ? { auth_header: authHeader.trim() } : {}), | |
| 1261 | + } | |
| 1262 | + : {}; | |
| 1245 | 1263 | return api.createSource(kbId, { |
| 1246 | 1264 | kind, |
| 1247 | 1265 | name: name.trim(), |
| @@ -1292,7 +1310,17 @@ | ||
| 1292 | 1310 | <div className="px-5 py-4"> |
| 1293 | 1311 | {/* 类型 */} |
| 1294 | 1312 | <div className="flex gap-2 mb-2"> |
| 1295 | - {(["folder", "url", "rss", "github_issues", "api", "custom"] as const).map((k) => { | |
| 1313 | + {( | |
| 1314 | + [ | |
| 1315 | + "folder", | |
| 1316 | + "url", | |
| 1317 | + "rss", | |
| 1318 | + "github_issues", | |
| 1319 | + "jira_issues", | |
| 1320 | + "api", | |
| 1321 | + "custom", | |
| 1322 | + ] as const | |
| 1323 | + ).map((k) => { | |
| 1296 | 1324 | const Icon = KIND_ICON[k]; |
| 1297 | 1325 | return ( |
| 1298 | 1326 | <button |
| @@ -1400,6 +1428,38 @@ | ||
| 1400 | 1428 | onChange={(e) => setFeedUrl(e.target.value)} |
| 1401 | 1429 | />, |
| 1402 | 1430 | )} |
| 1431 | + {kind === "jira_issues" && ( | |
| 1432 | + <> | |
| 1433 | + {field( | |
| 1434 | + S.library.jiraUrlField, | |
| 1435 | + <input | |
| 1436 | + className="input-dark w-full px-3 py-2 text-sm font-mono" | |
| 1437 | + placeholder="https://jira.example.com" | |
| 1438 | + value={jiraUrl} | |
| 1439 | + onChange={(e) => setJiraUrl(e.target.value)} | |
| 1440 | + />, | |
| 1441 | + )} | |
| 1442 | + {field( | |
| 1443 | + S.library.jiraProjectField, | |
| 1444 | + <input | |
| 1445 | + className="input-dark w-full px-3 py-2 text-sm font-mono" | |
| 1446 | + placeholder="KAFKA" | |
| 1447 | + value={jiraProject} | |
| 1448 | + onChange={(e) => setJiraProject(e.target.value)} | |
| 1449 | + />, | |
| 1450 | + )} | |
| 1451 | + {field( | |
| 1452 | + S.library.tokenField, | |
| 1453 | + <input | |
| 1454 | + className="input-dark w-full px-3 py-2 text-sm font-mono" | |
| 1455 | + type="password" | |
| 1456 | + placeholder="Basic dXNlcjp0b2tlbg==" | |
| 1457 | + value={authHeader} | |
| 1458 | + onChange={(e) => setAuthHeader(e.target.value)} | |
| 1459 | + />, | |
| 1460 | + )} | |
| 1461 | + </> | |
| 1462 | + )} | |
| 1403 | 1463 | {kind === "github_issues" && ( |
| 1404 | 1464 | <> |
| 1405 | 1465 | {field( |
modified web/src/pages/SourcesRail.tsx +9 −1
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | Rocket, |
| 24 | 24 | Rss, |
| 25 | 25 | Server, |
| 26 | + SquareKanban, | |
| 26 | 27 | Upload, |
| 27 | 28 | Users, |
| 28 | 29 | Webhook, |
| @@ -65,12 +66,19 @@ | ||
| 65 | 66 | api: Webhook, |
| 66 | 67 | custom: Puzzle, |
| 67 | 68 | github_issues: CircleDot, |
| 69 | + jira_issues: SquareKanban, | |
| 68 | 70 | memory: Brain, |
| 69 | 71 | upload: Upload, |
| 70 | 72 | } as const; |
| 71 | 73 | |
| 72 | 74 | /** 有拉取/同步语义的来源类型(folder/api 无同步概念) */ |
| 73 | -export const SYNCING_KINDS = new Set(["url", "rss", "custom", "github_issues"]); | |
| 75 | +export const SYNCING_KINDS = new Set([ | |
| 76 | + "url", | |
| 77 | + "rss", | |
| 78 | + "custom", | |
| 79 | + "github_issues", | |
| 80 | + "jira_issues", | |
| 81 | +]); | |
| 74 | 82 | |
| 75 | 83 | export const SYNC_DOT: Record<SourceView["last_sync_status"], string> = { |
| 76 | 84 | never: "bg-neutral-600", |