Skip to content

Commit 8f94953

Browse files
committed
Record events when updating a branch
1 parent 4d92f09 commit 8f94953

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/Share/Notifications/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ instance PG.EncodeValue NotificationFilter where
118118
data ProjectBranchData = ProjectBranchData
119119
{ projectId :: ProjectId,
120120
branchId :: BranchId,
121-
branchContributorUserId :: UserId
121+
branchContributorUserId :: Maybe UserId
122122
}
123123

124124
instance Aeson.ToJSON ProjectBranchData where

src/Share/Postgres/Queries.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import Share.Branch
1717
import Share.Contribution
1818
import Share.IDs
1919
import Share.IDs qualified as IDs
20+
import Share.Notifications.Queries qualified as NotifQ
21+
import Share.Notifications.Types (NotificationEvent (..), NotificationEventData (..), ProjectBranchData (..))
2022
import Share.OAuth.Types
2123
import Share.Postgres (unrecoverableError)
2224
import Share.Postgres qualified as PG
@@ -633,6 +635,7 @@ setBranchCausalHash ::
633635
setBranchCausalHash !_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

663690
getCausalIdForBranch :: BranchId -> PG.Transaction e CausalId
664691
getCausalIdForBranch branchId = do

0 commit comments

Comments
 (0)