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 Events []event 313} 314 315// event is one heatmap cell, one tooltip, one link — either a real 316// activity_log row, or (when State is set) a synthetic cell standing in for 317// content this side plainly holds without graft ever having logged a push 318// to it directly: the Forgejo side changes originate on ("source"), or a 319// side that received the content some other way graft doesn't log itself — 320// Radicle's own peer-to-peer gossip, or a Forgejo-to-Forgejo Authorized 321// Integration ("replicated"). Synthetic cells reuse the real event they 322// stand in for (same kind, date, summary) so they read exactly like a 323// normal commit/issue/patch cell, just in a different color, with the 324// tooltip naming where it actually happened. 325type event struct { 326 Kind string // "git", "issue", "patch" — drives the cell's color when State is unset 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 State string // "" for a real event; "source" or "replicated" for a synthetic one — drives the cell's color instead of Kind 333 OriginLabel string // for a synthetic cell, the sub-row label the real event was actually logged on 334} 335 336type commitLine struct { 337 When string 338 Pair string 339 PairURL string 340 Server string 341 Kind string // "Commit", "Issue", "Patch" 342 Message string 343 URL string 344} 345 346// serverLabel names which side of a series a repo_pair belongs to, e.g. 347// "federation-x-f1" under series "federation-x" becomes "f1". Several pairs 348// share one series row/badge, so without this an operator can't tell which 349// mirrored server (f1, f2, an external instance...) a given event actually 350// happened on. Empty if the pair name doesn't start with its series name. 351func serverLabel(repoPair, series string) string { 352 if series == "" { 353 return "" 354 } 355 suffix := strings.TrimPrefix(repoPair, series+"-") 356 if suffix == repoPair { 357 return "" 358 } 359 return suffix 360} 361 362// hostLabel shortens a URL's host to its canonical name for compact 363// display: the TLD is dropped ("f1.cyberwild.org" -> "f1.cyberwild", 364// "artefacts.bimr.net" -> "artefacts.bimr"), so every server — ours or an 365// external instance's — reads the same way, never a per-pair alias. 366func hostLabel(rawURL string) string { 367 u, err := url.Parse(rawURL) 368 if err != nil || u.Host == "" { 369 return "" 370 } 371 host := u.Host 372 // A Radicle Explorer URL's host is always the shared frontend 373 // (e.g. radicle.cyberwild.org) — the actual node lives in the path, 374 // /nodes/<node-host>/<rid>/... — so different Radicle nodes get 375 // distinct labels instead of collapsing into one shared one. 376 if segs := strings.Split(strings.TrimPrefix(u.Path, "/"), "/"); len(segs) >= 2 && segs[0] == "nodes" { 377 host = segs[1] 378 } 379 return host 380} 381 382// buildSeriesRows groups entries by their Series (one row per monitored 383// repo, spanning both its Forgejo and Radicle sides) — Atlassian 384// Statuspage style: one full-width horizontal strip per series. Each entry 385// becomes its own cell, oldest first, so a busy day never hides events 386// behind one shared tooltip. 387func buildSeriesRows(entries []state.ActivityEntry, health map[string]bool, topology map[string][]ServerRef) []seriesRow { 388 type subAcc struct { 389 url string 390 events []state.ActivityEntry 391 radicle bool 392 ai bool 393 } 394 type seriesAcc struct { 395 subOrder []string 396 subs map[string]*subAcc 397 } 398 seriesAccs := map[string]*seriesAcc{} 399 var seriesOrder []string 400 401 ensureSeries := func(name string) *seriesAcc { 402 sa, ok := seriesAccs[name] 403 if !ok { 404 sa = &seriesAcc{subs: map[string]*subAcc{}} 405 seriesAccs[name] = sa 406 seriesOrder = append(seriesOrder, name) 407 } 408 return sa 409 } 410 ensureSub := func(sa *seriesAcc, label string) *subAcc { 411 sub, ok := sa.subs[label] 412 if !ok { 413 sub = &subAcc{} 414 sa.subs[label] = sub 415 sa.subOrder = append(sa.subOrder, label) 416 } 417 return sub 418 } 419 420 // Seed every configured mirror target first, so a side that has never 421 // produced an event (e.g. a Radicle node nothing has been pushed to 422 // yet) still gets its own row instead of being invisible. 423 for name, refs := range topology { 424 sa := ensureSeries(name) 425 for _, ref := range refs { 426 sub := ensureSub(sa, ref.Label) 427 if sub.url == "" { 428 sub.url = ref.URL 429 } 430 sub.radicle = ref.Radicle 431 sub.ai = ref.AuthorizedIntegration 432 } 433 } 434 435 for _, e := range entries { 436 name := e.Series 437 if name == "" { 438 name = e.RepoPair 439 } 440 sa := ensureSeries(name) 441 server := hostLabel(e.URL) 442 if server == "" { 443 server = serverLabel(e.RepoPair, e.Series) 444 } 445 if server == "" { 446 server = e.RepoPair 447 } 448 sub := ensureSub(sa, server) 449 if sub.url == "" { 450 sub.url = repoRootURL(e.URL) 451 } 452 sub.events = append(sub.events, e) 453 } 454 sort.Strings(seriesOrder) 455 456 rows := make([]seriesRow, 0, len(seriesOrder)) 457 for _, name := range seriesOrder { 458 sa := seriesAccs[name] 459 subOrder := append([]string(nil), sa.subOrder...) 460 sort.Strings(subOrder) 461 462 // distinctEvents dedupes every event logged anywhere in the series 463 // down to one representative per real underlying commit/issue/patch 464 // — keyed by commit SHA for git (content-addressed, stable across 465 // every mirror), or by (kind, summary) otherwise — keeping 466 // whichever occurrence was logged earliest, since that's the 467 // closest graft gets to "when this actually entered the series". 468 // A series with at least one logged event anywhere means every 469 // currently-silent side already holds this content too — either 470 // as the origin, or received via a path graft doesn't log itself 471 // (Radicle gossip, an Authorized Integration) — so those sides 472 // get synthetic cells built from this map instead of the usual 473 // per-event ones. Only a series with zero events anywhere stays 474 // genuinely empty. 475 type rep struct { 476 entry state.ActivityEntry 477 label string 478 } 479 reps := map[string]rep{} 480 for _, label := range subOrder { 481 for _, e := range sa.subs[label].events { 482 key := dedupKey(e.Kind, e.URL, e.Summary) 483 cur, ok := reps[key] 484 if !ok || e.OccurredAt.Before(cur.entry.OccurredAt) { 485 reps[key] = rep{entry: e, label: label} 486 } 487 } 488 } 489 repKeys := make([]string, 0, len(reps)) 490 for k := range reps { 491 repKeys = append(repKeys, k) 492 } 493 sort.Slice(repKeys, func(i, j int) bool { 494 return reps[repKeys[i]].entry.OccurredAt.Before(reps[repKeys[j]].entry.OccurredAt) 495 }) 496 497 subRows := make([]subRow, 0, len(subOrder)) 498 for _, label := range subOrder { 499 sub := sa.subs[label] 500 if len(sub.events) == 0 && len(reps) > 0 { 501 cellState := "source" 502 if sub.ai || sub.radicle { 503 cellState = "replicated" 504 } 505 synth := make([]event, 0, len(repKeys)) 506 for _, k := range repKeys { 507 r := reps[k] 508 synth = append(synth, event{ 509 Kind: r.entry.Kind, 510 Label: kindLabel(r.entry.Kind), 511 Text: r.entry.Summary, 512 URL: reconstructLink(sub.url, r.entry.Kind, r.entry.URL), 513 Server: label, 514 When: r.entry.OccurredAt.Format("Mon, Jan 2, 15:04"), 515 State: cellState, 516 OriginLabel: r.label, 517 }) 518 } 519 subRows = append(subRows, subRow{Label: label, URL: sub.url, Events: synth}) 520 continue 521 } 522 523 // entries arrive newest-first (see ActivitySince); the 524 // heatmap reads left-to-right as oldest-to-newest. 525 es := make([]state.ActivityEntry, len(sub.events)) 526 copy(es, sub.events) 527 sort.Slice(es, func(i, j int) bool { return es[i].OccurredAt.Before(es[j].OccurredAt) }) 528 subRows = append(subRows, subRow{Label: label, URL: sub.url, Events: toEvents(es)}) 529 } 530 531 ok, known := health[name] 532 if !known { 533 ok = true 534 } 535 rows = append(rows, seriesRow{Name: name, OK: ok, SubRows: subRows}) 536 } 537 return rows 538} 539 540func toEvents(es []state.ActivityEntry) []event { 541 out := make([]event, 0, len(es)) 542 for _, e := range es { 543 server := hostLabel(e.URL) 544 if server == "" { 545 server = serverLabel(e.RepoPair, e.Series) 546 } 547 out = append(out, event{ 548 Kind: e.Kind, 549 Label: kindLabel(e.Kind), 550 Text: e.Summary, 551 URL: e.URL, 552 Server: server, 553 When: e.OccurredAt.Format("Mon, Jan 2, 15:04"), 554 }) 555 } 556 return out 557} 558 559func kindLabel(kind string) string { 560 switch kind { 561 case "git": 562 return "Commit" 563 case "issue": 564 return "Issue" 565 case "patch": 566 return "Patch" 567 default: 568 return kind 569 } 570} 571 572// recentActivity lists every mirrored event — commits, issues, and 573// patches/pull requests alike, newest first. graft doesn't mirror stars or 574// other social metadata: its sync scope is git content, issues, and 575// patches/PRs only (see config.SyncScope), so that's what shows up here. 576func recentActivity(entries []state.ActivityEntry) []commitLine { 577 out := make([]commitLine, 0, len(entries)) 578 for _, e := range entries { 579 name := e.Series 580 if name == "" { 581 name = e.RepoPair 582 } 583 server := hostLabel(e.URL) 584 if server == "" { 585 server = serverLabel(e.RepoPair, e.Series) 586 } 587 // The (server) parenthetical should point at that specific 588 // server's own repo, not the series' shared Radicle explorer 589 // link (which is fixed to whichever pair logged first). 590 pairURL := repoRootURL(e.URL) 591 if pairURL == "" { 592 pairURL = e.SeriesURL 593 } 594 out = append(out, commitLine{ 595 When: e.OccurredAt.Format("Jan 2, 15:04"), 596 Pair: name, 597 PairURL: pairURL, 598 Server: server, 599 Kind: kindLabel(e.Kind), 600 Message: e.Summary, 601 URL: e.URL, 602 }) 603 } 604 return out 605} 606 607// repoRootURL trims an event's specific-item URL (a commit, issue, or 608// patch/PR page) back down to its repository root, e.g. 609// ".../owner/repo/commit/<sha>" -> ".../owner/repo". Empty if rawURL is 610// empty or doesn't contain a recognized item path. 611func repoRootURL(rawURL string) string { 612 // Forgejo uses singular "/commit/"; Radicle Explorer uses plural 613 // "/commits/" — both must be recognized, or every Radicle-hosted 614 // commit link falls back to a non-clickable label. 615 for _, marker := range []string{"/commit/", "/commits/", "/issues/", "/pulls/", "/patches/"} { 616 if idx := strings.Index(rawURL, marker); idx >= 0 { 617 return rawURL[:idx] 618 } 619 } 620 return "" 621} 622 623// commitSHA pulls the trailing commit hash out of a git-item URL, e.g. 624// ".../owner/repo/commit/<sha>" or ".../repo/commits/<sha>" -> "<sha>". 625// Empty if rawURL isn't a recognized commit link. 626func commitSHA(rawURL string) string { 627 for _, marker := range []string{"/commit/", "/commits/"} { 628 idx := strings.Index(rawURL, marker) 629 if idx < 0 { 630 continue 631 } 632 sha := rawURL[idx+len(marker):] 633 if i := strings.IndexAny(sha, "/?#"); i >= 0 { 634 sha = sha[:i] 635 } 636 return sha 637 } 638 return "" 639} 640 641// dedupKey identifies "the same underlying event" across every mirror it 642// got logged on. A commit is content-addressed — its SHA is identical on 643// every side it's mirrored to — so that's the stable key for git events. 644// Issues and patches get local, per-instance IDs that aren't portable 645// across hosts, so their summary text is the best available stand-in. 646func dedupKey(kind, url, summary string) string { 647 if sha := commitSHA(url); sha != "" { 648 return kind + ":" + sha 649 } 650 return kind + ":" + summary 651} 652 653// reconstructLink builds a same-host link for a synthetic cell: a commit's 654// SHA is identical everywhere it's mirrored, so subURL (this side's own 655// repo root) plus the right per-host item path reaches the same commit on 656// this side specifically, rather than sending the reader to the side it 657// was actually logged on. Falls back to the original event's own URL for 658// anything that isn't a reconstructible git link — an issue or patch ID 659// isn't portable across hosts, so linking to where it's actually visible 660// beats guessing. 661func reconstructLink(subURL, kind, originURL string) string { 662 sha := commitSHA(originURL) 663 if kind != "git" || sha == "" || subURL == "" { 664 return originURL 665 } 666 if strings.Contains(subURL, "/nodes/") { 667 return subURL + "/commits/" + sha 668 } 669 return subURL + "/commit/" + sha 670} 671 672var dashboardTmpl = template.Must(template.New("dashboard").Parse(`<!doctype html> 673<html lang="en"> 674<head> 675<meta charset="utf-8"> 676<meta name="viewport" content="width=device-width, initial-scale=1"> 677<title>graft</title> 678<style> 679 :root { 680 color-scheme: light; 681 --surface: #ffffff; 682 --surface-sunk: #f4f5f7; 683 --text: #172b4d; 684 --text-muted: #6b778c; 685 --border: #dfe1e6; 686 --brand: #0052cc; 687 --brand-dark: #0747a6; 688 --kind-git: #0052cc; 689 --kind-issue: #00875a; 690 --kind-patch: #6554c0; 691 --kind-source: #ff991f; 692 --kind-replicated: #00b8d9; 693 --bad: #de350b; 694 --good: #36b37e; 695 } 696 * { box-sizing: border-box; } 697 body { 698 margin: 0; 699 background: var(--surface-sunk); 700 color: var(--text); 701 font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 702 } 703 main { max-width: 920px; margin: 0 auto; padding: 2.5rem 1.5rem 1rem; } 704 705 .top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.5rem; } 706 .top > div { display: flex; align-items: baseline; gap: .6rem; } 707 h1 { font-size: 1.25rem; margin: 0; font-weight: 600; } 708 .sub { color: var(--text-muted); font-size: .85rem; } 709 .nav-link { color: var(--brand); font-size: .82rem; text-decoration: none; font-weight: 500; } 710 .nav-link:hover { text-decoration: underline; } 711 712 .card { 713 background: var(--surface); 714 border: 1px solid var(--border); 715 border-radius: 4px; 716 padding: 1.25rem 1.5rem; 717 margin-bottom: 1.25rem; 718 } 719 720 .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; display: inline-block; } 721 .dot.bad { background: var(--bad); } 722 723 .heatmap-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: .9rem; } 724 .heatmap-head h2 { margin: 0; } 725 .legend { display: flex; gap: .9rem; margin-bottom: .9rem; } 726 .legend span { display: flex; align-items: center; gap: .35rem; font-size: .74rem; color: var(--text-muted); } 727 .legend .sw { width: 8px; height: 8px; border-radius: 2px; display: inline-block; } 728 .legend .sw[data-kind="git"] { background: var(--kind-git); } 729 .legend .sw[data-kind="issue"] { background: var(--kind-issue); } 730 .legend .sw[data-kind="patch"] { background: var(--kind-patch); } 731 .legend .sw[data-kind="source"] { background: var(--kind-source); } 732 .legend .sw[data-kind="replicated"] { background: var(--kind-replicated); } 733 .heatmap { display: flex; flex-direction: column; gap: .15rem; } 734 .series-group { border-bottom: 1px solid var(--border); } 735 .series-group:last-child { border-bottom: none; } 736 .series-group[open] { padding-bottom: .5rem; } 737 .series-label { 738 display: flex; align-items: center; gap: .45rem; padding: .55rem 0; 739 cursor: pointer; list-style: none; 740 } 741 .series-label::-webkit-details-marker { display: none; } 742 .series-label::before { 743 content: ""; width: 0; height: 0; flex: none; 744 border-style: solid; border-width: 4px 0 4px 5px; 745 border-color: transparent transparent transparent var(--text-muted); 746 transition: transform .12s ease; 747 } 748 .series-group[open] > .series-label::before { transform: rotate(90deg); } 749 .series-name { font-size: .82rem; font-weight: 600; color: var(--text); } 750 .series-count { font-size: .74rem; color: var(--text-muted); } 751 .subrows { display: flex; flex-direction: column; gap: .5rem; padding-left: 1.3rem; } 752 .subrow { display: flex; align-items: center; gap: .75rem; } 753 .subrow-name { 754 flex: 0 0 11rem; font-size: .78rem; color: var(--text-muted); text-decoration: none; 755 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 756 } 757 a.subrow-name { color: var(--brand); } 758 a.subrow-name:hover { text-decoration: underline; } 759 .days { display: flex; gap: 3px; flex-wrap: wrap; } 760 .cell { 761 flex: none; width: 10px; height: 22px; border-radius: 3px; 762 background: var(--border); position: relative; cursor: default; 763 } 764 .cell[data-kind="git"] { background: var(--kind-git); } 765 .cell[data-kind="issue"] { background: var(--kind-issue); } 766 .cell[data-kind="patch"] { background: var(--kind-patch); } 767 .cell[data-kind="source"] { background: var(--kind-source); } 768 .cell[data-kind="replicated"] { background: var(--kind-replicated); } 769 770 .tip { 771 display: none; position: absolute; top: calc(100% + 8px); left: 50%; transform: translateX(-50%); 772 background: var(--text); color: #fff; border-radius: 6px; 773 font-size: .78rem; z-index: 20; padding: .5rem 0; 774 box-shadow: 0 4px 12px rgba(9,30,66,.25); 775 width: max-content; max-width: min(320px, 90vw); 776 } 777 .cell:nth-child(-n+2) .tip { left: 0; transform: none; } 778 .cell:nth-last-child(-n+2) .tip { left: auto; right: 0; transform: none; } 779 .cell:hover .tip, .tip:hover { display: block; } 780 .tip .tip-date { padding: 0 .75rem .35rem; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,.15); margin-bottom: .35rem; } 781 .tip a.tip-row { 782 display: flex; gap: .4em; padding: .3rem .75rem; color: #fff; text-decoration: none; 783 white-space: normal; overflow-wrap: anywhere; line-height: 1.35; 784 } 785 .tip a.tip-row:hover { background: rgba(255,255,255,.12); } 786 .tip .tip-kind { color: #b3bac5; flex: none; } 787 .tip .tip-empty { padding: 0 .75rem; color: #b3bac5; } 788 .tip .tip-note { 789 padding: .35rem .75rem 0; margin-top: .3rem; border-top: 1px solid rgba(255,255,255,.15); 790 color: #b3bac5; font-size: .7rem; line-height: 1.4; 791 } 792 793 h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 .9rem; font-weight: 600; } 794 .commits { border-top: 1px solid var(--border); } 795 .commit { 796 display: flex; align-items: center; gap: .75rem; padding: .55rem 0; border-bottom: 1px solid var(--border); 797 font-size: .82rem; 798 } 799 .commit .when { color: var(--text-muted); flex: none; width: 9em; } 800 .commit .kind { color: var(--text-muted); flex: none; width: 4.5em; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; } 801 .commit .pair { 802 color: var(--text-muted); flex: 0 1 auto; max-width: 22em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; 803 text-decoration: none; 804 } 805 .commit a.pair { color: var(--brand); } 806 .commit a.pair:hover { text-decoration: underline; } 807 .commit .msg { 808 flex: 1 1 auto; min-width: 0; 809 overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace; 810 color: inherit; text-decoration: none; 811 } 812 .commit a.msg { color: var(--brand); } 813 .commit a.msg:hover { text-decoration: underline; } 814 .empty { color: var(--text-muted); padding: .5rem 0; } 815 816 footer { 817 max-width: 920px; margin: 0 auto; padding: 1rem 1.5rem 2.5rem; 818 color: var(--text-muted); font-size: .78rem; display: flex; gap: 1rem; 819 } 820 footer a { color: var(--text-muted); } 821</style> 822</head> 823<body> 824<main> 825 <div class="top"> 826 <div> 827 <h1>graft</h1> 828 <span class="sub">Forgejos &amp; Radicles syncs</span> 829 </div> 830 {{if .SocialEnabled}}<a class="nav-link" href="/social">Social IDs &rarr;</a>{{end}} 831 </div> 832 833 <div class="card"> 834 <div class="heatmap-head"> 835 <div class="legend"> 836 <span><i class="sw" data-kind="git"></i>Commit</span> 837 <span><i class="sw" data-kind="issue"></i>Issue</span> 838 <span><i class="sw" data-kind="patch"></i>Patch</span> 839 <span><i class="sw" data-kind="source"></i>Source</span> 840 <span><i class="sw" data-kind="replicated"></i>Replicated</span> 841 </div> 842 </div> 843 <div class="heatmap"> 844 {{range .Series}} 845 <details class="series-group"> 846 <summary class="series-label"> 847 <span class="dot{{if not .OK}} bad{{end}}"></span> 848 <span class="series-name">{{.Name}}</span> 849 <span class="series-count">{{len .SubRows}} mirror{{if ne (len .SubRows) 1}}s{{end}}</span> 850 </summary> 851 <div class="subrows"> 852 {{range .SubRows}} 853 <div class="subrow"> 854 {{if .URL}} 855 <a class="subrow-name" href="{{.URL}}" target="_blank" rel="noopener">{{.Label}}</a> 856 {{else}} 857 <span class="subrow-name">{{.Label}}</span> 858 {{end}} 859 <div class="days"> 860 {{range .Events}} 861 <div class="cell" data-kind="{{if .State}}{{.State}}{{else}}{{.Kind}}{{end}}"> 862 <div class="tip"> 863 <div class="tip-date">{{.When}}</div> 864 {{if .URL}} 865 <a class="tip-row" href="{{.URL}}" target="_blank" rel="noopener"><span class="tip-kind">{{.Label}}{{if eq .State "source"}} · source{{else if eq .State "replicated"}} · replicated{{end}}</span>{{.Text}}</a> 866 {{else}} 867 <span class="tip-row"><span class="tip-kind">{{.Label}}{{if eq .State "source"}} · source{{else if eq .State "replicated"}} · replicated{{end}}</span>{{.Text}}</span> 868 {{end}} 869 {{if eq .State "source"}} 870 <div class="tip-note">origin of this content — graft mirrored it out from here, via {{.OriginLabel}}</div> 871 {{else if eq .State "replicated"}} 872 <div class="tip-note">replicated here without a graft-logged push — originally pushed via {{.OriginLabel}}, {{.When}}</div> 873 {{end}} 874 </div> 875 </div> 876 {{else}} 877 <span class="tip-empty">nothing synced</span> 878 {{end}} 879 </div> 880 </div> 881 {{end}} 882 </div> 883 </details> 884 {{else}} 885 <span class="empty">nothing synced yet</span> 886 {{end}} 887 </div> 888 </div> 889 890 <div class="card"> 891 <div class="heatmap-head"> 892 <h2>Recent activity</h2> 893 <span class="sub">last 3 days</span> 894 </div> 895 <div class="commits"> 896 {{range .Activity}} 897 <div class="commit"> 898 <span class="when">{{.When}}</span> 899 <span class="kind">{{.Kind}}</span> 900 {{if .PairURL}} 901 <a class="pair" href="{{.PairURL}}" target="_blank" rel="noopener">{{.Pair}}{{if .Server}} ({{.Server}}){{end}}</a> 902 {{else}} 903 <span class="pair">{{.Pair}}{{if .Server}} ({{.Server}}){{end}}</span> 904 {{end}} 905 {{if .URL}} 906 <a class="msg" href="{{.URL}}" target="_blank" rel="noopener">{{.Message}}</a> 907 {{else}} 908 <span class="msg">{{.Message}}</span> 909 {{end}} 910 </div> 911 {{else}} 912 <p class="empty">nothing mirrored yet</p> 913 {{end}} 914 </div> 915 </div> 916</main> 917<footer> 918 {{if .SourceURL}}<a href="{{.SourceURL}}" target="_blank" rel="noopener">{{.SourceURL}}</a>{{end}} 919 <span>GPLv3</span> 920</footer> 921</body> 922</html> 923`)) 924 925var socialTmpl = template.Must(template.New("social").Parse(`<!doctype html> 926<html lang="en"> 927<head> 928<meta charset="utf-8"> 929<meta name="viewport" content="width=device-width, initial-scale=1"> 930<title>graft — social IDs</title> 931<style> 932 :root { 933 color-scheme: light; 934 --surface: #ffffff; 935 --surface-sunk: #f4f5f7; 936 --text: #172b4d; 937 --text-muted: #6b778c; 938 --border: #dfe1e6; 939 --brand: #0052cc; 940 } 941 * { box-sizing: border-box; } 942 body { 943 margin: 0; background: var(--surface-sunk); color: var(--text); 944 font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 945 } 946 main { max-width: 760px; margin: 0 auto; padding: 2.5rem 1.5rem 1rem; } 947 .top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.5rem; } 948 .top > div { display: flex; align-items: baseline; gap: .6rem; } 949 h1 { font-size: 1.25rem; margin: 0; font-weight: 600; } 950 .sub { color: var(--text-muted); font-size: .85rem; } 951 .nav-link { color: var(--brand); font-size: .82rem; text-decoration: none; font-weight: 500; } 952 .nav-link:hover { text-decoration: underline; } 953 .card { 954 background: var(--surface); border: 1px solid var(--border); border-radius: 4px; 955 padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; 956 } 957 .series-block { padding: .75rem 0; border-bottom: 1px solid var(--border); } 958 .series-block:last-child { border-bottom: none; } 959 .handle { font-size: .95rem; font-weight: 600; color: var(--text); } 960 h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: .6rem 0 .4rem; font-weight: 600; } 961 .endpoints { display: flex; flex-direction: column; gap: .3rem; } 962 .endpoints a { font-size: .8rem; color: var(--brand); text-decoration: none; font-family: ui-monospace, monospace; } 963 .endpoints a:hover { text-decoration: underline; } 964 .badge { 965 display: inline-block; font-size: .72rem; color: var(--text-muted); background: var(--surface-sunk); 966 border: 1px solid var(--border); border-radius: 3px; padding: .15rem .5rem; margin-top: .4rem; 967 } 968 .empty { color: var(--text-muted); padding: .5rem 0; } 969 footer { 970 max-width: 760px; margin: 0 auto; padding: 1rem 1.5rem 2.5rem; 971 color: var(--text-muted); font-size: .78rem; display: flex; gap: 1rem; 972 } 973 footer a { color: var(--text-muted); } 974</style> 975</head> 976<body> 977<main> 978 <div class="top"> 979 <div> 980 <h1>graft — social IDs</h1> 981 <span class="sub">ActivityPub + AT Proto</span> 982 </div> 983 <a class="nav-link" href="/">&larr; Dashboard</a> 984 </div> 985 986 <div class="card"> 987 {{range .Series}} 988 <div class="series-block"> 989 <div class="handle">@{{.Handle}}</div> 990 <h2>ActivityPub &middot; {{.FollowerCount}} follower{{if ne .FollowerCount 1}}s{{end}}</h2> 991 <div class="endpoints"> 992 <a href="{{.WebfingerURL}}" target="_blank" rel="noopener">WebFinger</a> 993 <a href="{{.ActorURL}}" target="_blank" rel="noopener">Actor</a> 994 <a href="{{.OutboxURL}}" target="_blank" rel="noopener">Outbox</a> 995 </div> 996 <h2>AT Proto / Bluesky</h2> 997 <span class="badge">{{if .BlueskyConfigured}}posts on new activity{{else}}not configured{{end}}</span> 998 </div> 999 {{else}} 1000 <span class="empty">no series configured</span> 1001 {{end}} 1002 </div> 1003</main> 1004<footer> 1005 {{if .SourceURL}}<a href="{{.SourceURL}}" target="_blank" rel="noopener">{{.SourceURL}}</a>{{end}} 1006 <span>GPLv3</span> 1007</footer> 1008</body> 1009</html> 1010`))