@@ -17,10 +17,12 @@ module GithubApi
1717(
1818 GithubOperation (.. ),
1919 PullRequest (.. ),
20+ ReactionContent (.. ),
2021 getOpenPullRequests,
2122 getPullRequest,
2223 hasPushAccess,
2324 leaveComment,
25+ addReaction,
2426 runGithub,
2527 runGithubReadOnly,
2628)
@@ -32,13 +34,16 @@ import Effectful (Dispatch (Dynamic), DispatchOf, Eff, Effect, IOE, (:>))
3234import Effectful.Dispatch.Dynamic (interpret , send , interpose )
3335import Data.IntSet (IntSet )
3436import Data.Text (Text )
37+ import GitHub.Data.Reactions (ReactionContent (.. ))
3538
3639import qualified Data.IntSet as IntSet
3740import qualified Data.Vector as Vector
41+ import qualified GitHub.Data.Id as Github3
3842import qualified GitHub.Data.Name as Github3
3943import qualified GitHub.Data.Options as Github3
4044import qualified GitHub.Endpoints.Issues.Comments as Github3
4145import qualified GitHub.Endpoints.PullRequests as Github3
46+ import qualified GitHub.Endpoints.Reactions as Github3
4247import qualified GitHub.Endpoints.Repos.Collaborators as Github3
4348import qualified GitHub.Request as Github3
4449import qualified Network.HTTP.Client as Http
@@ -48,7 +53,7 @@ import Format (format)
4853import Git (BaseBranch (.. ), Branch (.. ), Sha (.. ))
4954import MonadLoggerEffect (MonadLoggerEffect )
5055import Project (ProjectInfo )
51- import Types (PullRequestId (.. ), Username (.. ))
56+ import Types (PullRequestId (.. ), Username (.. ), CommentId ( .. ), ReactableId ( .. ) )
5257
5358import qualified Project
5459
@@ -64,6 +69,7 @@ data PullRequest = PullRequest
6469
6570data GithubOperation :: Effect where
6671 LeaveComment :: PullRequestId -> Text -> GithubOperation m ()
72+ AddReaction :: ReactableId -> ReactionContent -> GithubOperation m ()
6773 HasPushAccess :: Username -> GithubOperation m Bool
6874 GetPullRequest :: PullRequestId -> GithubOperation m (Maybe PullRequest )
6975 GetOpenPullRequests :: GithubOperation m (Maybe IntSet )
@@ -73,6 +79,9 @@ type instance DispatchOf GithubOperation = 'Dynamic
7379leaveComment :: GithubOperation :> es => PullRequestId -> Text -> Eff es ()
7480leaveComment pr remoteBranch = send $ LeaveComment pr remoteBranch
7581
82+ addReaction :: GithubOperation :> es => ReactableId -> ReactionContent -> Eff es ()
83+ addReaction id' reaction = send $ AddReaction id' reaction
84+
7685hasPushAccess :: GithubOperation :> es => Username -> Eff es Bool
7786hasPushAccess username = send $ HasPushAccess username
7887
@@ -119,6 +128,26 @@ runGithub auth projectInfo =
119128 Right _ -> logInfoN $ format " Posted comment on {}#{}: {}"
120129 (Project. repository projectInfo, pr, body)
121130
131+ AddReaction reactableId reaction -> do
132+ let
133+ createReactionR project owner =
134+ case reactableId of
135+ OnIssueComment (CommentId commentId) -> Github3. createCommentReactionR project owner (Github3. Id commentId)
136+ OnPullRequest (PullRequestId prId) -> Github3. createIssueReactionR project owner (Github3. Id prId)
137+
138+ result <- liftIO $ Github3. github auth $ createReactionR
139+ (Github3. N $ Project. owner projectInfo)
140+ (Github3. N $ Project. repository projectInfo)
141+ reaction
142+
143+ case result of
144+ Left err -> logWarnN $ format " Failed to add reaction: {}" [show err]
145+ Right _ ->
146+ logInfoN $
147+ format
148+ " Added reaction in {} on {}: {}"
149+ (Project. repository projectInfo, reactableId, show reaction)
150+
122151 HasPushAccess (Username username) -> do
123152 result <- liftIO $ Github3. github auth $ Github3. collaboratorPermissionOnR
124153 (Github3. N $ Project. owner projectInfo)
@@ -196,3 +225,5 @@ runGithubReadOnly auth projectInfo = runGithub auth projectInfo . augmentedGithu
196225 -- These operations have side effects, we fake them.
197226 LeaveComment pr body ->
198227 logInfoN $ format " Would have posted comment on {}: {}" (show pr, body)
228+ AddReaction reactableId reaction ->
229+ logInfoN $ format " Would have added reaction on {}: {}" (reactableId, show reaction)
0 commit comments