Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

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

authored by

Seongmin Lee and committed by
Tangled
35ada393 a79983a4

+34 -28
+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" ··· 20 19 } 21 20 } 22 21 23 - func (ix *Indexer) NewIssueState(ctx context.Context, issue *models.Issue) { 22 + func (ix *Indexer) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 24 23 l := log.FromContext(ctx).With("notifier", "indexer", "issue", issue) 25 24 l.Debug("updating an issue") 26 25 err := ix.Issues.Index(ctx, *issue) ··· 47 46 } 48 47 } 49 48 50 - func (ix *Indexer) NewPullState(ctx context.Context, pull *models.Pull) { 49 + func (ix *Indexer) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 51 50 l := log.FromContext(ctx).With("notifier", "indexer", "pull", pull) 52 51 l.Debug("updating a pr") 53 52 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 ··· 316 317 } 317 318 318 319 n.notifyEvent( 319 - actorDid, 320 + actor, 320 321 recipients, 321 322 eventType, 322 323 entityType, ··· 327 328 ) 328 329 } 329 330 330 - func (n *databaseNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 331 + func (n *databaseNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 331 332 // Get repo details 332 333 repo, err := db.GetRepo(n.db, db.FilterEq("at_uri", string(pull.RepoAt))) 333 334 if err != nil { ··· 352 353 recipients = append(recipients, syntax.DID(p)) 353 354 } 354 355 355 - actorDid := syntax.DID(repo.Did) 356 356 entityType := "pull" 357 357 entityId := pull.PullAt().String() 358 358 repoId := &repo.Id ··· 372 374 pullId := &p 373 375 374 376 n.notifyEvent( 375 - actorDid, 377 + actor, 376 378 recipients, 377 379 eventType, 378 380 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 ) ··· 62 61 m.fanout("NewIssueComment", ctx, comment) 63 62 } 64 63 65 - func (m *mergedNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 66 - m.fanout("NewIssueState", ctx, issue) 64 + func (m *mergedNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 65 + m.fanout("NewIssueState", ctx, actor, issue) 67 66 } 68 67 69 68 func (m *mergedNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) { ··· 86 85 m.fanout("NewPullComment", ctx, comment) 87 86 } 88 87 89 - func (m *mergedNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 90 - m.fanout("NewPullState", ctx, pull) 88 + func (m *mergedNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 89 + m.fanout("NewPullState", ctx, actor, pull) 91 90 } 92 91 93 92 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 ··· 15 14 16 15 NewIssue(ctx context.Context, issue *models.Issue) 17 16 NewIssueComment(ctx context.Context, comment *models.IssueComment) 18 - NewIssueState(ctx context.Context, issue *models.Issue) 17 + NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) 19 18 DeleteIssue(ctx context.Context, issue *models.Issue) 20 19 21 20 NewFollow(ctx context.Context, follow *models.Follow) ··· 23 22 24 23 NewPull(ctx context.Context, pull *models.Pull) 25 24 NewPullComment(ctx context.Context, comment *models.PullComment) 26 - NewPullState(ctx context.Context, pull *models.Pull) 25 + NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) 27 26 28 27 UpdateProfile(ctx context.Context, profile *models.Profile) 29 28 ··· 42 41 func (m *BaseNotifier) NewStar(ctx context.Context, star *models.Star) {} 43 42 func (m *BaseNotifier) DeleteStar(ctx context.Context, star *models.Star) {} 44 43 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, issue *models.Issue) {} 48 - func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 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, actor syntax.DID, issue *models.Issue) {} 47 + func (m *BaseNotifier) DeleteIssue(ctx context.Context, issue *models.Issue) {} 49 48 50 49 func (m *BaseNotifier) NewFollow(ctx context.Context, follow *models.Follow) {} 51 50 func (m *BaseNotifier) DeleteFollow(ctx context.Context, follow *models.Follow) {} 52 51 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, pull *models.Pull) {} 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, actor syntax.DID, pull *models.Pull) {} 56 55 57 56 func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *models.Profile) {} 58 57
+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" ··· 191 190 } 192 191 } 193 192 194 - func (n *posthogNotifier) NewIssueState(ctx context.Context, issue *models.Issue) { 193 + func (n *posthogNotifier) NewIssueState(ctx context.Context, actor syntax.DID, issue *models.Issue) { 195 194 var event string 196 195 if issue.Open { 197 196 event = "issue_reopen" ··· 203 202 Event: event, 204 203 Properties: posthog.Properties{ 205 204 "repo_at": issue.RepoAt.String(), 205 + "actor": actor, 206 206 "issue_id": issue.IssueId, 207 207 }, 208 208 }) ··· 212 210 } 213 211 } 214 212 215 - func (n *posthogNotifier) NewPullState(ctx context.Context, pull *models.Pull) { 213 + func (n *posthogNotifier) NewPullState(ctx context.Context, actor syntax.DID, pull *models.Pull) { 216 214 var event string 217 215 switch pull.State { 218 216 case models.PullClosed: ··· 231 229 Properties: posthog.Properties{ 232 230 "repo_at": pull.RepoAt, 233 231 "pull_id": pull.PullId, 232 + "actor": actor, 234 233 }, 235 234 }) 236 235 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" ··· 2107 2106 } 2108 2107 2109 2108 func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { 2109 + user := s.oauth.GetUser(r) 2110 2110 f, err := s.repoResolver.Resolve(r) 2111 2111 if err != nil { 2112 2112 log.Println("failed to resolve repo:", err) ··· 2218 2216 2219 2217 // notify about the pull merge 2220 2218 for _, p := range pullsToMerge { 2221 - s.notifier.NewPullState(r.Context(), p) 2219 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2222 2220 } 2223 2221 2224 2222 s.pages.HxLocation(w, fmt.Sprintf("/@%s/%s/pulls/%d", f.OwnerHandle(), f.Name, pull.PullId)) ··· 2290 2288 } 2291 2289 2292 2290 for _, p := range pullsToClose { 2293 - s.notifier.NewPullState(r.Context(), p) 2291 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2294 2292 } 2295 2293 2296 2294 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId)) ··· 2363 2361 } 2364 2362 2365 2363 for _, p := range pullsToReopen { 2366 - s.notifier.NewPullState(r.Context(), p) 2364 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2367 2365 } 2368 2366 2369 2367 s.pages.HxLocation(w, fmt.Sprintf("/%s/pulls/%d", f.OwnerSlashRepo(), pull.PullId))