a love letter to tangled (android, iOS, and a search API)
1package normalize
2
3import (
4 "fmt"
5
6 "tangled.org/desertthunder.dev/twister/internal/store"
7)
8
9const collectionPullComment = "sh.tangled.repo.pull.comment"
10
11// PullCommentAdapter normalizes pull comments for collaborator discovery.
12type PullCommentAdapter struct{}
13
14func (a *PullCommentAdapter) Collection() string { return collectionPullComment }
15func (a *PullCommentAdapter) RecordType() string { return "pull_comment" }
16
17func (a *PullCommentAdapter) Searchable(record map[string]any) bool {
18 return str(record, "body") != ""
19}
20
21func (a *PullCommentAdapter) Normalize(event TapRecordEvent) (*store.Document, error) {
22 r := event.Record
23 rec := r.Record
24 body := str(rec, "body")
25 pullURI := str(rec, "pull")
26
27 repoDID := ""
28 if pullURI != "" {
29 did, _, _, err := ParseATURI(pullURI)
30 if err != nil {
31 return nil, fmt.Errorf("pull comment pull AT-URI: %w", err)
32 }
33 repoDID = did
34 }
35
36 return &store.Document{
37 ID: StableID(r.DID, r.Collection, r.RKey),
38 DID: r.DID,
39 Collection: r.Collection,
40 RKey: r.RKey,
41 ATURI: BuildATURI(r.DID, r.Collection, r.RKey),
42 CID: r.CID,
43 RecordType: a.RecordType(),
44 Body: body,
45 Summary: truncate(body, 200),
46 RepoDID: repoDID,
47 TagsJSON: "[]",
48 CreatedAt: str(rec, "createdAt"),
49 }, nil
50}