Federated via graft
0

Configure Feed

Select the types of activity you want to include in your feed.

1// Package status tracks the outcome of each repo pair's most recent sync 2// pass, keeps a small dashboard over the activity log, and serves both over 3// HTTP — so an operator can tell the daemon is alive and see what it's 4// actually done without reading logs. 5package status 6 7import ( 8 "encoding/json" 9 "html/template" 10 "net/http" 11 "net/url" 12 "sort" 13 "strings" 14 "sync" 15 "time" 16 17 "graft/internal/state" 18) 19 20// PairResult is the outcome of one repo pair's most recent pass. An empty 21// error string means that scope is either disabled or succeeded. 22type PairResult struct { 23 Name string `json:"name"` 24 Series string `json:"series"` 25 LastRun time.Time `json:"last_run"` 26 GitError string `json:"git_error,omitempty"` 27 IssuesError string `json:"issues_error,omitempty"` 28 PatchError string `json:"patch_error,omitempty"` 29} 30 31func (r PairResult) ok() bool { 32 return r.GitError == "" && r.IssuesError == "" && r.PatchError == "" 33} 34 35// ServerRef is one repo pair's declared mirror target — a specific Forgejo 36// instance or a specific Radicle node — as configured, regardless of 37// whether it has ever actually produced an event yet. 38type ServerRef struct { 39 Label string // host, e.g. "f1.cyberwild.org" 40 URL string // repo root on that host 41 Radicle bool // true if this side is a Radicle node 42 AuthorizedIntegration bool // true if this Forgejo side receives pushes directly from another pair's Forgejo, bypassing graft 43} 44 45// Tracker holds the latest result per repo pair, safe for concurrent use, 46// plus a handle on the state store for the activity dashboard. 47type Tracker struct { 48 startedAt time.Time 49 store *state.Store 50 sourceURL string 51 52 mu sync.Mutex 53 pairs map[string]PairResult 54 topology map[string][]ServerRef 55 publicHost string 56 blueskyConfigured map[string]bool 57} 58 59func NewTracker(store *state.Store, sourceURL string) *Tracker { 60 return &Tracker{startedAt: time.Now(), store: store, sourceURL: sourceURL, pairs: map[string]PairResult{}} 61} 62 63// SetTopology declares every mirror target configured for each series, so 64// the dashboard can show a side that's never produced an event yet (e.g. a 65// Radicle node nothing has been pushed to) instead of only sides the 66// activity log happens to mention. 67func (t *Tracker) SetTopology(topology map[string][]ServerRef) { 68 t.mu.Lock() 69 defer t.mu.Unlock() 70 t.topology = topology 71} 72 73// SetPublicHost declares the host graft is reachable at (e.g. 74// graft.cyberwild.org), enabling the "Social bridges" link and the 75// /social page. Call with "" (the default) to leave ActivityPub disabled. 76func (t *Tracker) SetPublicHost(host string) { 77 t.mu.Lock() 78 defer t.mu.Unlock() 79 t.publicHost = host 80} 81 82// SetBlueskyConfigured declares which series have a Bluesky account 83// configured, for the /social page's status badge. 84func (t *Tracker) SetBlueskyConfigured(configured map[string]bool) { 85 t.mu.Lock() 86 defer t.mu.Unlock() 87 t.blueskyConfigured = configured 88} 89 90// Record stores the outcome of a pass for one pair. Pass nil for a scope 91// that succeeded or wasn't enabled. series is the dashboard row this pair's 92// status badge groups under (see config.RepoPair.Series). 93func (t *Tracker) Record(name, series string, gitErr, issuesErr, patchErr error) { 94 r := PairResult{Name: name, Series: series, LastRun: time.Now()} 95 if gitErr != nil { 96 r.GitError = gitErr.Error() 97 } 98 if issuesErr != nil { 99 r.IssuesError = issuesErr.Error() 100 } 101 if patchErr != nil { 102 r.PatchError = patchErr.Error() 103 } 104 t.mu.Lock() 105 defer t.mu.Unlock() 106 t.pairs[name] = r 107} 108 109func (t *Tracker) snapshot() []PairResult { 110 t.mu.Lock() 111 defer t.mu.Unlock() 112 out := make([]PairResult, 0, len(t.pairs)) 113 for _, r := range t.pairs { 114 out = append(out, r) 115 } 116 sort.Slice(out, func(i, j int) bool { return out[i].Name < out[j].Name }) 117 return out 118} 119 120type statusResponse struct { 121 StartedAt time.Time `json:"started_at"` 122 Pairs []PairResult `json:"pairs"` 123} 124 125// Handler serves: 126// 127// GET /healthz - 200 if every pair's last pass was clean, 503 otherwise 128// GET /api/status - the JSON snapshot Record() has been fed 129// GET / - the activity dashboard (calendar + recent commits) 130func (t *Tracker) Handler() http.Handler { 131 mux := http.NewServeMux() 132 133 mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { 134 for _, p := range t.snapshot() { 135 if !p.ok() { 136 w.WriteHeader(http.StatusServiceUnavailable) 137 return 138 } 139 } 140 w.WriteHeader(http.StatusOK) 141 }) 142 143 mux.HandleFunc("/api/status", func(w http.ResponseWriter, r *http.Request) { 144 resp := statusResponse{StartedAt: t.startedAt, Pairs: t.snapshot()} 145 w.Header().Set("Content-Type", "application/json") 146 json.NewEncoder(w).Encode(resp) 147 }) 148 149 mux.HandleFunc("/", t.serveDashboard) 150 mux.HandleFunc("/social", t.serveSocial) 151 152 return mux 153} 154 155const dashboardDays = 3 156 157func (t *Tracker) serveDashboard(w http.ResponseWriter, r *http.Request) { 158 since := time.Now().UTC().AddDate(0, 0, -(dashboardDays - 1)).Truncate(24 * time.Hour) 159 entries, err := t.store.ActivitySince(since) 160 if err != nil { 161 http.Error(w, "load activity: "+err.Error(), http.StatusInternalServerError) 162 return 163 } 164 165 pairs := groupPairStatus(t.snapshot()) 166 health := make(map[string]bool, len(pairs)) 167 for _, p := range pairs { 168 health[p.Name] = p.OK 169 } 170 171 t.mu.Lock() 172 topology := t.topology 173 publicHost := t.publicHost 174 t.mu.Unlock() 175 176 data := dashboardData{ 177 Series: buildSeriesRows(entries, health, topology), 178 Activity: recentActivity(entries), 179 SourceURL: t.sourceURL, 180 SocialEnabled: publicHost != "", 181 } 182 w.Header().Set("Content-Type", "text/html; charset=utf-8") 183 w.Header().Set("Cache-Control", "no-store") 184 if err := dashboardTmpl.Execute(w, data); err != nil { 185 http.Error(w, err.Error(), http.StatusInternalServerError) 186 } 187} 188 189// socialData is what the /social page renders: one row per series 190// describing its ActivityPub and AT Proto/Bluesky bridges. Built 191// incrementally across the v2 milestones — see the plan for what each 192// stage adds (follower counts, delivery timestamps, bridged-comment 193// counts, Bluesky status). 194type socialData struct { 195 PublicHost string 196 Series []socialRow 197 SourceURL string 198} 199 200type socialRow struct { 201 Name string 202 Handle string // "series@host" 203 WebfingerURL string 204 ActorURL string 205 OutboxURL string 206 FollowerCount int 207 BlueskyConfigured bool 208} 209 210func (t *Tracker) serveSocial(w http.ResponseWriter, r *http.Request) { 211 t.mu.Lock() 212 topology := t.topology 213 publicHost := t.publicHost 214 blueskyConfigured := t.blueskyConfigured 215 t.mu.Unlock() 216 217 if publicHost == "" { 218 http.NotFound(w, r) 219 return 220 } 221 222 names := make([]string, 0, len(topology)) 223 for name := range topology { 224 names = append(names, name) 225 } 226 sort.Strings(names) 227 228 rows := make([]socialRow, 0, len(names)) 229 for _, name := range names { 230 actorURL := "https://" + publicHost + "/actors/" + name 231 followerCount, err := t.store.FollowerCount(name) 232 if err != nil { 233 followerCount = 0 234 } 235 rows = append(rows, socialRow{ 236 Name: name, 237 Handle: name + "@" + publicHost, 238 WebfingerURL: "https://" + publicHost + "/.well-known/webfinger?resource=acct:" + name + "@" + publicHost, 239 ActorURL: actorURL, 240 OutboxURL: actorURL + "/outbox", 241 FollowerCount: followerCount, 242 BlueskyConfigured: blueskyConfigured[name], 243 }) 244 } 245 246 data := socialData{PublicHost: publicHost, Series: rows, SourceURL: t.sourceURL} 247 w.Header().Set("Content-Type", "text/html; charset=utf-8") 248 w.Header().Set("Cache-Control", "no-store") 249 if err := socialTmpl.Execute(w, data); err != nil { 250 http.Error(w, err.Error(), http.StatusInternalServerError) 251 } 252} 253 254type dashboardData struct { 255 Series []seriesRow 256 Activity []commitLine 257 SourceURL string 258 SocialEnabled bool 259} 260 261// pairStatus is one badge in the dashboard's top status card: one per 262// series (repo), OK only if every pair mirroring that repo's last pass was 263// clean — grouped so a repo with 3 mirrored sides (e.g. two Forgejos plus 264// an external instance) shows one badge, not three. 265type pairStatus struct { 266 Name string 267 OK bool 268} 269 270func groupPairStatus(results []PairResult) []pairStatus { 271 order := []string{} 272 ok := map[string]bool{} 273 for _, r := range results { 274 name := r.Series 275 if name == "" { 276 name = r.Name 277 } 278 if _, seen := ok[name]; !seen { 279 order = append(order, name) 280 ok[name] = true 281 } 282 if !r.ok() { 283 ok[name] = false 284 } 285 } 286 sort.Strings(order) 287 out := make([]pairStatus, 0, len(order)) 288 for _, name := range order { 289 out = append(out, pairStatus{Name: name, OK: ok[name]}) 290 } 291 return out 292} 293 294// seriesRow is one full-width strip of the activity heatmap: everything 295// mirrored for one underlying repository (grouped across its Forgejo and 296// Radicle sides via config.RepoPair.Series), one cell per actual event — 297// not one per day — so nothing is ever aggregated behind a single tooltip. 298type seriesRow struct { 299 Name string 300 OK bool 301 SubRows []subRow 302} 303 304// subRow is one mirrored side of a series — one real repo (a specific 305// Forgejo instance, or a specific Radicle node) — shown once the series is 306// expanded, with only that side's own events and its own link. A series 307// with 3 mirrored sides (two Forgejos plus Radicle) gets 3 sub-rows, never 308// one link picked arbitrarily to represent all of them. 309type subRow struct { 310 Label string 311 URL string 312 // EmptyState explains why this side shows no events even though it may 313 // already hold the mirrored content — empty when Events is non-empty, 314 // or when the whole series has genuinely never been touched. "source" 315 // marks the Forgejo side changes originate on (graft only logs the 316 // pushes it makes, never the pushes it reads from); "replicated" marks 317 // a side that received the content some other way graft doesn't log 318 // itself — Radicle's own peer-to-peer gossip between nodes, or a 319 // Forgejo-to-Forgejo Authorized Integration. 320 EmptyState string 321 Events []event 322} 323 324// event is one activity_log row: one heatmap cell, one tooltip, one link. 325type event struct { 326 Kind string // "git", "issue", "patch" — drives the cell's color 327 Label string // "Commit", "Issue", "Patch" 328 Text string 329 URL string 330 Server string // which mirrored side this happened on, e.g. "f1", "alice" 331 When string // human-readable timestamp, for the tooltip 332} 333 334type commitLine struct { 335 When string 336 Pair string 337 PairURL string 338 Server string 339 Kind string // "Commit", "Issue", "Patch" 340 Message string 341 URL string 342} 343 344// serverLabel names which side of a series a repo_pair belongs to, e.g. 345// "federation-x-f1" under series "federation-x" becomes "f1". Several pairs 346// share one series row/badge, so without this an operator can't tell which 347// mirrored server (f1, f2, an external instance...) a given event actually 348// happened on. Empty if the pair name doesn't start with its series name. 349func serverLabel(repoPair, series string) string { 350 if series == "" { 351 return "" 352 } 353 suffix := strings.TrimPrefix(repoPair, series+"-") 354 if suffix == repoPair { 355 return "" 356 } 357 return suffix 358} 359 360// hostLabel shortens a URL's host to its canonical name for compact 361// display: the TLD is dropped ("f1.cyberwild.org" -> "f1.cyberwild", 362// "artefacts.bimr.net" -> "artefacts.bimr"), so every server — ours or an 363// external instance's — reads the same way, never a per-pair alias. 364func hostLabel(rawURL string) string { 365 u, err := url.Parse(rawURL) 366 if err != nil || u.Host == "" { 367 return "" 368 } 369 host := u.Host 370 // A Radicle Explorer URL's host is always the shared frontend 371 // (e.g. radicle.cyberwild.org) — the actual node lives in the path, 372 // /nodes/<node-host>/<rid>/... — so different Radicle nodes get 373 // distinct labels instead of collapsing into one shared one. 374 if segs := strings.Split(strings.TrimPrefix(u.Path, "/"), "/"); len(segs) >= 2 && segs[0] == "nodes" { 375 host = segs[1] 376 } 377 return host 378} 379 380// buildSeriesRows groups entries by their Series (one row per monitored 381// repo, spanning both its Forgejo and Radicle sides) — Atlassian 382// Statuspage style: one full-width horizontal strip per series. Each entry 383// becomes its own cell, oldest first, so a busy day never hides events 384// behind one shared tooltip. 385func buildSeriesRows(entries []state.ActivityEntry, health map[string]bool, topology map[string][]ServerRef) []seriesRow { 386 type subAcc struct { 387 url string 388 events []state.ActivityEntry 389 radicle bool 390 ai bool 391 } 392 type seriesAcc struct { 393 subOrder []string 394 subs map[string]*subAcc 395 } 396 seriesAccs := map[string]*seriesAcc{} 397 var seriesOrder []string 398 399 ensureSeries := func(name string) *seriesAcc { 400 sa, ok := seriesAccs[name] 401 if !ok { 402 sa = &seriesAcc{subs: map[string]*subAcc{}} 403 seriesAccs[name] = sa 404 seriesOrder = append(seriesOrder, name) 405 } 406 return sa 407 } 408 ensureSub := func(sa *seriesAcc, label string) *subAcc { 409 sub, ok := sa.subs[label] 410 if !ok { 411 sub = &subAcc{} 412 sa.subs[label] = sub 413 sa.subOrder = append(sa.subOrder, label) 414 } 415 return sub 416 } 417 418 // Seed every configured mirror target first, so a side that has never 419 // produced an event (e.g. a Radicle node nothing has been pushed to 420 // yet) still gets its own row instead of being invisible. 421 for name, refs := range topology { 422 sa := ensureSeries(name) 423 for _, ref := range refs { 424 sub := ensureSub(sa, ref.Label) 425 if sub.url == "" { 426 sub.url = ref.URL 427 } 428 sub.radicle = ref.Radicle 429 sub.ai = ref.AuthorizedIntegration 430 } 431 } 432 433 for _, e := range entries { 434 name := e.Series 435 if name == "" { 436 name = e.RepoPair 437 } 438 sa := ensureSeries(name) 439 server := hostLabel(e.URL) 440 if server == "" { 441 server = serverLabel(e.RepoPair, e.Series) 442 } 443 if server == "" { 444 server = e.RepoPair 445 } 446 sub := ensureSub(sa, server) 447 if sub.url == "" { 448 sub.url = repoRootURL(e.URL) 449 } 450 sub.events = append(sub.events, e) 451 } 452 sort.Strings(seriesOrder) 453 454 rows := make([]seriesRow, 0, len(seriesOrder)) 455 for _, name := range seriesOrder { 456 sa := seriesAccs[name] 457 subOrder := append([]string(nil), sa.subOrder...) 458 sort.Strings(subOrder) 459 460 // A series with at least one logged event anywhere means every 461 // currently-silent side already holds the mirrored content too — 462 // either as the origin, or received via a path graft doesn't log 463 // itself (Radicle gossip, an Authorized Integration). Only a 464 // series with zero events anywhere is genuinely untouched. 465 anyEvents := false 466 for _, label := range subOrder { 467 if len(sa.subs[label].events) > 0 { 468 anyEvents = true 469 break 470 } 471 } 472 473 subRows := make([]subRow, 0, len(subOrder)) 474 for _, label := range subOrder { 475 sub := sa.subs[label] 476 // entries arrive newest-first (see ActivitySince); the 477 // heatmap reads left-to-right as oldest-to-newest. 478 es := make([]state.ActivityEntry, len(sub.events)) 479 copy(es, sub.events) 480 sort.Slice(es, func(i, j int) bool { return es[i].OccurredAt.Before(es[j].OccurredAt) }) 481 482 emptyState := "" 483 if len(es) == 0 && anyEvents { 484 switch { 485 case sub.ai, sub.radicle: 486 emptyState = "replicated" 487 default: 488 emptyState = "source" 489 } 490 } 491 subRows = append(subRows, subRow{Label: label, URL: sub.url, EmptyState: emptyState, Events: toEvents(es)}) 492 } 493 494 ok, known := health[name] 495 if !known { 496 ok = true 497 } 498 rows = append(rows, seriesRow{Name: name, OK: ok, SubRows: subRows}) 499 } 500 return rows 501} 502 503func toEvents(es []state.ActivityEntry) []event { 504 out := make([]event, 0, len(es)) 505 for _, e := range es { 506 server := hostLabel(e.URL) 507 if server == "" { 508 server = serverLabel(e.RepoPair, e.Series) 509 } 510 out = append(out, event{ 511 Kind: e.Kind, 512 Label: kindLabel(e.Kind), 513 Text: e.Summary, 514 URL: e.URL, 515 Server: server, 516 When: e.OccurredAt.Format("Mon, Jan 2, 15:04"), 517 }) 518 } 519 return out 520} 521 522func kindLabel(kind string) string { 523 switch kind { 524 case "git": 525 return "Commit" 526 case "issue": 527 return "Issue" 528 case "patch": 529 return "Patch" 530 default: 531 return kind 532 } 533} 534 535// recentActivity lists every mirrored event — commits, issues, and 536// patches/pull requests alike, newest first. graft doesn't mirror stars or 537// other social metadata: its sync scope is git content, issues, and 538// patches/PRs only (see config.SyncScope), so that's what shows up here. 539func recentActivity(entries []state.ActivityEntry) []commitLine { 540 out := make([]commitLine, 0, len(entries)) 541 for _, e := range entries { 542 name := e.Series 543 if name == "" { 544 name = e.RepoPair 545 } 546 server := hostLabel(e.URL) 547 if server == "" { 548 server = serverLabel(e.RepoPair, e.Series) 549 } 550 // The (server) parenthetical should point at that specific 551 // server's own repo, not the series' shared Radicle explorer 552 // link (which is fixed to whichever pair logged first). 553 pairURL := repoRootURL(e.URL) 554 if pairURL == "" { 555 pairURL = e.SeriesURL 556 } 557 out = append(out, commitLine{ 558 When: e.OccurredAt.Format("Jan 2, 15:04"), 559 Pair: name, 560 PairURL: pairURL, 561 Server: server, 562 Kind: kindLabel(e.Kind), 563 Message: e.Summary, 564 URL: e.URL, 565 }) 566 } 567 return out 568} 569 570// repoRootURL trims an event's specific-item URL (a commit, issue, or 571// patch/PR page) back down to its repository root, e.g. 572// ".../owner/repo/commit/<sha>" -> ".../owner/repo". Empty if rawURL is 573// empty or doesn't contain a recognized item path. 574func repoRootURL(rawURL string) string { 575 // Forgejo uses singular "/commit/"; Radicle Explorer uses plural 576 // "/commits/" — both must be recognized, or every Radicle-hosted 577 // commit link falls back to a non-clickable label. 578 for _, marker := range []string{"/commit/", "/commits/", "/issues/", "/pulls/", "/patches/"} { 579 if idx := strings.Index(rawURL, marker); idx >= 0 { 580 return rawURL[:idx] 581 } 582 } 583 return "" 584} 585 586var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!doctype html> 587<html lang="en"> 588<head> 589<meta charset="utf-8"> 590<meta name="viewport" content="width=device-width, initial-scale=1"> 591<title>graft</title> 592<style> 593 :root { 594 color-scheme: light; 595 --surface: #ffffff; 596 --surface-sunk: #f4f5f7; 597 --text: #172b4d; 598 --text-muted: #6b778c; 599 --border: #dfe1e6; 600 --brand: #0052cc; 601 --brand-dark: #0747a6; 602 --kind-git: #0052cc; 603 --kind-issue: #00875a; 604 --kind-patch: #6554c0; 605 --kind-source: #ff991f; 606 --kind-replicated: #00b8d9; 607 --bad: #de350b; 608 --good: #36b37e; 609 } 610 * { box-sizing: border-box; } 611 body { 612 margin: 0; 613 background: var(--surface-sunk); 614 color: var(--text); 615 font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 616 } 617 main { max-width: 920px; margin: 0 auto; padding: 2.5rem 1.5rem 1rem; } 618 619 .top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.5rem; } 620 .top > div { display: flex; align-items: baseline; gap: .6rem; } 621 h1 { font-size: 1.25rem; margin: 0; font-weight: 600; } 622 .sub { color: var(--text-muted); font-size: .85rem; } 623 .nav-link { color: var(--brand); font-size: .82rem; text-decoration: none; font-weight: 500; } 624 .nav-link:hover { text-decoration: underline; } 625 626 .card { 627 background: var(--surface); 628 border: 1px solid var(--border); 629 border-radius: 4px; 630 padding: 1.25rem 1.5rem; 631 margin-bottom: 1.25rem; 632 } 633 634 .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; display: inline-block; } 635 .dot.bad { background: var(--bad); } 636 637 .heatmap-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .9rem; } 638 .heatmap-head h2 { margin: 0; } 639 .legend { display: flex; gap: .9rem; margin-bottom: .9rem; } 640 .legend span { display: flex; align-items: center; gap: .35rem; font-size: .74rem; color: var(--text-muted); } 641 .legend .sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; } 642 .legend .sw[data-kind="git"] { background: var(--kind-git); } 643 .legend .sw[data-kind="issue"] { background: var(--kind-issue); } 644 .legend .sw[data-kind="patch"] { background: var(--kind-patch); } 645 .legend .sw[data-kind="source"] { background: var(--kind-source); } 646 .legend .sw[data-kind="replicated"] { background: var(--kind-replicated); } 647 .heatmap { display: flex; flex-direction: column; gap: .15rem; } 648 .series-group { border-bottom: 1px solid var(--border); } 649 .series-group:last-child { border-bottom: none; } 650 .series-group[open] { padding-bottom: .5rem; } 651 .series-label { 652 display: flex; align-items: center; gap: .45rem; padding: .55rem 0; 653 cursor: pointer; list-style: none; 654 } 655 .series-label::-webkit-details-marker { display: none; } 656 .series-label::before { 657 content: ""; width: 0; height: 0; flex: none; 658 border-style: solid; border-width: 4px 0 4px 5px; 659 border-color: transparent transparent transparent var(--text-muted); 660 transition: transform .12s ease; 661 } 662 .series-group[open] > .series-label::before { transform: rotate(90deg); } 663 .series-name { font-size: .82rem; font-weight: 600; color: var(--text); } 664 .series-count { font-size: .74rem; color: var(--text-muted); } 665 .subrows { display: flex; flex-direction: column; gap: .5rem; padding-left: 1.3rem; } 666 .subrow { display: flex; align-items: center; gap: .75rem; } 667 .subrow-name { 668 flex: 0 0 11rem; font-size: .78rem; color: var(--text-muted); text-decoration: none; 669 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 670 } 671 a.subrow-name { color: var(--brand); } 672 a.subrow-name:hover { text-decoration: underline; } 673 .days { display: flex; gap: 3px; flex-wrap: wrap; } 674 .cell { 675 flex: none; width: 10px; height: 22px; border-radius: 3px; 676 background: var(--border); position: relative; cursor: default; 677 } 678 .cell[data-kind="git"] { background: var(--kind-git); } 679 .cell[data-kind="issue"] { background: var(--kind-issue); } 680 .cell[data-kind="patch"] { background: var(--kind-patch); } 681 682 .tip { 683 display: none; position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); 684 background: var(--text); color: #fff; border-radius: 6px; 685 font-size: .78rem; z-index: 20; padding: .5rem 0; 686 box-shadow: 0 4px 12px rgba(9,30,66,.25); 687 width: max-content; max-width: min(320px, 90vw); 688 } 689 .cell:nth-child(-n+2) .tip { left: 0; transform: none; } 690 .cell:nth-last-child(-n+2) .tip { left: auto; right: 0; transform: none; } 691 .cell:hover .tip, .tip:hover { display: block; } 692 .tip .tip-date { padding: 0 .75rem .35rem; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: .35rem; } 693 .tip a.tip-row { 694 display: flex; gap: .4em; padding: .3rem .75rem; color: #fff; text-decoration: none; 695 white-space: normal; overflow-wrap: anywhere; line-height: 1.35; 696 } 697 .tip a.tip-row:hover { background: rgba(255,255,255,.12); } 698 .tip .tip-kind { color: #b3bac5; flex: none; } 699 .tip .tip-empty { padding: 0 .75rem; color: #b3bac5; } 700 701 .state-pill { 702 display: inline-flex; align-items: center; gap: .35rem; 703 font-size: .74rem; padding: .2rem .6rem; border-radius: 999px; 704 } 705 .state-pill .state-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; } 706 .state-pill.state-source { background: rgba(255,153,31,.14); color: #974f0c; } 707 .state-pill.state-source .state-dot { background: var(--kind-source); } 708 .state-pill.state-replicated { background: rgba(0,184,217,.14); color: #0868a0; } 709 .state-pill.state-replicated .state-dot { background: var(--kind-replicated); } 710 711 h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 .9rem; font-weight: 600; } 712 .commits { border-top: 1px solid var(--border); } 713 .commit { 714 display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); 715 font-size: .82rem; 716 } 717 .commit .when { color: var(--text-muted); flex: none; width: 9em; } 718 .commit .kind { color: var(--text-muted); flex: none; width: 4.5em; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; } 719 .commit .pair { 720 color: var(--text-muted); flex: 0 1 auto; max-width: 22em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 721 text-decoration: none; 722 } 723 .commit a.pair { color: var(--brand); } 724 .commit a.pair:hover { text-decoration: underline; } 725 .commit .msg { 726 flex: 1 1 auto; min-width: 0; 727 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace; 728 color: inherit; text-decoration: none; 729 } 730 .commit a.msg { color: var(--brand); } 731 .commit a.msg:hover { text-decoration: underline; } 732 .empty { color: var(--text-muted); padding: .5rem 0; } 733 734 footer { 735 max-width: 920px; margin: 0 auto; padding: 1rem 1.5rem 2.5rem; 736 color: var(--text-muted); font-size: .78rem; display: flex; gap: 1rem; 737 } 738 footer a { color: var(--text-muted); } 739</style> 740</head> 741<body> 742<main> 743 <div class="top"> 744 <div> 745 <h1>graft</h1> 746 <span class="sub">Forgejos &amp; Radicles syncs</span> 747 </div> 748 {{if .SocialEnabled}}<a class="nav-link" href="/social">Social IDs &rarr;</a>{{end}} 749 </div> 750 751 <div class="card"> 752 <div class="heatmap-head"> 753 <div class="legend"> 754 <span><i class="sw" data-kind="git"></i>Commit</span> 755 <span><i class="sw" data-kind="issue"></i>Issue</span> 756 <span><i class="sw" data-kind="patch"></i>Patch</span> 757 <span><i class="sw" data-kind="source"></i>Source</span> 758 <span><i class="sw" data-kind="replicated"></i>Replicated</span> 759 </div> 760 </div> 761 <div class="heatmap"> 762 {{range .Series}} 763 <details class="series-group"> 764 <summary class="series-label"> 765 <span class="dot{{if not .OK}} bad{{end}}"></span> 766 <span class="series-name">{{.Name}}</span> 767 <span class="series-count">{{len .SubRows}} mirror{{if ne (len .SubRows) 1}}s{{end}}</span> 768 </summary> 769 <div class="subrows"> 770 {{range .SubRows}} 771 <div class="subrow"> 772 {{if .URL}} 773 <a class="subrow-name" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a> 774 {{else}} 775 <span class="subrow-name">{{.Label}}</span> 776 {{end}} 777 <div class="days"> 778 {{range .Events}} 779 <div class="cell" data-kind="{{.Kind}}"> 780 <div class="tip"> 781 <div class="tip-date">{{.When}}</div> 782 {{if .URL}} 783 <a class="tip-row" href="{{.URL}}" target="_blank" rel="noopener"><span class="tip-kind">{{.Label}}</span>{{.Text}}</a> 784 {{else}} 785 <span class="tip-row"><span class="tip-kind">{{.Label}}</span>{{.Text}}</span> 786 {{end}} 787 </div> 788 </div> 789 {{else}} 790 {{if eq .EmptyState "source"}} 791 <span class="state-pill state-source" title="content originates here — graft only logs the pushes it makes, not the pushes it reads from"><span class="state-dot"></span>source</span> 792 {{else if eq .EmptyState "replicated"}} 793 <span class="state-pill state-replicated" title="content arrived here without a graft-logged push — Radicle peer-to-peer gossip, or a Forgejo Authorized Integration"><span class="state-dot"></span>replicated</span> 794 {{else}} 795 <span class="tip-empty">nothing synced</span> 796 {{end}} 797 {{end}} 798 </div> 799 </div> 800 {{end}} 801 </div> 802 </details> 803 {{else}} 804 <span class="empty">nothing synced yet</span> 805 {{end}} 806 </div> 807 </div> 808 809 <div class="card"> 810 <div class="heatmap-head"> 811 <h2>Recent activity</h2> 812 <span class="sub">last 3 days</span> 813 </div> 814 <div class="commits"> 815 {{range .Activity}} 816 <div class="commit"> 817 <span class="when">{{.When}}</span> 818 <span class="kind">{{.Kind}}</span> 819 {{if .PairURL}} 820 <a class="pair" href="{{.PairURL}}" target="_blank" rel="noopener">{{.Pair}}{{if .Server}} ({{.Server}}){{end}}</a> 821 {{else}} 822 <span class="pair">{{.Pair}}{{if .Server}} ({{.Server}}){{end}}</span> 823 {{end}} 824 {{if .URL}} 825 <a class="msg" href="{{.URL}}" target="_blank" rel="noopener">{{.Message}}</a> 826 {{else}} 827 <span class="msg">{{.Message}}</span> 828 {{end}} 829 </div> 830 {{else}} 831 <p class="empty">nothing mirrored yet</p> 832 {{end}} 833 </div> 834 </div> 835</main> 836<footer> 837 {{if .SourceURL}}<a href="{{.SourceURL}}" target="_blank" rel="noopener">{{.SourceURL}}</a>{{end}} 838 <span>GPLv3</span> 839</footer> 840</body> 841</html> 842`)) 843 844var socialTmpl = template.Must(template.New("social").Parse(`<!doctype html> 845<html lang="en"> 846<head> 847<meta charset="utf-8"> 848<meta name="viewport" content="width=device-width, initial-scale=1"> 849<title>graft — social IDs</title> 850<style> 851 :root { 852 color-scheme: light; 853 --surface: #ffffff; 854 --surface-sunk: #f4f5f7; 855 --text: #172b4d; 856 --text-muted: #6b778c; 857 --border: #dfe1e6; 858 --brand: #0052cc; 859 } 860 * { box-sizing: border-box; } 861 body { 862 margin: 0; background: var(--surface-sunk); color: var(--text); 863 font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 864 } 865 main { max-width: 760px; margin: 0 auto; padding: 2.5rem 1.5rem 1rem; } 866 .top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.5rem; } 867 .top > div { display: flex; align-items: baseline; gap: .6rem; } 868 h1 { font-size: 1.25rem; margin: 0; font-weight: 600; } 869 .sub { color: var(--text-muted); font-size: .85rem; } 870 .nav-link { color: var(--brand); font-size: .82rem; text-decoration: none; font-weight: 500; } 871 .nav-link:hover { text-decoration: underline; } 872 .card { 873 background: var(--surface); border: 1px solid var(--border); border-radius: 4px; 874 padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; 875 } 876 .series-block { padding: .75rem 0; border-bottom: 1px solid var(--border); } 877 .series-block:last-child { border-bottom: none; } 878 .handle { font-size: .95rem; font-weight: 600; color: var(--text); } 879 h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: .6rem 0 .4rem; font-weight: 600; } 880 .endpoints { display: flex; flex-direction: column; gap: .3rem; } 881 .endpoints a { font-size: .8rem; color: var(--brand); text-decoration: none; font-family: ui-monospace, monospace; } 882 .endpoints a:hover { text-decoration: underline; } 883 .badge { 884 display: inline-block; font-size: .72rem; color: var(--text-muted); background: var(--surface-sunk); 885 border: 1px solid var(--border); border-radius: 3px; padding: .15rem .5rem; margin-top: .4rem; 886 } 887 .empty { color: var(--text-muted); padding: .5rem 0; } 888 footer { 889 max-width: 760px; margin: 0 auto; padding: 1rem 1.5rem 2.5rem; 890 color: var(--text-muted); font-size: .78rem; display: flex; gap: 1rem; 891 } 892 footer a { color: var(--text-muted); } 893</style> 894</head> 895<body> 896<main> 897 <div class="top"> 898 <div> 899 <h1>graft — social IDs</h1> 900 <span class="sub">ActivityPub + AT Proto</span> 901 </div> 902 <a class="nav-link" href="/">&larr; Dashboard</a> 903 </div> 904 905 <div class="card"> 906 {{range .Series}} 907 <div class="series-block"> 908 <div class="handle">@{{.Handle}}</div> 909 <h2>ActivityPub &middot; {{.FollowerCount}} follower{{if ne .FollowerCount 1}}s{{end}}</h2> 910 <div class="endpoints"> 911 <a href="{{.WebfingerURL}}" target="_blank" rel="noopener">WebFinger</a> 912 <a href="{{.ActorURL}}" target="_blank" rel="noopener">Actor</a> 913 <a href="{{.OutboxURL}}" target="_blank" rel="noopener">Outbox</a> 914 </div> 915 <h2>AT Proto / Bluesky</h2> 916 <span class="badge">{{if .BlueskyConfigured}}posts on new activity{{else}}not configured{{end}}</span> 917 </div> 918 {{else}} 919 <span class="empty">no series configured</span> 920 {{end}} 921 </div> 922</main> 923<footer> 924 {{if .SourceURL}}<a href="{{.SourceURL}}" target="_blank" rel="noopener">{{.SourceURL}}</a>{{end}} 925 <span>GPLv3</span> 926</footer> 927</body> 928</html> 929`))