Monorepo for Tangled

appview: re-index issues and pulls when labels are modified

Signed-off-by: Thomas Karpiniec <tkarpiniec@icloud.com>

authored by

Thomas Karpiniec and committed by tangled.org b162fea0 79d5bed4

+64
+18
appview/indexer/notifier.go
··· 38 } 39 } 40 41 func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { 42 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 43 l.Debug("indexing new pr")
··· 38 } 39 } 40 41 + func (ix *Indexer) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 42 + l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 43 + l.Debug("reindexing issue after label change") 44 + err := ix.Issues.Index(ctx, *issue) 45 + if err != nil { 46 + l.Error("failed to index an issue", "err", err) 47 + } 48 + } 49 + 50 + func (ix *Indexer) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 51 + l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 52 + l.Debug("reindexing pull after label change") 53 + err := ix.Pulls.Index(ctx, pull) 54 + if err != nil { 55 + l.Error("failed to index a pr", "err", err) 56 + } 57 + } 58 + 59 func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { 60 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 61 l.Debug("indexing new pr")
+18
appview/labels/labels.go
··· 13 "tangled.org/core/appview/db" 14 "tangled.org/core/appview/middleware" 15 "tangled.org/core/appview/models" 16 "tangled.org/core/appview/oauth" 17 "tangled.org/core/appview/pages" 18 "tangled.org/core/appview/validator" ··· 34 logger *slog.Logger 35 validator *validator.Validator 36 enforcer *rbac.Enforcer 37 } 38 39 func New( ··· 42 db *db.DB, 43 validator *validator.Validator, 44 enforcer *rbac.Enforcer, 45 logger *slog.Logger, 46 ) *Labels { 47 return &Labels{ ··· 51 logger: logger, 52 validator: validator, 53 enforcer: enforcer, 54 } 55 } 56 ··· 244 245 // clear aturi when everything is successful 246 atUri = "" 247 248 l.pages.HxRefresh(w) 249 }
··· 13 "tangled.org/core/appview/db" 14 "tangled.org/core/appview/middleware" 15 "tangled.org/core/appview/models" 16 + "tangled.org/core/appview/notify" 17 "tangled.org/core/appview/oauth" 18 "tangled.org/core/appview/pages" 19 "tangled.org/core/appview/validator" ··· 35 logger *slog.Logger 36 validator *validator.Validator 37 enforcer *rbac.Enforcer 38 + notifier notify.Notifier 39 } 40 41 func New( ··· 44 db *db.DB, 45 validator *validator.Validator, 46 enforcer *rbac.Enforcer, 47 + notifier notify.Notifier, 48 logger *slog.Logger, 49 ) *Labels { 50 return &Labels{ ··· 54 logger: logger, 55 validator: validator, 56 enforcer: enforcer, 57 + notifier: notifier, 58 } 59 } 60 ··· 248 249 // clear aturi when everything is successful 250 atUri = "" 251 + 252 + subject := syntax.ATURI(subjectUri) 253 + if subject.Collection() == tangled.RepoIssueNSID { 254 + issues, err := db.GetIssues(l.db, orm.FilterEq("at_uri", subjectUri)) 255 + if err == nil && len(issues) == 1 { 256 + l.notifier.NewIssueLabelOp(r.Context(), &issues[0]) 257 + } 258 + } 259 + if subject.Collection() == tangled.RepoPullNSID { 260 + pulls, err := db.GetPulls(l.db, orm.FilterEq("at_uri", subjectUri)) 261 + if err == nil && len(pulls) == 1 { 262 + l.notifier.NewPullLabelOp(r.Context(), pulls[0]) 263 + } 264 + } 265 266 l.pages.HxRefresh(w) 267 }
+3
appview/notify/db/db.go
··· 206 // no-op for now 207 } 208 209 func (n *databaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 210 actorDid := syntax.DID(follow.UserDid) 211 recipients := sets.Singleton(syntax.DID(follow.SubjectDid))
··· 206 // no-op for now 207 } 208 209 + func (n *databaseNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) {} 210 + func (n *databaseNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) {} 211 + 212 func (n *databaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 213 actorDid := syntax.DID(follow.UserDid) 214 recipients := sets.Singleton(syntax.DID(follow.SubjectDid))
+10
appview/notify/logging_notifier.go
··· 59 l.inner.DeleteIssue(ctx, issue) 60 } 61 62 func (l *loggingNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 63 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewFollow")) 64 l.inner.NewFollow(ctx, follow)
··· 59 l.inner.DeleteIssue(ctx, issue) 60 } 61 62 + func (l *loggingNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 63 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewIssueLabelOp")) 64 + l.inner.NewIssueLabelOp(ctx, issue) 65 + } 66 + 67 + func (l *loggingNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 68 + ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewPullLabelOp")) 69 + l.inner.NewPullLabelOp(ctx, pull) 70 + } 71 + 72 func (l *loggingNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 73 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewFollow")) 74 l.inner.NewFollow(ctx, follow)
+8
appview/notify/merged_notifier.go
··· 58 m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) 59 } 60 61 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 62 m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) 63 }
··· 58 m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) 59 } 60 61 + func (m *mergedNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) { 62 + m.fanout(func(n Notifier) { n.NewIssueLabelOp(ctx, issue) }) 63 + } 64 + 65 + func (m *mergedNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) { 66 + m.fanout(func(n Notifier) { n.NewPullLabelOp(ctx, pull) }) 67 + } 68 + 69 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 70 m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) 71 }
+6
appview/notify/notifier.go
··· 25 NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 UpdateProfile(ctx context.Context, profile *models.Profile) 29 30 NewString(ctx context.Context, s *models.String) ··· 49 } 50 func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 51 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 52 53 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 54 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
··· 25 NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 + NewIssueLabelOp(ctx context.Context, issue *models.Issue) 29 + NewPullLabelOp(ctx context.Context, pull *models.Pull) 30 + 31 UpdateProfile(ctx context.Context, profile *models.Profile) 32 33 NewString(ctx context.Context, s *models.String) ··· 52 } 53 func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 54 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 55 + 56 + func (m *BaseNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) {} 57 + func (m *BaseNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) {} 58 59 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 60 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
+1
appview/state/router.go
··· 340 s.db, 341 s.validator, 342 s.enforcer, 343 log.SubLogger(s.logger, "labels"), 344 ) 345 return ls.Router()
··· 340 s.db, 341 s.validator, 342 s.enforcer, 343 + s.notifier, 344 log.SubLogger(s.logger, "labels"), 345 ) 346 return ls.Router()