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