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