@@ -17,6 +17,8 @@ import Share.Branch
1717import Share.Contribution
1818import Share.IDs
1919import Share.IDs qualified as IDs
20+ import Share.Notifications.Queries qualified as NotifQ
21+ import Share.Notifications.Types (NotificationEvent (.. ), NotificationEventData (.. ), ProjectBranchData (.. ))
2022import Share.OAuth.Types
2123import Share.Postgres (unrecoverableError )
2224import Share.Postgres qualified as PG
@@ -633,6 +635,7 @@ setBranchCausalHash ::
633635setBranchCausalHash ! _nameLookupReceipt description callerUserId branchId causalId = do
634636 PG. execute_ updateReflogSQL
635637 PG. execute_ setBranchSQL
638+ recordNotificationEvent
636639 where
637640 setBranchSQL =
638641 [PG. sql |
@@ -659,6 +662,30 @@ setBranchCausalHash !_nameLookupReceipt description callerUserId branchId causal
659662 FROM project_branches
660663 WHERE id = #{branchId}
661664 |]
665+ recordNotificationEvent = do
666+ (projectId, projectResourceId, projectOwnerUserId, branchContributorUserId) <-
667+ PG. queryExpect1Row
668+ [PG. sql |
669+ SELECT p.id, p.resource_id, p.owner_user_id, pb.contributor_id
670+ FROM project_branches pb
671+ JOIN projects p ON p.id = pb.project_id
672+ WHERE pb.id = #{branchId}
673+ |]
674+ let branchUpdateEventData =
675+ ProjectBranchData
676+ { projectId,
677+ branchId,
678+ branchContributorUserId
679+ }
680+ let notifEvent =
681+ NotificationEvent
682+ { eventId = () ,
683+ eventOccurredAt = () ,
684+ eventResourceId = projectResourceId,
685+ eventData = ProjectBranchUpdatedData branchUpdateEventData,
686+ eventScope = projectOwnerUserId
687+ }
688+ NotifQ. recordEvent notifEvent
662689
663690getCausalIdForBranch :: BranchId -> PG. Transaction e CausalId
664691getCausalIdForBranch branchId = do
0 commit comments