Monorepo for Tangled tangled.org

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

merged opened by boltless.me targeting master from feat/mentions
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3m4ksdieshw22
+34 -28
Diff #3
+3 -2
appview/indexer/notifier.go
··· 3 import ( 4 "context" 5 6 "tangled.org/core/appview/models" 7 "tangled.org/core/appview/notify" 8 "tangled.org/core/log" ··· 19 } 20 } 21 22 - func (ix *Indexer) NewIssueState(ctx context.Context, issue *models.Issue) { 23 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 24 l.Debug("updating an issue") 25 err := ix.Issues.Index(ctx, *issue) ··· 46 } 47 } 48 49 - func (ix *Indexer) NewPullState(ctx context.Context, pull *models.Pull) { 50 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 51 l.Debug("updating a pr") 52 err := ix.Pulls.Index(ctx, pull)
··· 3 import ( 4 "context" 5 6 + "github.com/bluesky-social/indigo/atproto/syntax" 7 "tangled.org/core/appview/models" 8 "tangled.org/core/appview/notify" 9 "tangled.org/core/log" ··· 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
··· 309 issue.Open = false 310 311 // notify about the issue closure 312 - rp.notifier.NewIssueState(r.Context(), issue) 313 314 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 315 return ··· 359 issue.Open = true 360 361 // notify about the issue reopen 362 - rp.notifier.NewIssueState(r.Context(), issue) 363 364 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 365 return
··· 309 issue.Open = false 310 311 // notify about the issue closure 312 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 313 314 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 315 return ··· 359 issue.Open = true 360 361 // notify about the issue reopen 362 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 363 364 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 365 return
+4 -6
appview/notify/db/db.go
··· 283 // no-op 284 } 285 286 - func (n *databaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 287 // build up the recipients list: 288 // - repo owner 289 // - repo collaborators ··· 302 recipients = append(recipients, syntax.DID(p)) 303 } 304 305 - actorDid := syntax.DID(issue.Repo.Did) 306 entityType := "pull" 307 entityId := issue.AtUri().String() 308 repoId := &issue.Repo.Id ··· 317 } 318 319 n.notifyEvent( 320 - actorDid, 321 recipients, 322 eventType, 323 entityType, ··· 328 ) 329 } 330 331 - func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 332 // Get repo details 333 repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) 334 if err != nil { ··· 353 recipients = append(recipients, syntax.DID(p)) 354 } 355 356 - actorDid := syntax.DID(repo.Did) 357 entityType := "pull" 358 entityId := pull.PullAt().String() 359 repoId := &repo.Id ··· 374 pullId := &p 375 376 n.notifyEvent( 377 - actorDid, 378 recipients, 379 eventType, 380 entityType,
··· 283 // no-op 284 } 285 286 + func (n *databaseNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 287 // build up the recipients list: 288 // - repo owner 289 // - repo collaborators ··· 302 recipients = append(recipients, syntax.DID(p)) 303 } 304 305 entityType := "pull" 306 entityId := issue.AtUri().String() 307 repoId := &issue.Repo.Id ··· 316 } 317 318 n.notifyEvent( 319 + actor, 320 recipients, 321 eventType, 322 entityType, ··· 327 ) 328 } 329 330 + func (n *databaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 331 // Get repo details 332 repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) 333 if err != nil { ··· 352 recipients = append(recipients, syntax.DID(p)) 353 } 354 355 entityType := "pull" 356 entityId := pull.PullAt().String() 357 repoId := &repo.Id ··· 372 pullId := &p 373 374 n.notifyEvent( 375 + actor, 376 recipients, 377 eventType, 378 entityType,
+5 -4
appview/notify/merged_notifier.go
··· 6 "reflect" 7 "sync" 8 9 "tangled.org/core/appview/models" 10 "tangled.org/core/log" 11 ) ··· 61 m.fanout("NewIssueComment", ctx, comment) 62 } 63 64 - func (m *mergedNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 65 - m.fanout("NewIssueState", ctx, issue) 66 } 67 68 func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { ··· 85 m.fanout("NewPullComment", ctx, comment) 86 } 87 88 - func (m *mergedNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 89 - m.fanout("NewPullState", ctx, pull) 90 } 91 92 func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {
··· 6 "reflect" 7 "sync" 8 9 + "github.com/bluesky-social/indigo/atproto/syntax" 10 "tangled.org/core/appview/models" 11 "tangled.org/core/log" 12 ) ··· 62 m.fanout("NewIssueComment", ctx, comment) 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) 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) {
+10 -9
appview/notify/notifier.go
··· 3 import ( 4 "context" 5 6 "tangled.org/core/appview/models" 7 ) 8 ··· 14 15 NewIssue(ctx context.Context, issue *models.Issue) 16 NewIssueComment(ctx context.Context, comment *models.IssueComment) 17 - NewIssueState(ctx context.Context, issue *models.Issue) 18 DeleteIssue(ctx context.Context, issue *models.Issue) 19 20 NewFollow(ctx context.Context, follow *models.Follow) ··· 22 23 NewPull(ctx context.Context, pull *models.Pull) 24 NewPullComment(ctx context.Context, comment *models.PullComment) 25 - NewPullState(ctx context.Context, pull *models.Pull) 26 27 UpdateProfile(ctx context.Context, profile *models.Profile) 28 ··· 41 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 42 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 43 44 - func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 45 - func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} 46 - func (m *BaseNotifier) NewIssueState(ctx context.Context, issue *models.Issue) {} 47 - func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 48 49 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 50 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} 51 52 - func (m *BaseNotifier) NewPull(ctx context.Context, pull *models.Pull) {} 53 - func (m *BaseNotifier) NewPullComment(ctx context.Context, models *models.PullComment) {} 54 - func (m *BaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) {} 55 56 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} 57
··· 3 import ( 4 "context" 5 6 + "github.com/bluesky-social/indigo/atproto/syntax" 7 "tangled.org/core/appview/models" 8 ) 9 ··· 15 16 NewIssue(ctx context.Context, issue *models.Issue) 17 NewIssueComment(ctx context.Context, comment *models.IssueComment) 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) 26 + NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 28 UpdateProfile(ctx context.Context, profile *models.Profile) 29 ··· 42 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 43 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 44 45 + func (m *BaseNotifier) NewIssue(ctx context.Context, issue *models.Issue) {} 46 + func (m *BaseNotifier) NewIssueComment(ctx context.Context, comment *models.IssueComment) {} 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) {} 51 func (m *BaseNotifier) DeleteFollow(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) {} 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
+5 -2
appview/notify/posthog/notifier.go
··· 4 "context" 5 "log" 6 7 "github.com/posthog/posthog-go" 8 "tangled.org/core/appview/models" 9 "tangled.org/core/appview/notify" ··· 190 } 191 } 192 193 - func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 194 var event string 195 if issue.Open { 196 event = "issue_reopen" ··· 202 Event: event, 203 Properties: posthog.Properties{ 204 "repo_at": issue.RepoAt.String(), 205 "issue_id": issue.IssueId, 206 }, 207 }) ··· 210 } 211 } 212 213 - func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 214 var event string 215 switch pull.State { 216 case models.PullClosed: ··· 229 Properties: posthog.Properties{ 230 "repo_at": pull.RepoAt, 231 "pull_id": pull.PullId, 232 }, 233 }) 234 if err != nil {
··· 4 "context" 5 "log" 6 7 + "github.com/bluesky-social/indigo/atproto/syntax" 8 "github.com/posthog/posthog-go" 9 "tangled.org/core/appview/models" 10 "tangled.org/core/appview/notify" ··· 191 } 192 } 193 194 + func (n *posthogNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 195 var event string 196 if issue.Open { 197 event = "issue_reopen" ··· 203 Event: event, 204 Properties: posthog.Properties{ 205 "repo_at": issue.RepoAt.String(), 206 + "actor": actor, 207 "issue_id": issue.IssueId, 208 }, 209 }) ··· 212 } 213 } 214 215 + func (n *posthogNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 216 var event string 217 switch pull.State { 218 case models.PullClosed: ··· 231 Properties: posthog.Properties{ 232 "repo_at": pull.RepoAt, 233 "pull_id": pull.PullId, 234 + "actor": actor, 235 }, 236 }) 237 if err != nil {
+5 -3
appview/pulls/pulls.go
··· 33 "tangled.org/core/types" 34 35 comatproto "github.com/bluesky-social/indigo/api/atproto" 36 lexutil "github.com/bluesky-social/indigo/lex/util" 37 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 38 "github.com/go-chi/chi/v5" ··· 2106 } 2107 2108 func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { 2109 f, err := s.repoResolver.Resolve(r) 2110 if err != nil { 2111 log.Println("failed to resolve repo:", err) ··· 2216 2217 // notify about the pull merge 2218 for _, p := range pullsToMerge { 2219 - s.notifier.NewPullState(r.Context(), p) 2220 } 2221 2222 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) ··· 2288 } 2289 2290 for _, p := range pullsToClose { 2291 - s.notifier.NewPullState(r.Context(), p) 2292 } 2293 2294 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) ··· 2361 } 2362 2363 for _, p := range pullsToReopen { 2364 - s.notifier.NewPullState(r.Context(), p) 2365 } 2366 2367 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))
··· 33 "tangled.org/core/types" 34 35 comatproto "github.com/bluesky-social/indigo/api/atproto" 36 + "github.com/bluesky-social/indigo/atproto/syntax" 37 lexutil "github.com/bluesky-social/indigo/lex/util" 38 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 39 "github.com/go-chi/chi/v5" ··· 2107 } 2108 2109 func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { 2110 + user := s.oauth.GetUser(r) 2111 f, err := s.repoResolver.Resolve(r) 2112 if err != nil { 2113 log.Println("failed to resolve repo:", err) ··· 2218 2219 // notify about the pull merge 2220 for _, p := range pullsToMerge { 2221 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2222 } 2223 2224 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) ··· 2290 } 2291 2292 for _, p := range pullsToClose { 2293 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2294 } 2295 2296 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) ··· 2363 } 2364 2365 for _, p := range pullsToReopen { 2366 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2367 } 2368 2369 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))

History

5 rounds 1 comment
sign up or login to add to the discussion
1 commit
expand
appview/notify: use correct actor on issue/pr state change events
3/3 success
expand
expand 0 comments
pull request successfully merged
1 commit
expand
appview/notify: use correct actor on issue/pr state change events
3/3 success
expand
expand 0 comments
1 commit
expand
appview/notify: use correct actor on issue/pr state change events
1/3 failed, 1/3 timeout, 1/3 success
expand
expand 0 comments
1 commit
expand
appview/notify: use correct actor on issue/pr state change events
1/3 failed, 2/3 timeout
expand
expand 0 comments
1 commit
expand
appview/notify: use correct actor on issue/pr state change events
1/3 failed, 2/3 timeout
expand
expand 1 comment

this is valuable as an interim fix! as you know, we are looking to atprotate issue state and PR state changes.

can you move this off of this stack? can be opened as a standalone PR.