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 38 } 39 39 } 40 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 + 41 59 func (ix *Indexer) NewPull(ctx context.Context, pull *models.Pull) { 42 60 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 43 61 l.Debug("indexing new pr")
+18
appview/labels/labels.go
··· 13 13 "tangled.org/core/appview/db" 14 14 "tangled.org/core/appview/middleware" 15 15 "tangled.org/core/appview/models" 16 + "tangled.org/core/appview/notify" 16 17 "tangled.org/core/appview/oauth" 17 18 "tangled.org/core/appview/pages" 18 19 "tangled.org/core/appview/validator" ··· 34 35 logger *slog.Logger 35 36 validator *validator.Validator 36 37 enforcer *rbac.Enforcer 38 + notifier notify.Notifier 37 39 } 38 40 39 41 func New( ··· 42 44 db *db.DB, 43 45 validator *validator.Validator, 44 46 enforcer *rbac.Enforcer, 47 + notifier notify.Notifier, 45 48 logger *slog.Logger, 46 49 ) *Labels { 47 50 return &Labels{ ··· 51 54 logger: logger, 52 55 validator: validator, 53 56 enforcer: enforcer, 57 + notifier: notifier, 54 58 } 55 59 } 56 60 ··· 244 248 245 249 // clear aturi when everything is successful 246 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 + } 247 265 248 266 l.pages.HxRefresh(w) 249 267 }
+3
appview/notify/db/db.go
··· 206 206 // no-op for now 207 207 } 208 208 209 + func (n *databaseNotifier) NewIssueLabelOp(ctx context.Context, issue *models.Issue) {} 210 + func (n *databaseNotifier) NewPullLabelOp(ctx context.Context, pull *models.Pull) {} 211 + 209 212 func (n *databaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 210 213 actorDid := syntax.DID(follow.UserDid) 211 214 recipients := sets.Singleton(syntax.DID(follow.SubjectDid))
+10
appview/notify/logging_notifier.go
··· 59 59 l.inner.DeleteIssue(ctx, issue) 60 60 } 61 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 + 62 72 func (l *loggingNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 63 73 ctx = tlog.IntoContext(ctx, tlog.SubLogger(l.logger, "NewFollow")) 64 74 l.inner.NewFollow(ctx, follow)
+8
appview/notify/merged_notifier.go
··· 58 58 m.fanout(func(n Notifier) { n.DeleteIssue(ctx, issue) }) 59 59 } 60 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 + 61 69 func (m *mergedNotifier) NewFollow(ctx context.Context, follow *models.Follow) { 62 70 m.fanout(func(n Notifier) { n.NewFollow(ctx, follow) }) 63 71 }
+6
appview/notify/notifier.go
··· 25 25 NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 26 NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 27 28 + NewIssueLabelOp(ctx context.Context, issue *models.Issue) 29 + NewPullLabelOp(ctx context.Context, pull *models.Pull) 30 + 28 31 UpdateProfile(ctx context.Context, profile *models.Profile) 29 32 30 33 NewString(ctx context.Context, s *models.String) ··· 49 52 } 50 53 func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 51 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) {} 52 58 53 59 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 54 60 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {}
+1
appview/state/router.go
··· 340 340 s.db, 341 341 s.validator, 342 342 s.enforcer, 343 + s.notifier, 343 344 log.SubLogger(s.logger, "labels"), 344 345 ) 345 346 return ls.Router()