Monorepo for Tangled tangled.org

appview/notify: use correct actor on issue/pr state change events

Signed-off-by: Seongmin Lee <git@boltless.me>

boltless.me 3d18fe3a fdbd73d8

verified
Changed files
+24 -23
appview
+2 -2
appview/indexer/notifier.go
··· 20 } 21 } 22 23 - func (ix *Indexer) NewIssueState(ctx context.Context, issue *models.Issue) { 24 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 25 l.Debug("updating an issue") 26 err := ix.Issues.Index(ctx, *issue) ··· 47 } 48 } 49 50 - func (ix *Indexer) NewPullState(ctx context.Context, pull *models.Pull) { 51 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 52 l.Debug("updating a pr") 53 err := ix.Pulls.Index(ctx, pull)
··· 20 } 21 } 22 23 + func (ix *Indexer) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 24 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 25 l.Debug("updating an issue") 26 err := ix.Issues.Index(ctx, *issue) ··· 47 } 48 } 49 50 + func (ix *Indexer) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 51 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 52 l.Debug("updating a pr") 53 err := ix.Pulls.Index(ctx, pull)
+2 -2
appview/issues/issues.go
··· 310 issue.Open = false 311 312 // notify about the issue closure 313 - rp.notifier.NewIssueState(r.Context(), issue) 314 315 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 316 return ··· 360 issue.Open = true 361 362 // notify about the issue reopen 363 - rp.notifier.NewIssueState(r.Context(), issue) 364 365 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 366 return
··· 310 issue.Open = false 311 312 // notify about the issue closure 313 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 314 315 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 316 return ··· 360 issue.Open = true 361 362 // notify about the issue reopen 363 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 364 365 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 366 return
+4 -6
appview/notify/db/db.go
··· 311 // no-op 312 } 313 314 - func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 315 // build up the recipients list: 316 // - repo owner 317 // - repo collaborators ··· 330 recipients = append(recipients, syntax.DID(p)) 331 } 332 333 - actorDid := syntax.DID(issue.Repo.Did) 334 entityType := "pull" 335 entityId := issue.AtUri().String() 336 repoId := &issue.Repo.Id ··· 345 } 346 347 n.notifyEvent( 348 - actorDid, 349 recipients, 350 eventType, 351 entityType, ··· 356 ) 357 } 358 359 - func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 360 // Get repo details 361 repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) 362 if err != nil { ··· 381 recipients = append(recipients, syntax.DID(p)) 382 } 383 384 - actorDid := syntax.DID(repo.Did) 385 entityType := "pull" 386 entityId := pull.PullAt().String() 387 repoId := &repo.Id ··· 402 pullId := &p 403 404 n.notifyEvent( 405 - actorDid, 406 recipients, 407 eventType, 408 entityType,
··· 311 // no-op 312 } 313 314 + func (n *databaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 315 // build up the recipients list: 316 // - repo owner 317 // - repo collaborators ··· 330 recipients = append(recipients, syntax.DID(p)) 331 } 332 333 entityType := "pull" 334 entityId := issue.AtUri().String() 335 repoId := &issue.Repo.Id ··· 344 } 345 346 n.notifyEvent( 347 + actor, 348 recipients, 349 eventType, 350 entityType, ··· 355 ) 356 } 357 358 + func (n *databaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 359 // Get repo details 360 repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) 361 if err != nil { ··· 380 recipients = append(recipients, syntax.DID(p)) 381 } 382 383 entityType := "pull" 384 entityId := pull.PullAt().String() 385 repoId := &repo.Id ··· 400 pullId := &p 401 402 n.notifyEvent( 403 + actor, 404 recipients, 405 eventType, 406 entityType,
+4 -4
appview/notify/merged_notifier.go
··· 62 m.fanout("NewIssueComment", ctx, comment, mentions) 63 } 64 65 - func (m *mergedNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 66 - m.fanout("NewIssueState", ctx, issue) 67 } 68 69 func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { ··· 86 m.fanout("NewPullComment", ctx, comment, mentions) 87 } 88 89 - func (m *mergedNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 90 - m.fanout("NewPullState", ctx, pull) 91 } 92 93 func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
··· 62 m.fanout("NewIssueComment", ctx, comment, mentions) 63 } 64 65 + func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 66 + m.fanout("NewIssueState", ctx, actor, issue) 67 } 68 69 func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { ··· 86 m.fanout("NewPullComment", ctx, comment, mentions) 87 } 88 89 + func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 90 + m.fanout("NewPullState", ctx, actor, pull) 91 } 92 93 func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
+4 -4
appview/notify/notifier.go
··· 15 16 NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) 17 NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) 18 - NewIssueState(ctx context.Context, issue *models.Issue) 19 DeleteIssue(ctx context.Context, issue *models.Issue) 20 21 NewFollow(ctx context.Context, follow *models.Follow) ··· 23 24 NewPull(ctx context.Context, pull *models.Pull) 25 NewPullComment(ctx context.Context, comment *models.PullComment, mentions []syntax.DID) 26 - NewPullState(ctx context.Context, pull *models.Pull) 27 28 UpdateProfile(ctx context.Context, profile *models.Profile) 29 ··· 44 45 func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {} 46 func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) {} 47 - func (m *BaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {} 48 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 49 50 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} ··· 52 53 func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 54 func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment, mentions []syntax.DID) {} 55 - func (m *BaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) {} 56 57 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} 58
··· 15 16 NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) 17 NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) 18 + NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) 19 DeleteIssue(ctx context.Context, issue *models.Issue) 20 21 NewFollow(ctx context.Context, follow *models.Follow) ··· 23 24 NewPull(ctx context.Context, pull *models.Pull) 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 ··· 44 45 func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue, mentions []syntax.DID) {} 46 func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment, mentions []syntax.DID) {} 47 + func (m *BaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) {} 48 func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 49 50 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} ··· 52 53 func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 54 func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment, mentions []syntax.DID) {} 55 + func (m *BaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) {} 56 57 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} 58
+4 -2
appview/notify/posthog/notifier.go
··· 194 } 195 } 196 197 - func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 198 var event string 199 if issue.Open { 200 event = "issue_reopen" ··· 206 Event: event, 207 Properties: posthog.Properties{ 208 "repo_at": issue.RepoAt.String(), 209 "issue_id": issue.IssueId, 210 }, 211 }) ··· 214 } 215 } 216 217 - func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 218 var event string 219 switch pull.State { 220 case models.PullClosed: ··· 233 Properties: posthog.Properties{ 234 "repo_at": pull.RepoAt, 235 "pull_id": pull.PullId, 236 }, 237 }) 238 if err != nil {
··· 194 } 195 } 196 197 + func (n *posthogNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 198 var event string 199 if issue.Open { 200 event = "issue_reopen" ··· 206 Event: event, 207 Properties: posthog.Properties{ 208 "repo_at": issue.RepoAt.String(), 209 + "actor": actor, 210 "issue_id": issue.IssueId, 211 }, 212 }) ··· 215 } 216 } 217 218 + func (n *posthogNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 219 var event string 220 switch pull.State { 221 case models.PullClosed: ··· 234 Properties: posthog.Properties{ 235 "repo_at": pull.RepoAt, 236 "pull_id": pull.PullId, 237 + "actor": actor, 238 }, 239 }) 240 if err != nil {
+4 -3
appview/pulls/pulls.go
··· 2117 } 2118 2119 func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { 2120 f, err := s.repoResolver.Resolve(r) 2121 if err != nil { 2122 log.Println("failed to resolve repo:", err) ··· 2227 2228 // notify about the pull merge 2229 for _, p := range pullsToMerge { 2230 - s.notifier.NewPullState(r.Context(), p) 2231 } 2232 2233 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) ··· 2299 } 2300 2301 for _, p := range pullsToClose { 2302 - s.notifier.NewPullState(r.Context(), p) 2303 } 2304 2305 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) ··· 2372 } 2373 2374 for _, p := range pullsToReopen { 2375 - s.notifier.NewPullState(r.Context(), p) 2376 } 2377 2378 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
··· 2117 } 2118 2119 func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { 2120 + user := s.oauth.GetUser(r) 2121 f, err := s.repoResolver.Resolve(r) 2122 if err != nil { 2123 log.Println("failed to resolve repo:", err) ··· 2228 2229 // notify about the pull merge 2230 for _, p := range pullsToMerge { 2231 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2232 } 2233 2234 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) ··· 2300 } 2301 2302 for _, p := range pullsToClose { 2303 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2304 } 2305 2306 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) ··· 2373 } 2374 2375 for _, p := range pullsToReopen { 2376 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2377 } 2378 2379 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))