···
case tangled.RepoIssueNSID:
err = i.ingestIssue(ctx, e)
77
+
case tangled.RepoIssueCommentNSID:
78
+
err = i.ingestIssueComment(e)
l = i.Logger.With("nsid", e.Commit.Collection)
···
return fmt.Errorf("unknown operation: %s", e.Commit.Operation)
868
+
func (i *Ingester) ingestIssueComment(e *models.Event) error {
870
+
rkey := e.Commit.RKey
874
+
l := i.Logger.With("handler", "ingestIssueComment", "nsid", e.Commit.Collection, "did", did, "rkey", rkey)
875
+
l.Info("ingesting record")
877
+
ddb, ok := i.Db.Execer.(*db.DB)
879
+
return fmt.Errorf("failed to index issue comment record, invalid db cast")
882
+
switch e.Commit.Operation {
883
+
case models.CommitOperationCreate:
884
+
raw := json.RawMessage(e.Commit.Record)
885
+
record := tangled.RepoIssueComment{}
886
+
err = json.Unmarshal(raw, &record)
888
+
l.Error("invalid record", "err", err)
892
+
comment, err := db.IssueCommentFromRecord(ddb, did, rkey, record)
894
+
l.Error("failed to parse comment from record", "err", err)
898
+
sanitizer := markup.NewSanitizer()
899
+
if sb := strings.TrimSpace(sanitizer.SanitizeDefault(comment.Body)); sb == "" {
900
+
return fmt.Errorf("body is empty after HTML sanitization")
903
+
err = db.NewIssueComment(ddb, &comment)
905
+
l.Error("failed to create issue comment", "err", err)
911
+
case models.CommitOperationUpdate:
912
+
raw := json.RawMessage(e.Commit.Record)
913
+
record := tangled.RepoIssueComment{}
914
+
err = json.Unmarshal(raw, &record)
916
+
l.Error("invalid record", "err", err)
920
+
sanitizer := markup.NewSanitizer()
921
+
if sb := strings.TrimSpace(sanitizer.SanitizeDefault(record.Body)); sb == "" {
922
+
return fmt.Errorf("body is empty after HTML sanitization")
925
+
err = db.UpdateCommentByRkey(ddb, did, rkey, record.Body)
927
+
l.Error("failed to update issue comment", "err", err)
933
+
case models.CommitOperationDelete:
934
+
if err := db.DeleteCommentByRkey(ddb, did, rkey); err != nil {
935
+
l.Error("failed to delete", "err", err)
936
+
return fmt.Errorf("failed to delete issue comment record: %w", err)
942
+
return fmt.Errorf("unknown operation: %s", e.Commit.Operation)