A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.
Swift ai-agentsanthropicantigravityclaudeclaude-codecodexcursordynamic-islandgemini-cliiosiphonlinuxmacosmacos-appmenubar-appnotchopen-sourceswiftswiftuiwindows
feat: add Gitea integration pulse
andrey3a7416f54a2c
diff --git a/windows/src-tauri/src/integrations.rs b/windows/src-tauri/src/integrations.rsindex 14969e48..e589b6f8 100644--- a/windows/src-tauri/src/integrations.rs+++ b/windows/src-tauri/src/integrations.rs@@ -17,7 +17,7 @@ use serde_json::{json, Value};use tauri::{AppHandle, Emitter, Manager};use tokio::sync::Notify;-use crate::github::{self, GitHubActivity, GitHubPulse};+use crate::github::{self, CiState, ContributionDay, GitHubActivity, GitHubPr, GitHubPulse, GitHubRepoCi, ReviewState};use crate::island::WINDOW_LABEL;use crate::log;use crate::secrets;@@ -70,6 +70,7 @@ pub fn start(app: AppHandle) {spawn(app.clone(), "integration_resend", 6, 60, poll_resend);spawn(app.clone(), "integration_github", 7, 300, poll_github);spawn_github_loops(app.clone());+ spawn(app.clone(), "integration_gitea", 7, 300, poll_gitea);spawn(app.clone(), "integration_calcom", 8, 300, poll_calcom);spawn(app, "integration_notion", 9, 300, poll_notion);}@@ -115,6 +116,7 @@ pub async fn poll_once(app: AppHandle, id: &str) {github_refresh_if_stale("activity");poll_github(app).await}+ "integration_gitea" => poll_gitea(app).await,"integration_vercel" => poll_vercel(app).await,"integration_n8n" => poll_n8n(app).await,"integration_resend" => poll_resend(app).await,@@ -124,6 +126,135 @@ pub async fn poll_once(app: AppHandle, id: &str) {}}+// ── Gitea ────────────────────────────────────────────────────────────────────+// Gitea deliberately has its own REST poller: self-hosted instances need an+// address, and unlike GitHub there is no GraphQL endpoint shared by all of them.+fn gitea_api_base() -> Option<String> {+ let url = secrets::get("gitea-url")?;+ let parsed = reqwest::Url::parse(url.trim()).ok()?;+ if !matches!(parsed.scheme(), "http" | "https") || parsed.host_str().is_none() {+ return None;+ }+ Some(format!("{}/api/v1", url.trim_end_matches('/')))+}++async fn poll_gitea(app: AppHandle) {+ let (Some(token), Some(base)) = (secrets::get("gitea-token"), gitea_api_base()) else { return };+ let http = client();+ let user = http.get(format!("{base}/user")).header("Authorization", format!("token {token}")).send().await;+ let Ok(response) = user else { return };+ if !response.status().is_success() {+ emit(&app, IntegrationUpdate { id: "integration_gitea", data: json!({}),+ error: Some(status_error(response.status().as_u16(), &crate::i18n::t("Token lacks the needed scope"))), event: None });+ return;+ }+ let user: Value = response.json().await.unwrap_or(json!({}));+ let repos_response = http.get(format!("{base}/user/repos?limit=100&sort=updated"))+ .header("Authorization", format!("token {token}")).send().await;+ let repos: Vec<Value> = match repos_response {+ Ok(r) if r.status().is_success() => r.json().await.unwrap_or_default(),+ _ => Vec::new(),+ };+ let stars: i64 = repos.iter().filter_map(|r| r.get("stars_count").and_then(Value::as_i64)).sum();+ let open_prs: i64 = repos.iter().filter_map(|r| r.get("open_pr_counter").and_then(Value::as_i64)).sum();+ let profile_url = user.get("html_url").and_then(Value::as_str).unwrap_or("");+ // Gitea's heatmap API is the equivalent of GitHub's contribution calendar.+ // Keep just the latest week for the compact card: the endpoint is optional+ // on older/self-hosted instances, so a missing one never hides the stats.+ let login = user.get("login").and_then(Value::as_str).unwrap_or("");+ let heatmap: Vec<Value> = if login.is_empty() {+ Vec::new()+ } else {+ match http.get(format!("{base}/users/{login}/heatmap"))+ .header("Authorization", format!("token {token}")).send().await {+ Ok(r) if r.status().is_success() => r.json().await.unwrap_or_default(),+ _ => Vec::new(),+ }+ };+ let activity = gitea_activity(&heatmap, now_ms());+ let my_raw = gitea_get(&http, &token, format!("{base}/repos/issues/search?state=open&type=pulls&created=true&limit=20")).await;+ let review_raw = gitea_get(&http, &token, format!("{base}/repos/issues/search?state=open&type=pulls&review_requested=true&limit=20")).await;+ let my_prs = gitea_prs(&my_raw);+ let to_review = gitea_prs(&review_raw);+ let main_ci = gitea_main_ci(&http, &token, &base, &repos).await;+ let pulse = GitHubPulse { login: login.to_string(), my_prs, to_review, main_ci, fetched_at: now_ms() };+ emit(&app, IntegrationUpdate { id: "integration_gitea", data: json!({+ "totalRepos": repos.len(), "totalStars": stars, "openPRs": open_prs,+ "profileUrl": profile_url, "pulse": pulse, "activity": activity,+ }), error: None, event: None });+}++async fn gitea_get(http: &reqwest::Client, token: &str, url: String) -> Vec<Value> {+ match http.get(url).header("Authorization", format!("token {token}")).send().await {+ Ok(r) if r.status().is_success() => r.json().await.unwrap_or_default(),+ _ => Vec::new(),+ }+}++fn gitea_prs(raw: &[Value]) -> Vec<GitHubPr> {+ raw.iter().filter_map(|pr| {+ let repo = pr.get("repository")?.get("full_name")?.as_str()?.to_string();+ let number = pr.get("number")?.as_i64()?;+ Some(GitHubPr { id: format!("{repo}#{number}"), title: pr.get("title").and_then(Value::as_str).unwrap_or("").to_string(),+ url: pr.get("html_url").and_then(Value::as_str).unwrap_or("").to_string(), repo, number,+ is_draft: pr.get("is_draft").and_then(Value::as_bool).unwrap_or(false), ci: CiState::Unknown,+ review: ReviewState::Unknown, head_sha: None })+ }).collect()+}++fn gitea_ci(state: Option<&str>) -> CiState {+ match state.map(str::to_ascii_lowercase).as_deref() {+ Some("success") => CiState::Success,+ Some("pending") => CiState::Pending,+ Some("failure") | Some("error") => CiState::Failure,+ _ => CiState::Unknown,+ }+}++async fn gitea_main_ci(http: &reqwest::Client, token: &str, base: &str, repos: &[Value]) -> Vec<GitHubRepoCi> {+ let mut out = Vec::new();+ for repo in repos.iter().take(20) {+ let Some(name) = repo.get("full_name").and_then(Value::as_str) else { continue };+ let branch = repo.get("default_branch").and_then(Value::as_str).unwrap_or("main");+ let statuses = gitea_get(http, token, format!("{base}/repos/{name}/commits/{branch}/statuses?limit=1&sort=recentupdate")).await;+ out.push(GitHubRepoCi { repo: name.to_string(), url: repo.get("html_url").and_then(Value::as_str).unwrap_or("").to_string(),+ branch: branch.to_string(), ci: gitea_ci(statuses.first().and_then(|s| s.get("state")).and_then(Value::as_str)), head_sha: None });+ }+ out+}++fn civil_day(day: i64) -> (i32, u32, u32, u8) {+ // Days since Unix epoch → Gregorian date and Sunday-based weekday.+ let z = day + 719_468; let era = if z >= 0 { z } else { z - 146_096 } / 146_097;+ let doe = z - era * 146_097; let yoe = (doe - doe / 1_460 + doe / 36_524 - doe / 146_096) / 365;+ let y = yoe + era * 400; let doy = doe - (365 * yoe + yoe / 4 - yoe / 100);+ let mp = (5 * doy + 2) / 153; let d = doy - (153 * mp + 2) / 5 + 1;+ let m = mp + if mp < 10 { 3 } else { -9 }; let year = y + if m <= 2 { 1 } else { 0 };+ (year as i32, m as u32, d as u32, ((day + 4).rem_euclid(7)) as u8)+}++fn gitea_activity(heatmap: &[Value], fetched_at: u64) -> GitHubActivity {+ let today = (fetched_at / 86_400_000) as i64;+ let mut weeks: Vec<Vec<ContributionDay>> = Vec::new();+ for chunk in (0..161).map(|offset| today - 160 + offset).collect::<Vec<_>>().chunks(7) {+ weeks.push(chunk.iter().map(|&day| {+ let count = heatmap.iter().find_map(|entry| { let ts = entry.get("timestamp")?.as_i64()?; let d = if ts > 10_000_000_000 { ts / 86_400_000 } else { ts / 86_400 }; (d == day).then(|| entry.get("contributions").and_then(Value::as_i64).unwrap_or(0)) }).unwrap_or(0);+ let (y, m, d, weekday) = civil_day(day); ContributionDay { date: format!("{y:04}-{m:02}-{d:02}"), count,+ level: if count == 0 { 0 } else if count == 1 { 1 } else if count < 4 { 2 } else if count < 8 { 3 } else { 4 }, weekday }+ }).collect());+ }+ let total = weeks.iter().flatten().map(|d| d.count).sum(); GitHubActivity { total, weeks, fetched_at }+}++/// A Gitea address or token changed: old totals belong to the previous account+/// and must not remain on the card while the new credentials are checked.+pub fn gitea_credentials_changed(app: &AppHandle) {+ emit(app, IntegrationUpdate { id: "integration_gitea", data: json!({}), error: None, event: None });+ if !PAUSED.load(Ordering::Relaxed) && enabled(app, "integration_gitea") {+ tauri::async_runtime::spawn(poll_gitea(app.clone()));+ }+}+/// Remembers the newest id per integration so an event fires once, not on every poll.struct Seen(Mutex<std::collections::HashMap<&'static str, String>>);diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rsindex e35793fa..6c4d3979 100644--- a/windows/src-tauri/src/lib.rs+++ b/windows/src-tauri/src/lib.rs@@ -205,6 +205,25 @@ fn open_url(url: String) {platform::open_url(&url);}+/// The configured Gitea address is a credential-store value, so the island+/// asks Rust to open it instead of ever receiving it.+#[tauri::command]+fn open_gitea() {+ if let Some(url) = secrets::get("gitea-url") {+ open_url(url);+ }+}++#[tauri::command]+fn open_gitea_url(url: String) {+ let (Ok(target), Some(base)) = (reqwest::Url::parse(&url), secrets::get("gitea-url")) else { return };+ let Ok(instance) = reqwest::Url::parse(&base) else { return };+ if matches!(target.scheme(), "http" | "https") && target.scheme() == instance.scheme()+ && target.host_str() == instance.host_str() && target.port_or_known_default() == instance.port_or_known_default() {+ open_url(url);+ }+}+/// "Open terminal" opens the working folder in VS Code when `code` is on PATH,/// and falls back to the file manager otherwise.#[tauri::command]@@ -521,6 +540,9 @@ fn secret_set(app: AppHandle, key: String, value: String) -> Result<(), String>integrations::github_token_changed(&app);}}+ if key == "gitea-token" || key == "gitea-url" {+ integrations::gitea_credentials_changed(&app);+ }Ok(())}@@ -531,6 +553,9 @@ fn secret_clear(app: AppHandle, key: String) -> Result<(), String> {if had {integrations::github_token_changed(&app);}+ if key == "gitea-token" || key == "gitea-url" {+ integrations::gitea_credentials_changed(&app);+ }Ok(())}@@ -689,6 +714,8 @@ pub fn run() {reposition,list_monitors,open_url,+ open_gitea,+ open_gitea_url,open_in_vscode,open_session,open_claude_desktop,diff --git a/windows/src-tauri/src/secrets.rs b/windows/src-tauri/src/secrets.rsindex e81ef527..78d76e39 100644--- a/windows/src-tauri/src/secrets.rs+++ b/windows/src-tauri/src/secrets.rs@@ -16,6 +16,8 @@ pub const KNOWN_KEYS: &[&str] = &["n8n-api-key","vercel-token","github-token",+ "gitea-url",+ "gitea-token","stripe-api-key","resend-api-key","notion-api-key",diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.tsindex 848daecf..c61c3757 100644--- a/windows/src/core/bridge.ts+++ b/windows/src/core/bridge.ts@@ -204,6 +204,10 @@ export const Bridge = {listMonitors: () => call<{ key: string; label: string }[]>("list_monitors"),openUrl: (url: string) => call<void>("open_url", { url }),+ /** Opens the configured Gitea instance without exposing its URL to the page. */+ openGitea: () => call<void>("open_gitea"),+ /** Opens a Gitea link only if it belongs to the configured instance. */+ openGiteaUrl: (url: string) => call<void>("open_gitea_url", { url }),/** Which of these sounds have a file of the user's own in the sounds folder. */customSounds: (names: readonly string[]) => call<string[]>("custom_sounds", { names }),diff --git a/windows/src/core/pills.ts b/windows/src/core/pills.tsindex 8242ad30..e2eb9b7c 100644--- a/windows/src/core/pills.ts+++ b/windows/src/core/pills.ts@@ -122,6 +122,8 @@ export const PILL_CATALOG: readonly PillDefinition[] = [subtitle: N_("Integration"), source: "n8n", support: "yes", connect: key("vercel-token") },{ id: "integration_github", name: "GitHub", color: "#F4505E", category: "service",subtitle: N_("Integration"), source: "n8n", support: "yes", connect: key("github-token") },+ { id: "integration_gitea", name: "Gitea", color: "#609926", category: "service",+ subtitle: N_("Integration"), source: "n8n", support: "yes", connect: key("gitea-token") },{ id: "integration_notion", name: "Notion", color: "#8C8C8C", category: "service",subtitle: N_("Integration"), source: "n8n", support: "yes", connect: key("notion-api-key") },{ id: "integration_calcom", name: "Cal.com", color: "#C9956A", category: "service",diff --git a/windows/src/island/island.ts b/windows/src/island/island.tsindex 2ef6fb90..52a3e61e 100644--- a/windows/src/island/island.ts+++ b/windows/src/island/island.ts@@ -191,6 +191,7 @@ export class Island {else if (task.id === "integration_claude" || task.sessionId) {void Bridge.openSession(task.sessionId ?? null, task.sessionCwd ?? null);} else if (task.id === "integration_n8n") void Bridge.openN8n();+ else if (task.id === "integration_gitea") void Bridge.openGitea();else if (task.id === SPOTIFY_ID) void Bridge.spotifyOpen();else if (urls[task.id]) void Bridge.openUrl(urls[task.id]);},diff --git a/windows/src/settings/main.ts b/windows/src/settings/main.tsindex 7d0dfe6c..268c270a 100644--- a/windows/src/settings/main.ts+++ b/windows/src/settings/main.ts@@ -763,6 +763,11 @@ const INTEGRATIONS: IntegrationDef[] = [{ id: "integration_github", name: "GitHub", color: "#F4505E",fields: [{ key: "github-token", label: N_("Token"), placeholder: "ghp_…", secret: true }],hint: N_("Classic token with the repo scope, or fine-grained with read access to Pull requests, Commit statuses and Actions.") },+ { id: "integration_gitea", name: "Gitea", color: "#609926",+ fields: [+ { key: "gitea-url", label: N_("Instance URL"), placeholder: "https://gitea.example.com", secret: false },+ { key: "gitea-token", label: N_("Token"), placeholder: "…", secret: true },+ ] },{ id: "integration_vercel", name: "Vercel", color: "#7C5CFF",fields: [{ key: "vercel-token", label: N_("Token"), placeholder: "…", secret: true }] },{ id: "integration_n8n", name: "n8n", color: "#F29B38",@@ -1328,7 +1333,7 @@ async function render() {const shortcutReport = await Bridge.shortcutsStatus();const keys = [- "stripe-api-key", "github-token", "vercel-token",+ "stripe-api-key", "github-token", "gitea-url", "gitea-token", "vercel-token","n8n-url", "n8n-api-key", "resend-api-key", "notion-api-key", "calcom-api-key",];const present: Record<string, boolean> = {};diff --git a/windows/src/views/github.ts b/windows/src/views/github.tsindex 86fba2f2..7835d638 100644--- a/windows/src/views/github.ts+++ b/windows/src/views/github.ts@@ -19,10 +19,14 @@ import {const GITHUB_RED = "#F4505E";+export interface ForgeCardOptions { title: string; color: string; gitea?: boolean }+let forge: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED };+/** Which list the detail view shows; kept across re-renders of the card. */let openSection: GitHubSection = "myPRs";function open(url: string) {+ if (forge.gitea) { void Bridge.openGiteaUrl(url); return; }const safe = safeGitHubUrl(url);if (safe) void Bridge.openUrl(safe);}@@ -53,14 +57,17 @@ export function githubPulseCard(stats: GitHubStats | null,activity: GitHubActivity | null,openDetail: () => void,+ options: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED },): HTMLElement {+ forge = options;const show = (section: GitHubSection) => {openSection = section;- void Bridge.githubRefresh(section === "activity" ? "activity" : "pulse");+ if (forge.gitea) void Bridge.refreshIntegration("integration_gitea");+ else void Bridge.githubRefresh(section === "activity" ? "activity" : "pulse");openDetail();};- const head = h("div", { class: "int-head" }, dot(GITHUB_RED, 7), h("b", { text: GH_STRINGS.title }));+ const head = h("div", { class: "int-head" }, dot(forge.color, 7), h("b", { text: forge.title }));if (stats || activity) {const spark = h("button", { class: "gh-spark", onclick: () => show("activity") });if (stats) spark.append(h("span", { text: `★ ${formatCount(stats.totalStars)}` }));@@ -130,7 +137,7 @@ function prRow(pr: GitHubPR, showCI: boolean): HTMLElement {function repoRow(repo: GitHubRepoCI): HTMLElement {const word = ciWord(repo.ci);return row(- () => open(actionsUrl(repo.url)),+ () => open(forge.gitea ? repo.url : actionsUrl(repo.url)),ciDot(repo.ci),h("span", { class: "gh-ref", text: shortRepo(repo.repo) }),h("span", { class: "gh-title", text: repo.branch }),@@ -190,7 +197,7 @@ function activityDetail(const right = h("button", {class: "gh-head-right",text: activityHeader(activity, stats, null),- onclick: () => open(profileUrl(login)),+ onclick: () => forge.gitea ? void Bridge.openGitea() : open(profileUrl(login)),});let picked: ContributionDay | null = null;@@ -230,7 +237,9 @@ export function githubDetail(stats: GitHubStats | null,activity: GitHubActivity | null,onBack: () => void,+ options: ForgeCardOptions = { title: "GitHub", color: GITHUB_RED },): HTMLElement {+ forge = options;return openSection === "activity"? activityDetail(activity, stats, pulse.login, onBack): listDetail(openSection, pulse, onBack);diff --git a/windows/src/views/integrations.ts b/windows/src/views/integrations.tsindex 2317d9c0..202d93a4 100644--- a/windows/src/views/integrations.ts+++ b/windows/src/views/integrations.ts@@ -11,7 +11,7 @@ import { Bridge } from "../core/bridge";import { isComingSoon, pillDefinition } from "../core/pills";import { refreshHookPills } from "../island/integrations";import { readActivity, readPulse, readStats } from "../core/github";-import { githubDetail, githubPulseCard } from "./github";+import { githubDetail, githubPulseCard, type ForgeCardOptions } from "./github";import { N_, language, t } from "../i18n/i18n";/** Same shape as the Swift `timeAgo` computed properties. */@@ -271,6 +271,13 @@ function githubCard(): HTMLElement {);}+function giteaCard(): HTMLElement {+ const d = get("integration_gitea");+ return h("div", { class: "int-card" }, header("#609926", "Gitea", t("Overview")),+ h("div", { class: "int-stats" }, statRow(ICONS.star, "#F5A524", t("Total stars"), String(d.totalStars ?? 0)),+ statRow(ICONS.stack, "#6B7079", t("Repositories"), String(d.totalRepos ?? 0))));+}+// ── Stripe ────────────────────────────────────────────────────────────────────function stripeCard(): HTMLElement {@@ -434,6 +441,8 @@ export function hasIntegrationData(id: string): boolean {return arr(id, "emails").length > 0;case "integration_github":return get(id).totalRepos != null || readPulse(get(id)) != null;+ case "integration_gitea":+ return get(id).totalRepos != null;case "integration_stripe":return info.loaded;case "integration_notion":@@ -467,12 +476,21 @@ export function renderIntegrationCard(task: AgentTask, hooks: IntegrationCardHoo: githubPulseCard(pulse, readStats(d), readActivity(d), hooks.openDetail);}}+ if (task.id === "integration_gitea") {+ const d = get(task.id); const pulse = readPulse(d);+ if (pulse) {+ const options: ForgeCardOptions = { title: "Gitea", color: "#609926", gitea: true };+ return hooks.detailOpen ? githubDetail(pulse, readStats(d), readActivity(d), hooks.closeDetail, options) : githubPulseCard(pulse, readStats(d), readActivity(d), hooks.openDetail, options);+ }+ }switch (task.id) {case "integration_resend":return resendCard();case "integration_github":return githubCard();+ case "integration_gitea":+ return giteaCard();case "integration_stripe":return stripeCard();case "integration_notion":diff --git a/windows/tests/pills.test.mjs b/windows/tests/pills.test.mjsindex 3186d801..236ebae2 100644--- a/windows/tests/pills.test.mjs+++ b/windows/tests/pills.test.mjs@@ -42,7 +42,8 @@ test("the catalog holds the Mac's pills, in the Mac's order, with the Mac's valu["integration_spotify", "Spotify", "#1DB954", "service", "Integration"],];assert.deepEqual(- PILL_CATALOG.map((p) => [p.id, p.name, p.color, p.category, p.subtitle]),+ PILL_CATALOG.filter((p) => p.id !== "integration_gitea")+ .map((p) => [p.id, p.name, p.color, p.category, p.subtitle]),mac,);assert.deepEqual(PILL_CATEGORIES.map((c) => c.title), [@@ -50,6 +51,14 @@ test("the catalog holds the Mac's pills, in the Mac's order, with the Mac's valu]);});+test("Gitea is an available service pill", () => {+ assert.deepEqual(+ pillDefinition("integration_gitea"),+ { id: "integration_gitea", name: "Gitea", color: "#609926", category: "service",+ subtitle: "Integration", source: "n8n", support: "yes", connect: { kind: "key", key: "gitea-token" } },+ );+});+test("the pills Windows always had keep their IDs, names, colours and sources", () => {const shipped = [["integration_claude", "VS Code", "#F5F6F8", "claudeCode"],