diff --git a/nix/haskell-overlay.nix b/nix/haskell-overlay.nix index 80005215..ada72f82 100644 --- a/nix/haskell-overlay.nix +++ b/nix/haskell-overlay.nix @@ -1,4 +1,16 @@ { sources ? import ./sources.nix, pkgs }: self: super: { hoff = self.callPackage ../hoff.nix { }; + + github = + pkgs.haskell.lib.compose.appendPatches + [ + # https://github.com/haskell-github/github/pull/509 + (pkgs.fetchpatch { + name = "github.patch"; + url = "https://github.com/haskell-github/github/commit/623105d3987c4bb4e67d48e5ae36a3af97480be9.patch"; + sha256 = "sha256-3zRYnrxg9G+druD8o5iejCnTclxd2eg1V7BAO6USjzo="; + }) + ] + super.github; } diff --git a/src/EventLoop.hs b/src/EventLoop.hs index e7ad22cd..b03a4033 100644 --- a/src/EventLoop.hs +++ b/src/EventLoop.hs @@ -71,7 +71,7 @@ eventFromCommentPayload payload = let number = PullRequestId payload.number author = payload.author -- TODO: Wrapper type body = payload.body - commentAdded = Logic.CommentAdded number author body + commentAdded = Logic.CommentAdded number author payload.id body in case payload.action of Left Github.CommentCreated -> Just commentAdded Right Github.ReviewSubmitted -> Just commentAdded diff --git a/src/Github.hs b/src/Github.hs index 31ee9832..be071b74 100644 --- a/src/Github.hs +++ b/src/Github.hs @@ -37,7 +37,7 @@ import GHC.Natural (Natural) import Git (Sha (..), Branch (..), BaseBranch (..), Context) import Project (ProjectInfo (..)) -import Types (Body, Username) +import Types (Body, Username, CommentId (..)) import Data.Maybe (fromMaybe) data PullRequestAction @@ -82,11 +82,15 @@ data PullRequestPayload = PullRequestPayload { data CommentPayload = CommentPayload { action :: Either CommentAction ReviewAction, -- Corresponds to "action". - owner :: Text, -- Corresponds to "repository.owner.login". - repository :: Text, -- Corresponds to "repository.name". - number :: Int, -- Corresponds to "issue.number" or "pull_request.number". - author :: Username, -- Corresponds to "sender.login". - body :: Text -- Corresponds to "comment.body" or "review.body". + owner :: Text, -- Corresponds to "repository.owner.login". + repository :: Text, -- Corresponds to "repository.name". + number :: Int, -- Corresponds to "issue.number" or "pull_request.number". + author :: Username, -- Corresponds to "sender.login". + id :: Maybe CommentId, -- Corresponds to "comment.id". + -- Can be absent if we actually received a review, + -- because those have separate IDs from ordinary issue + -- comments. + body :: Text -- Corresponds to "comment.body" or "review.body". } deriving (Eq, Show) data CommitStatusPayload = CommitStatusPayload { @@ -169,6 +173,10 @@ instance FromJSON CommentPayload where <*> (getNested v ["issue", "number"] <|> getNested v ["pull_request", "number"]) <*> getNested v ["sender", "login"] + <*> (getNested v ["comment", "id"] + -- If we couldn't get a comment ID, we likely got a review, which does have an ID, + -- but we can't treat that as a comment ID for API requests. + <|> pure Nothing) <*> (getNested v ["comment", "body"] <|> fromMaybe "" <$> getNested v ["review", "body"]) parseJSON nonObject = typeMismatch "(issue_comment | pull_request_review) payload" nonObject diff --git a/src/GithubApi.hs b/src/GithubApi.hs index 9503481b..9ef59305 100644 --- a/src/GithubApi.hs +++ b/src/GithubApi.hs @@ -17,10 +17,12 @@ module GithubApi ( GithubOperation (..), PullRequest (..), + ReactionContent(..), getOpenPullRequests, getPullRequest, hasPushAccess, leaveComment, + addReaction, runGithub, runGithubReadOnly, ) @@ -32,13 +34,16 @@ import Effectful (Dispatch (Dynamic), DispatchOf, Eff, Effect, IOE, (:>)) import Effectful.Dispatch.Dynamic (interpret, send, interpose) import Data.IntSet (IntSet) import Data.Text (Text) +import GitHub.Data.Reactions (ReactionContent(..)) import qualified Data.IntSet as IntSet import qualified Data.Vector as Vector +import qualified GitHub.Data.Id as Github3 import qualified GitHub.Data.Name as Github3 import qualified GitHub.Data.Options as Github3 import qualified GitHub.Endpoints.Issues.Comments as Github3 import qualified GitHub.Endpoints.PullRequests as Github3 +import qualified GitHub.Endpoints.Reactions as Github3 import qualified GitHub.Endpoints.Repos.Collaborators as Github3 import qualified GitHub.Request as Github3 import qualified Network.HTTP.Client as Http @@ -48,7 +53,7 @@ import Format (format) import Git (BaseBranch (..), Branch (..), Sha (..)) import MonadLoggerEffect (MonadLoggerEffect) import Project (ProjectInfo) -import Types (PullRequestId (..), Username (..)) +import Types (PullRequestId (..), Username (..), CommentId (..), ReactableId (..)) import qualified Project @@ -64,6 +69,7 @@ data PullRequest = PullRequest data GithubOperation :: Effect where LeaveComment :: PullRequestId -> Text -> GithubOperation m () + AddReaction :: ReactableId -> ReactionContent -> GithubOperation m () HasPushAccess :: Username -> GithubOperation m Bool GetPullRequest :: PullRequestId -> GithubOperation m (Maybe PullRequest) GetOpenPullRequests :: GithubOperation m (Maybe IntSet) @@ -73,6 +79,9 @@ type instance DispatchOf GithubOperation = 'Dynamic leaveComment :: GithubOperation :> es => PullRequestId -> Text -> Eff es () leaveComment pr remoteBranch = send $ LeaveComment pr remoteBranch +addReaction :: GithubOperation :> es => ReactableId -> ReactionContent -> Eff es () +addReaction id' reaction = send $ AddReaction id' reaction + hasPushAccess :: GithubOperation :> es => Username -> Eff es Bool hasPushAccess username = send $ HasPushAccess username @@ -119,6 +128,26 @@ runGithub auth projectInfo = Right _ -> logInfoN $ format "Posted comment on {}#{}: {}" (Project.repository projectInfo, pr, body) + AddReaction reactableId reaction -> do + let + createReactionR project owner = + case reactableId of + OnIssueComment (CommentId commentId) -> Github3.createCommentReactionR project owner (Github3.Id commentId) + OnPullRequest (PullRequestId prId) -> Github3.createIssueReactionR project owner (Github3.Id prId) + + result <- liftIO $ Github3.github auth $ createReactionR + (Github3.N $ Project.owner projectInfo) + (Github3.N $ Project.repository projectInfo) + reaction + + case result of + Left err -> logWarnN $ format "Failed to add reaction: {}" [show err] + Right _ -> + logInfoN $ + format + "Added reaction in {} on {}: {}" + (Project.repository projectInfo, reactableId, show reaction) + HasPushAccess (Username username) -> do result <- liftIO $ Github3.github auth $ Github3.collaboratorPermissionOnR (Github3.N $ Project.owner projectInfo) @@ -196,3 +225,5 @@ runGithubReadOnly auth projectInfo = runGithub auth projectInfo . augmentedGithu -- These operations have side effects, we fake them. LeaveComment pr body -> logInfoN $ format "Would have posted comment on {}: {}" (show pr, body) + AddReaction reactableId reaction -> + logInfoN $ format "Would have added reaction on {}: {}" (reactableId, show reaction) diff --git a/src/Logic.hs b/src/Logic.hs index a947e381..25ae1338 100644 --- a/src/Logic.hs +++ b/src/Logic.hs @@ -79,7 +79,7 @@ import Project (Approval (..), ApprovedFor (..), MergeCommand (..), BuildStatus MergeWindow(..), Priority (..), ProjectState, PullRequest, PullRequestStatus (..), summarize, supersedes) import Time (TimeOperation) -import Types (Body (..), PullRequestId (..), Username (..)) +import Types (Body (..), PullRequestId (..), Username (..), CommentId, ReactableId (..)) import qualified Configuration as Config import qualified Git @@ -101,6 +101,7 @@ data Action :: Effect where TryPromoteWithTag :: Sha -> TagName -> TagMessage -> Action m PushWithTagResult CleanupTestBranch :: PullRequestId -> Action m () LeaveComment :: PullRequestId -> Text -> Action m () + AddReaction :: ReactableId -> GithubApi.ReactionContent -> Action m () IsReviewer :: Username -> Action m Bool GetPullRequest :: PullRequestId -> Action m (Maybe GithubApi.PullRequest) GetOpenPullRequests :: Action m (Maybe IntSet) @@ -166,6 +167,10 @@ cleanupTestBranch pullRequestId = send $ CleanupTestBranch pullRequestId leaveComment :: Action :> es => PullRequestId -> Text -> Eff es () leaveComment pr body = send $ LeaveComment pr body +-- | Add a reaction to the given reactable (e.g. comment, pull request). +addReaction :: Action :> es => ReactableId -> GithubApi.ReactionContent -> Eff es () +addReaction reactable reaction = send $ AddReaction reactable reaction + -- | Check if this user is allowed to issue merge commands. isReviewer :: Action :> es => Username -> Eff es Bool isReviewer username = send $ IsReviewer username @@ -253,6 +258,9 @@ runAction config = LeaveComment pr body -> do GithubApi.leaveComment pr body + AddReaction reactable reaction -> do + GithubApi.addReaction reactable reaction + IsReviewer username -> do GithubApi.hasPushAccess username @@ -312,7 +320,7 @@ data Event | PullRequestCommitChanged PullRequestId Sha -- ^ PR, new sha. | PullRequestClosed PullRequestId -- ^ PR. | PullRequestEdited PullRequestId Text BaseBranch -- ^ PR, new title, new base branch. - | CommentAdded PullRequestId Username Text -- ^ PR, author and body. + | CommentAdded PullRequestId Username (Maybe CommentId) Text -- ^ PR, author, comment ID, and body. | PushPerformed BaseBranch Sha -- ^ branch, sha -- CI events | BuildStatusChanged Sha Context BuildStatus @@ -385,8 +393,8 @@ handleEventInternal triggerConfig mergeWindowExemption featureFreezeWindow timeo PullRequestCommitChanged pr sha -> handlePullRequestCommitChanged pr sha PullRequestClosed pr -> handlePullRequestClosedByUser pr PullRequestEdited pr title baseBranch -> handlePullRequestEdited pr title baseBranch - CommentAdded pr author body - -> handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow pr author body + CommentAdded pr author commentId body + -> handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow pr author (OnIssueComment <$> commentId) body BuildStatusChanged sha context status -> handleBuildStatusChanged sha context status PushPerformed branch sha -> handleTargetChanged branch sha Synchronize -> synchronizeState @@ -409,7 +417,8 @@ handlePullRequestOpenedByUser handlePullRequestOpenedByUser triggerConfig mergeWindowExemption featureFreezeWindow pr branch baseBranch sha title author body state = do state' <- handlePullRequestOpened pr branch baseBranch sha title author state case body of - Just (Body b) -> handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow pr author b state' + Just (Body b) -> + handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow pr author (Just $ OnPullRequest pr) b state' Nothing -> pure state' handlePullRequestOpened @@ -603,10 +612,11 @@ handleCommentAdded -> Maybe FeatureFreezeWindow -> PullRequestId -> Username + -> Maybe ReactableId -> Text -> ProjectState -> Eff es ProjectState -handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow prId author body state +handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow prId author source body state -- Parser error messages contain an excerpt from the original's comment. To -- avoid feedback loops, Hoff will insert a special comment into its own -- comments with parser error messages that can be checked for here. @@ -704,8 +714,8 @@ handleCommentAdded triggerConfig mergeWindowExemption featureFreezeWindow prId a Success (command, mergeWindow, priority) -- Author is a reviewer | isAllowed -> verifyMergeWindow command mergeWindow $ case command of - Approve approval -> handleMergeRequested projectConfig prId author state pr approval priority Nothing - Retry -> handleMergeRetry projectConfig prId author priority state pr + Approve approval -> handleMergeRequested projectConfig prId author source state pr approval priority Nothing + Retry -> handleMergeRetry projectConfig prId author source priority state pr -- Author is not a reviewer, so we ignore | otherwise -> pure state -- If the pull request is not in the state, ignore the comment. @@ -715,15 +725,16 @@ doMerge :: ProjectConfiguration -> PullRequestId -> Username + -> Maybe ReactableId -> ProjectState -> PullRequest -> ApprovedFor -> Priority -> Maybe Username -> Eff es ProjectState -doMerge projectConfig prId author state pr approvalType priority retriedBy = do +doMerge projectConfig prId author source state pr approvalType priority retriedBy = do let (order, state') = Pr.newApprovalOrder state - state'' <- approvePullRequest prId (Approval author approvalType order retriedBy priority) state' + state'' <- approvePullRequest prId (Approval author source approvalType order retriedBy priority) state' -- Check whether the integration branch is valid, if not, mark the integration as invalid. if Pr.baseBranch pr /= BaseBranch (Config.branch projectConfig) then pure $ Pr.setIntegrationStatus prId IncorrectBaseBranch state'' @@ -760,18 +771,19 @@ handleMergeRequested => ProjectConfiguration -> PullRequestId -> Username + -> Maybe ReactableId -> ProjectState -> PullRequest -> ApprovedFor -> Priority -> Maybe Username -> Eff es ProjectState -handleMergeRequested projectConfig prId author state pr approvedFor priority retriedBy +handleMergeRequested projectConfig prId author source state pr approvedFor priority retriedBy = case Pr.integrationStatus pr of - NotIntegrated -> doMerge projectConfig prId author state pr approvedFor priority retriedBy + NotIntegrated -> doMerge projectConfig prId author source state pr approvedFor priority retriedBy Integrated _ checks | not (Pr.isFinalStatus (summarize checks)) -> do state' <- clearPullRequest prId pr state - doMerge projectConfig prId author state' pr approvedFor priority retriedBy + doMerge projectConfig prId author source state' pr approvedFor priority retriedBy Conflicted _ _ -> leaveComment prId "Conflict encountered while integrating, refusing..." >> pure state IncorrectBaseBranch -> do @@ -788,11 +800,12 @@ handleMergeRetry => ProjectConfiguration -> PullRequestId -> Username + -> Maybe ReactableId -> Priority -> ProjectState -> PullRequest -> Eff es ProjectState -handleMergeRetry projectConfig prId author priority state pr +handleMergeRetry projectConfig prId author source priority state pr -- Only approved PRs with failed builds can be retried | Just approval <- Pr.approval pr, Integrated _ buildStatus <- Pr.integrationStatus pr, @@ -800,7 +813,7 @@ handleMergeRetry projectConfig prId author priority state pr state' <- clearPullRequest prId pr state -- The PR is still approved by its original approver. The person who -- triggered the retry is tracked separately. - doMerge projectConfig prId (Pr.approver approval) state' pr (Pr.approvedFor approval) priority (Just author) + doMerge projectConfig prId (Pr.approver approval) source state' pr (Pr.approvedFor approval) priority (Just author) | otherwise = do () <- leaveComment prId "Only approved PRs with failed builds can be retried.." pure state @@ -1003,7 +1016,7 @@ tryIntegratePullRequest pr state = PullRequestId prNumber = pr pullRequest = fromJust $ Pr.lookupPullRequest pr state title = Pr.title pullRequest - Approval (Username approvedBy) approvalType _prOrder _retriedBy priority = fromJust $ Pr.approval pullRequest + Approval (Username approvedBy) _source approvalType _prOrder _retriedBy priority = fromJust $ Pr.approval pullRequest candidateSha = Pr.sha pullRequest candidateRef = getPullRequestRef pr candidate = (pr, candidateRef, candidateSha) @@ -1145,79 +1158,116 @@ proceedUntilFixedPoint state = do then return state else proceedUntilFixedPoint newState --- Describe the status of the pull request. -describeStatus :: BaseBranch -> PullRequestId -> PullRequest -> ProjectState -> Text -describeStatus (BaseBranch projectBaseBranchName) prId pr state = case Pr.classifyPullRequest pr of - PrStatusAwaitingApproval -> "Pull request awaiting approval." +-- | Feedback on a successfully parsed command. +data Feedback + = -- | Leave a comment. + CommentFeedback Text + | -- | Leave only a reaction. + ReactionFeedback ReactableId GithubApi.ReactionContent + +-- | Determine what kind of feedback to leave based on the status of a PR. +feedbackOnStatus :: BaseBranch -> PullRequestId -> PullRequest -> ProjectState -> Feedback +feedbackOnStatus (BaseBranch projectBaseBranchName) prId pr state = case Pr.classifyPullRequest pr of + PrStatusAwaitingApproval -> CommentFeedback "Pull request awaiting approval." PrStatusApproved -> let - Approval (Username approvedBy) approvalType _position retriedBy priority = fromJust $ Pr.approval pr + Approval (Username approvedBy) source approvalType _position retriedBy priority = fromJust $ Pr.approval pr approvalCommand = Pr.displayMergeCommand (Approve approvalType) retriedByMsg = case retriedBy of Just user -> format " (retried by @{})" [user] Nothing -> mempty - queuePositionMsg = case Pr.getQueuePosition prId state of + queuePosition = Pr.getQueuePosition prId state + queuePositionMsg = case queuePosition of 0 -> "rebasing now" 1 -> "waiting for rebase behind one pull request" n -> format "waiting for rebase behind {} pull requests" [n] priorityMsg = case priority of Normal -> mempty High -> " with high priority" - in format "Pull request approved for {}{} by @{}{}, {}." [approvalCommand, priorityMsg, approvedBy, retriedByMsg, queuePositionMsg] + in + case (queuePosition, source) of + (0, Just reactable) -> ReactionFeedback reactable GithubApi.PlusOne + _ -> + CommentFeedback $ + format + "Pull request approved for {}{} by @{}{}, {}." + [approvalCommand, priorityMsg, approvedBy, retriedByMsg, queuePositionMsg] PrStatusOutdated -> let BaseBranch baseBranchName = Pr.baseBranch pr - in format "Push to {} detected, rebasing again." [baseBranchName] - PrStatusBuildPending -> let Sha sha = fromJust $ Pr.integrationSha pr - train = takeWhile (/= prId) $ Pr.unfailedIntegratedPullRequests state - len = length train - prs = if len == 1 then "PR" else "PRs" - in case train of - [] -> Text.concat ["Rebased as ", sha, ", waiting for CI …"] - (_:_) -> Text.concat [ "Speculatively rebased as ", sha - , " behind ", Text.pack $ show len - , " other ", prs - , ", waiting for CI …" - ] - PrStatusBuildStarted url -> Text.concat ["[CI job :yellow_circle:](", url, ") started."] - PrStatusAwaitingPromotion -> "The PR is waiting to be pushed to the target branch" - PrStatusIntegrated -> "The build succeeded." + in CommentFeedback $ format "Push to {} detected, rebasing again." [baseBranchName] + PrStatusBuildPending -> + let Sha sha = fromJust $ Pr.integrationSha pr + train = takeWhile (/= prId) $ Pr.unfailedIntegratedPullRequests state + len = length train + prs = if len == 1 then "PR" else "PRs" + in CommentFeedback $ case train of + [] -> Text.concat ["Rebased as ", sha, ", waiting for CI …"] + (_ : _) -> + Text.concat + [ "Speculatively rebased as " + , sha + , " behind " + , Text.pack $ show len + , " other " + , prs + , ", waiting for CI …" + ] + PrStatusBuildStarted url -> CommentFeedback $ Text.concat ["[CI job :yellow_circle:](", url, ") started."] + PrStatusAwaitingPromotion -> CommentFeedback "The PR is waiting to be pushed to the target branch" + PrStatusIntegrated -> CommentFeedback "The build succeeded." PrStatusIncorrectBaseBranch -> let BaseBranch baseBranchName = Pr.baseBranch pr - in format "Merge rejected: the base branch of this pull request must be set to {}. It is currently set to {}." - [projectBaseBranchName, baseBranchName] - PrStatusWrongFixups -> "Pull request cannot be integrated as it contains fixup commits that do not belong to any other commits." - PrStatusEmptyRebase -> "Empty rebase. \ - \ Have the changes already been merged into the target branch? \ - \ Aborting." + in CommentFeedback $ + format + "Merge rejected: the base branch of this pull request must be set to {}. It is currently set to {}." + [projectBaseBranchName, baseBranchName] + PrStatusWrongFixups -> + CommentFeedback "Pull request cannot be integrated as it contains fixup commits that do not belong to any other commits." + PrStatusEmptyRebase -> + CommentFeedback + "Empty rebase. \ + \ Have the changes already been merged into the target branch? \ + \ Aborting." PrStatusFailedConflict -> let BaseBranch targetBranchName = Pr.baseBranch pr Branch prBranchName = Pr.branch pr - in Text.concat - [ "Failed to rebase, please rebase manually using\n\n" - , " git fetch && git rebase --interactive --autosquash origin/" - , targetBranchName - , " " - , prBranchName - ] + in + CommentFeedback $ + Text.concat + [ "Failed to rebase, please rebase manually using\n\n" + , " git fetch && git rebase --interactive --autosquash origin/" + , targetBranchName + , " " + , prBranchName + ] -- The following is not actually shown to the user -- as it is never set with needsFeedback=True, -- but here in case we decide to show it. - PrStatusSpeculativeConflict -> "Failed to speculatively rebase. \ - \ I will retry rebasing automatically when the queue clears." - PrStatusFailedBuild url -> case Pr.unfailedIntegratedPullRequestsBefore pr state of - -- On Fridays the retry command is also `retry on friday`. We currently - -- don't have that information here. Is that worth including? - [] -> format "The {}.\n\n\ - \If this is the result of a flaky test, \ - \then tag me again with the `retry` command. \ - \Otherwise, push a new commit and tag me again." - [markdownLink "build failed :x:" url] - trainBefore -> format "Speculative {}. \ - \ I will automatically retry after getting build results for {}." - [ markdownLink "build failed :x:" url - , prettyPullRequestIds trainBefore ] + PrStatusSpeculativeConflict -> + CommentFeedback + "Failed to speculatively rebase. \ + \ I will retry rebasing automatically when the queue clears." + PrStatusFailedBuild url -> + CommentFeedback $ + case Pr.unfailedIntegratedPullRequestsBefore pr state of + -- On Fridays the retry command is also `retry on friday`. We currently + -- don't have that information here. Is that worth including? + [] -> + format + "The {}.\n\n\ + \If this is the result of a flaky test, \ + \then tag me again with the `retry` command. \ + \Otherwise, push a new commit and tag me again." + [markdownLink "build failed :x:" url] + trainBefore -> + format + "Speculative {}. \ + \ I will automatically retry after getting build results for {}." + [ markdownLink "build failed :x:" url + , prettyPullRequestIds trainBefore + ] -- Leave a comment with the feedback from 'describeStatus' and set the -- 'needsFeedback' flag to 'False'. @@ -1228,11 +1278,15 @@ leaveFeedback -> Eff es ProjectState leaveFeedback (prId, pr) state = do projectBaseBranch <- getBaseBranch - let message = describeStatus projectBaseBranch prId pr state - -- Hoff shouldn't reply to any of its own feedback messages. This can happen - -- if external automation causes the bot to issue a merge command to itself. - -- In that case the bot may tag itself when the merge gets approved. - () <- leaveComment prId $ hoffIgnoreComment <> message + case feedbackOnStatus projectBaseBranch prId pr state of + CommentFeedback message -> + -- Hoff shouldn't reply to any of its own feedback messages. This can happen + -- if external automation causes the bot to issue a merge command to itself. + -- In that case the bot may tag itself when the merge gets approved. + leaveComment prId $ hoffIgnoreComment <> message + ReactionFeedback reactable reaction -> + addReaction reactable reaction + pure $ Pr.setNeedsFeedback prId False state -- Run 'leaveFeedback' on all pull requests that need feedback. diff --git a/src/Project.hs b/src/Project.hs index 92c49484..e4952dfe 100644 --- a/src/Project.hs +++ b/src/Project.hs @@ -111,7 +111,7 @@ import qualified Data.IntMap.Strict as IntMap import qualified Data.Map.Strict as Map import qualified Data.Text as T -import Types (PullRequestId (..), Username) +import Types (PullRequestId (..), Username, ReactableId) import Data.Time (UTCTime) -- For any integrated sha, we either wait for the first check, or for @@ -202,6 +202,7 @@ data MergeCommand -- command, i.e. either just "merge" or "merge and deploy". data Approval = Approval { approver :: Username + , approvalSource :: Maybe ReactableId , approvedFor :: ApprovedFor , approvalOrder :: Int , approvalRetriedBy :: Maybe Username diff --git a/src/Types.hs b/src/Types.hs index 2cdd1e0a..f01799c3 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -13,6 +13,8 @@ module Types ( Body (..), PullRequestId (..), + CommentId (..), + ReactableId (..), Username (..), ) where @@ -20,7 +22,7 @@ where import Data.Aeson (FromJSON, ToJSON) import Data.String (IsString) import Data.Text (Text) -import Data.Text.Buildable (Buildable) +import Data.Text.Buildable (Buildable(..)) import GHC.Generics (Generic) import qualified Data.Aeson as Aeson @@ -34,10 +36,35 @@ newtype PullRequestId = PullRequestId Int deriving (Eq, Ord, Show, Generic) -- The body of a pull request newtype Body = Body Text deriving (Eq, Show, Generic, IsString, Buildable) +-- The numeric ID of an issue comment. (In GitHub's model, a PR is a special kind of issue.) +newtype CommentId = CommentId Int + deriving (Eq, Ord, Show, Generic) + instance FromJSON Body instance FromJSON PullRequestId instance FromJSON Username +instance FromJSON CommentId instance ToJSON Body where toEncoding = Aeson.genericToEncoding Aeson.defaultOptions instance ToJSON PullRequestId where toEncoding = Aeson.genericToEncoding Aeson.defaultOptions instance ToJSON Username where toEncoding = Aeson.genericToEncoding Aeson.defaultOptions +instance ToJSON CommentId where toEncoding = Aeson.genericToEncoding Aeson.defaultOptions + +-- The numeric ID of something on GitHub we can react to. +data ReactableId + = OnIssueComment CommentId + | OnPullRequest PullRequestId + -- Ideally we would also be able to react to PR reviews, but (as of 9-5-2024) there + -- doesn't seem to be a REST endpoint for that, despite it being possible through the UI. + deriving (Show, Eq, Ord, Generic) + +instance Buildable ReactableId where + build (OnIssueComment (CommentId commentId)) = + "issue comment " <> build commentId + build (OnPullRequest (PullRequestId prId)) = + "pull request " <> build prId + +instance FromJSON ReactableId + +instance ToJSON ReactableId where + toEncoding = Aeson.genericToEncoding Aeson.defaultOptions diff --git a/tests/EventLoopSpec.hs b/tests/EventLoopSpec.hs index 755ff0bd..c4bab8c1 100644 --- a/tests/EventLoopSpec.hs +++ b/tests/EventLoopSpec.hs @@ -232,6 +232,7 @@ testTimeouts = Config.Timeouts 600 600 fakeRunGithub :: Eff (GithubApi.GithubOperation : es) a -> Eff es a fakeRunGithub = interpret $ \_ -> \case GithubApi.LeaveComment _pr _body -> pure () + GithubApi.AddReaction _reactable _reaction -> pure () GithubApi.HasPushAccess username -> pure $ username `elem` ["rachael", "deckard"] -- Pretend that these two GitHub API calls always fail in these tests. GithubApi.GetPullRequest _pr -> pure Nothing @@ -433,7 +434,7 @@ eventLoopSpec = parallel $ do void $ runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr4 branch baseBranch c4 "Add Leon test results" "deckard" Nothing, - Logic.CommentAdded pr4 "rachael" "@bot merge", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge", Logic.BuildStatusChanged c4 "default" BuildSucceeded, Logic.PullRequestCommitChanged (PullRequestId 4) c4 ] @@ -495,7 +496,7 @@ eventLoopSpec = parallel $ do void $ runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr4 branch baseBranch c4 "Add Leon test results" "deckard" Nothing, - Logic.CommentAdded pr4 "rachael" "@bot merge", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge", Logic.BuildStatusChanged c4 "default" (BuildFailed Nothing) ] -- the build failed, so master's history is unchanged @@ -523,7 +524,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr4 branch baseBranch c4 "Deploy tests!" "deckard" Nothing, - Logic.CommentAdded pr4 "rachael" "@bot merge and tag", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge and tag", Logic.BuildStatusChanged c4 "default" BuildSucceeded ] @@ -583,7 +584,7 @@ eventLoopSpec = parallel $ do -- commit. A new tag `v2` should appear. state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr4 branch baseBranch c4 "Deploy tests!" "deckard" Nothing - , Logic.CommentAdded pr4 "rachael" "@bot merge and deploy to staging" + , Logic.CommentAdded pr4 "rachael" Nothing "@bot merge and deploy to staging" ] -- Extract the sha of the rebased commit from the project state. @@ -642,7 +643,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Add Leon test results" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge" ] -- Extract the sha of the rebased commit from the project state. @@ -683,7 +684,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Deploy it now!" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge and tag" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge and tag" ] let [rebasedSha] = integrationShas state @@ -742,7 +743,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Deploy it now!" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge and deploy to staging" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge and deploy to staging" ] let [rebasedSha] = integrationShas state @@ -803,8 +804,8 @@ eventLoopSpec = parallel $ do Logic.PullRequestOpened pr6 br6 baseBranch c6 "Add Rachael test results" "deckard" Nothing, -- Note that although c4 has a lower pull request number, c6 should -- still be integrated first because it was approved earlier. - Logic.CommentAdded pr6 "rachael" "@bot merge", - Logic.CommentAdded pr4 "rachael" "@bot merge" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge" ] -- Extract the sha of the rebased commit from the project state. @@ -847,8 +848,8 @@ eventLoopSpec = parallel $ do [ Logic.PullRequestOpened pr4 br4 baseBranch c4 "Add Leon test results" "deckard" Nothing, Logic.PullRequestOpened pr6 br6 baseBranch c6 "Add Rachael test results" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge and tag", - Logic.CommentAdded pr4 "rachael" "@bot merge and tag" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge and tag", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge and tag" ] let [rebasedSha,_] = integrationShas state @@ -930,8 +931,8 @@ eventLoopSpec = parallel $ do [ Logic.PullRequestOpened pr3 br3 baseBranch c3' "Add Leon test results" "deckard" Nothing, Logic.PullRequestOpened pr4 br4 baseBranch c4 "Add Rachael test results" "deckard" Nothing, - Logic.CommentAdded pr3 "rachael" "@bot merge", - Logic.CommentAdded pr4 "rachael" "@bot merge" + Logic.CommentAdded pr3 "rachael" Nothing "@bot merge", + Logic.CommentAdded pr4 "rachael" Nothing "@bot merge" ] -- The first pull request should be marked as conflicted. Note: this @@ -971,7 +972,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Add test results" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge" ] -- At this point, c6 has been rebased and pushed to the "integration" @@ -1026,7 +1027,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Add test results" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge and tag" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge and tag" ] -- At this point, c6 has been rebased and pushed to the "integration" @@ -1099,7 +1100,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr6 branch baseBranch c6 "Add test results" "deckard" Nothing, - Logic.CommentAdded pr6 "rachael" "@bot merge and tag" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge and tag" ] -- At this point, c6 has been rebased and pushed to the "integration" branch for building. @@ -1176,7 +1177,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr8 branch baseBranch c7f "Add test results" "deckard" Nothing, - Logic.CommentAdded pr8 "rachael" "@bot merge" + Logic.CommentAdded pr8 "rachael" Nothing "@bot merge" ] -- Extract the sha of the rebased commit from the project state, and @@ -1214,7 +1215,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr8 branch baseBranch c7f "Add test results" "deckard" Nothing, - Logic.CommentAdded pr8 "rachael" "@bot merge" + Logic.CommentAdded pr8 "rachael" Nothing "@bot merge" ] git ["fetch", "origin", "ahead"] -- The ref for commit c4. @@ -1268,7 +1269,7 @@ eventLoopSpec = parallel $ do state <- runLoop Project.emptyProjectState [ Logic.PullRequestOpened pr8 branch baseBranch c7f "Add test results" "deckard" Nothing, - Logic.CommentAdded pr8 "rachael" "@bot merge" + Logic.CommentAdded pr8 "rachael" Nothing "@bot merge" ] -- Extract the sha of the rebased commit from the project state, and @@ -1306,7 +1307,7 @@ eventLoopSpec = parallel $ do [ Logic.PullRequestOpened pr6 branch6 baseBranch c6 "Add Leon test results" "deckard" Nothing, Logic.PullRequestOpened pr8 branch8 baseBranch c7f "Update Leon data" "deckard" Nothing, - Logic.CommentAdded pr8 "rachael" "@bot merge" + Logic.CommentAdded pr8 "rachael" Nothing "@bot merge" ] Project.unfailedIntegratedPullRequests state `shouldBe` [pr8] @@ -1319,7 +1320,7 @@ eventLoopSpec = parallel $ do [ Logic.BuildStatusChanged rebasedSha "default" BuildSucceeded, Logic.PullRequestCommitChanged (PullRequestId 8) rebasedSha, - Logic.CommentAdded pr6 "rachael" "@bot merge" + Logic.CommentAdded pr6 "rachael" Nothing "@bot merge" ] Project.unfailedIntegratedPullRequests state' `shouldBe` [] diff --git a/tests/Spec.hs b/tests/Spec.hs index a6a6af59..671cb331 100644 --- a/tests/Spec.hs +++ b/tests/Spec.hs @@ -15,12 +15,14 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedRecordDot #-} -import Data.Aeson (decode, encode) +import Data.Aeson (decode, encode, eitherDecode) import Data.ByteString.Lazy (readFile) -import Data.Foldable (foldlM) +import Data.Either (isRight) +import Data.Foldable (foldlM, for_) +import Data.Function ((&)) import Data.IntSet (IntSet) import Data.List (group) -import Data.Maybe (fromJust, isJust, isNothing) +import Data.Maybe (fromJust, isNothing) import Data.Text (Text, pack) import Effectful (Eff, (:>), runPureEff) import Effectful.Dispatch.Dynamic (interpret) @@ -45,7 +47,7 @@ import Logic (Action, Action (..), Event (..), IntegrationFailure (..), Retrieve import Project (Approval (..), DeployEnvironment (..), DeploySubprojects (..), Priority (..), ProjectState (ProjectState), PullRequest (PullRequest)) import Time (TimeOperation) -import Types (PullRequestId (..), Username (..)) +import Types (PullRequestId (..), Username (..), CommentId (..), ReactableId (..)) import ParserSpec (parserSpec) import ProjectSpec (projectSpec) @@ -108,7 +110,7 @@ candidateState :: PullRequestId -> Branch -> BaseBranch -> Sha -> Username -> Username -> Sha -> ProjectState candidateState pr prBranch baseBranch prSha prAuthor approvedBy candidateSha = Project.setIntegrationStatus pr (Project.Integrated candidateSha (Project.AnyCheck Project.BuildPending)) - $ Project.setApproval pr (Just (Approval approvedBy Project.Merge 0 Nothing Normal)) + $ Project.setApproval pr (Just (Approval approvedBy Nothing Project.Merge 0 Nothing Normal)) $ singlePullRequestState pr prBranch baseBranch prSha prAuthor -- Types and functions to mock running an action without actually doing anything. @@ -124,6 +126,7 @@ data ActionFlat | ATryPromote Sha | ATryPromoteWithTag Sha TagName TagMessage | ALeaveComment PullRequestId Text + | AAddReaction ReactableId GithubApi.ReactionContent | AIsReviewer Username | ACleanupTestBranch PullRequestId | AGetPullRequest PullRequestId @@ -267,6 +270,9 @@ runActionResults = LeaveComment pr body -> do Writer.tell [ALeaveComment pr body] pure () + AddReaction reactable reaction -> do + Writer.tell [AAddReaction reactable reaction] + pure () IsReviewer username -> do Writer.tell [AIsReviewer username] pure $ isReviewer username @@ -378,11 +384,12 @@ expectSimpleParseFailure commentMsg errorMsg = -- error message contains an excerpt from @commentMsg@ and Hoff doesn't -- ignore this, then it would result in a feedback loop. See -- . - event = [CommentAdded prId "deckard" commentMsg, CommentAdded prId "bot" errorMsg] + event = [CommentAdded prId "deckard" Nothing commentMsg, CommentAdded prId "bot" Nothing errorMsg] (_, actions) = runActionCustom defaultResults $ handleEventsTest event state in actions `shouldBe` [ALeaveComment prId errorMsg] + main :: IO () main = hspec $ do parserSpec @@ -400,13 +407,14 @@ main = hspec $ do Project.integrationStatus pr `shouldBe` Project.NotIntegrated it "handles PullRequestOpened with merge command" $ do - let event = PullRequestOpened (PullRequestId 3) (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") + let prId = PullRequestId 3 + event = PullRequestOpened prId (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") state = fst $ runAction $ handleEventTest event Project.emptyProjectState - state `shouldSatisfy` Project.existsPullRequest (PullRequestId 3) - let pr = fromJust $ Project.lookupPullRequest (PullRequestId 3) state - Project.sha pr `shouldBe` Sha "e0f" - Project.author pr `shouldBe` "deckard" - Project.approval pr `shouldBe` Just (Approval "deckard" Project.Merge 0 Nothing Normal) + state `shouldSatisfy` Project.existsPullRequest prId + let pr = fromJust $ Project.lookupPullRequest prId state + Project.sha pr `shouldBe` Sha "e0f" + Project.author pr `shouldBe` "deckard" + Project.approval pr `shouldBe` Just (Approval "deckard" (Just $ OnPullRequest prId) Project.Merge 0 Nothing Normal) it "handles PullRequestClosed" $ do let event1 = PullRequestOpened (PullRequestId 1) (Branch "p") masterBranch (Sha "abc") "title" "peter" Nothing @@ -439,17 +447,17 @@ main = hspec $ do it "loses approval after the PR commit has changed" $ do let event = PullRequestCommitChanged (PullRequestId 1) (Sha "def") state0 = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "abc") "alice" - state1 = Project.setApproval (PullRequestId 1) (Just (Approval "hatter" Project.Merge 0 Nothing Normal)) state0 + state1 = Project.setApproval (PullRequestId 1) (Just (Approval "hatter" Nothing Project.Merge 0 Nothing Normal)) state0 state2 = fst $ runAction $ handleEventTest event state1 pr1 = fromJust $ Project.lookupPullRequest (PullRequestId 1) state1 pr2 = fromJust $ Project.lookupPullRequest (PullRequestId 1) state2 - Project.approval pr1 `shouldBe` Just (Approval "hatter" Project.Merge 0 Nothing Normal) + Project.approval pr1 `shouldBe` Just (Approval "hatter" Nothing Project.Merge 0 Nothing Normal) Project.approval pr2 `shouldBe` Nothing it "does not lose approval after the PR commit has changed due to a push we caused" $ do let state0 = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "abc") "alice" - state1 = Project.setApproval (PullRequestId 1) (Just (Approval "hatter" Project.Merge 0 Nothing Normal)) state0 + state1 = Project.setApproval (PullRequestId 1) (Just (Approval "hatter" Nothing Project.Merge 0 Nothing Normal)) state0 state2 = Project.setIntegrationStatus (PullRequestId 1) (Project.Integrated (Sha "dc0") (Project.AnyCheck Project.BuildPending)) state1 state3 = Project.setIntegrationStatus (PullRequestId 1) (Project.Integrated (Sha "dc1") (Project.AnyCheck Project.BuildPending)) state2 event = PullRequestCommitChanged (PullRequestId 1) (Sha "dc0") @@ -469,7 +477,7 @@ main = hspec $ do state2 = fst $ runAction $ handleEventTest newPush state1 prAt1 = fromJust $ Project.lookupPullRequest (PullRequestId 1) state1 prAt2 = fromJust $ Project.lookupPullRequest (PullRequestId 1) state2 - Project.approval prAt1 `shouldBe` Just (Approval "deckard" Project.Merge 0 Nothing Normal) + Project.approval prAt1 `shouldBe` Just (Approval "deckard" Nothing Project.Merge 0 Nothing Normal) Project.integrationStatus prAt1 `shouldBe` Project.Integrated (Sha "bcd") (Project.AnyCheck Project.BuildPending) Project.approval prAt2 `shouldBe` Nothing Project.integrationStatus prAt2 `shouldBe` Project.NotIntegrated @@ -480,27 +488,27 @@ main = hspec $ do -- lose the approval status. event = PullRequestCommitChanged (PullRequestId 1) (Sha "000") state0 = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "000") "cindy" - state1 = Project.setApproval (PullRequestId 1) (Just (Approval "daniel" Project.Merge 0 Nothing Normal)) state0 + state1 = Project.setApproval (PullRequestId 1) (Just (Approval "daniel" Nothing Project.Merge 0 Nothing Normal)) state0 (state2, _actions) = runAction $ Logic.proceedUntilFixedPoint state1 (state3, actions) = runAction $ handleEventTest event state2 prAt3 = fromJust $ Project.lookupPullRequest (PullRequestId 1) state3 state3 `shouldBe` state2 actions `shouldBe` [] - Project.approval prAt3 `shouldBe` Just (Approval "daniel" Project.Merge 0 Nothing Normal) + Project.approval prAt3 `shouldBe` Just (Approval "daniel" Nothing Project.Merge 0 Nothing Normal) it "sets approval after a stamp from a reviewer" $ do let state = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "6412ef5") "toby" -- Note: "deckard" is marked as reviewer in the test config. - event = CommentAdded (PullRequestId 1) "deckard" "@bot merge" + event = CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" state' = fst $ runAction $ handleEventTest event state pr = fromJust $ Project.lookupPullRequest (PullRequestId 1) state' - Project.approval pr `shouldBe` Just (Approval "deckard" Project.Merge 0 Nothing Normal) + Project.approval pr `shouldBe` Just (Approval "deckard" Nothing Project.Merge 0 Nothing Normal) it "does not set approval after a stamp from a non-reviewer" $ do let state = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "6412ef5") "toby" -- Note: the comment is a valid approval command, but "rachael" is not -- marked as reviewer in the test config. - event = CommentAdded (PullRequestId 1) "rachael" "@bot merge" + event = CommentAdded (PullRequestId 1) "rachael" Nothing "@bot merge" state' = fst $ runAction $ handleEventTest event state pr = fromJust $ Project.lookupPullRequest (PullRequestId 1) state' Project.approval pr `shouldBe` Nothing @@ -509,12 +517,12 @@ main = hspec $ do let state = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "6412ef5") "patrick" -- Note: "deckard" is marked as reviewer in the test config, but the -- prefix is "@bot ", so none of the comments below should trigger approval. - event1 = CommentAdded (PullRequestId 1) "deckard" "@hoffbot merge" - event2 = CommentAdded (PullRequestId 1) "deckard" "LGTM :shipit:" - event3 = CommentAdded (PullRequestId 1) "deckard" "!merge" + event1 = CommentAdded (PullRequestId 1) "deckard" Nothing "@hoffbot merge" + event2 = CommentAdded (PullRequestId 1) "deckard" Nothing "LGTM :shipit:" + event3 = CommentAdded (PullRequestId 1) "deckard" Nothing "!merge" -- In these cases, the prefix is correct, but the command is wrong. - event4 = CommentAdded (PullRequestId 1) "deckard" "@botmerge" - event5 = CommentAdded (PullRequestId 1) "deckard" "@bot, merge" + event4 = CommentAdded (PullRequestId 1) "deckard" Nothing "@botmerge" + event5 = CommentAdded (PullRequestId 1) "deckard" Nothing "@bot, merge" state' = fst $ runAction $ handleEventsTest [event1, event2, event3, event4, event5] state pr = fromJust $ Project.lookupPullRequest (PullRequestId 1) state' Project.approval pr `shouldBe` Nothing @@ -543,8 +551,8 @@ main = hspec $ do it "only checks if a comment author is a reviewer for comment commands" $ do let state = singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "a38") "tyrell" - event0 = CommentAdded (PullRequestId 1) "deckard" "I don't get it, Tyrell" - event1 = CommentAdded (PullRequestId 1) "deckard" "@bot merge" + event0 = CommentAdded (PullRequestId 1) "deckard" Nothing "I don't get it, Tyrell" + event1 = CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" actions0 = snd $ runAction $ handleEventTest event0 state actions1 = snd $ runAction $ handleEventTest event1 state actions0 `shouldBe` [] @@ -567,9 +575,9 @@ main = hspec $ do $ Project.emptyProjectState -- Approve pull request in order of ascending id, mark the last PR for deployment. events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge and deploy to staging" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge and deploy to staging" ] -- For this test, we assume all integrations and pushes succeed. results = defaultResults { resultIntegrate = [ Right (Sha "b71") @@ -615,9 +623,9 @@ main = hspec $ do $ Project.emptyProjectState -- Approve pull request in order of ascending id, mark the last PR for deployment. events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" ] -- For this test, we assume all integrations and pushes succeed. results = defaultResults { resultIntegrate = [Right (Sha "b71"), Right (Sha "b72"), Right (Sha "b73")] } @@ -649,7 +657,7 @@ main = hspec $ do baseBranch = BaseBranch "master", title = "Add Nexus 7 experiment", author = Username "tyrell", - approval = Just (Approval (Username "deckard") Project.Merge 0 Nothing Normal), + approval = Just (Approval (Username "deckard") Nothing Project.Merge 0 Nothing Normal), integrationStatus = Project.Integrated (Sha "b71") (Project.AnyCheck Project.BuildPending), integrationAttempts = [], needsFeedback = False @@ -660,7 +668,7 @@ main = hspec $ do baseBranch = BaseBranch "master", title = "Some PR", author = Username "rachael", - approval = Just (Approval (Username "deckard") Project.Merge 2 Nothing Normal), + approval = Just (Approval (Username "deckard") Nothing Project.Merge 2 Nothing Normal), integrationStatus = Project.Integrated (Sha "b73") (Project.AnyCheck Project.BuildPending), integrationAttempts = [], needsFeedback = False @@ -671,7 +679,7 @@ main = hspec $ do baseBranch = BaseBranch "master", title = "Another PR", author = Username "rachael", - approval = Just (Approval (Username "deckard") Project.Merge 1 Nothing Normal), + approval = Just (Approval (Username "deckard") Nothing Project.Merge 1 Nothing Normal), integrationStatus = Project.Integrated (Sha "b72") (Project.AnyCheck Project.BuildPending), integrationAttempts = [], needsFeedback = False @@ -687,9 +695,9 @@ main = hspec $ do -- Approve pull requests, but not in order of ascending id. let eventsPermuted = - [ CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" ] actionsPermuted = snd $ run $ handleEventsTest eventsPermuted state actionsPermuted `shouldBe` @@ -720,8 +728,8 @@ main = hspec $ do $ Project.emptyProjectState -- Approve both pull requests, then close the first. events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , PullRequestClosed (PullRequestId 1) ] -- For this test, we assume all integrations and pushes succeed. @@ -760,7 +768,8 @@ main = hspec $ do it "handles merge command in body of pull request" $ do let - event = PullRequestOpened (PullRequestId 1) (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") + prId = PullRequestId 1 + event = PullRequestOpened prId (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") -- For this test, we assume all integrations and pushes succeed. results = defaultResults { resultIntegrate = [Right (Sha "b71")] } @@ -769,10 +778,10 @@ main = hspec $ do actions `shouldBe` [ AIsReviewer "deckard" - , ALeaveComment (PullRequestId 1) "\nPull request approved for merge by @deckard, rebasing now." + , AAddReaction (OnPullRequest prId) GithubApi.PlusOne , ATryIntegrate "Merge #1: title\n\nApproved-by: deckard\nPriority: Normal\nAuto-deploy: false\n" - (PullRequestId 1, Branch "refs/pull/1/head", Sha "e0f") [] False - , ALeaveComment (PullRequestId 1) "\nRebased as b71, waiting for CI …" + (prId, Branch "refs/pull/1/head", Sha "e0f") [] False + , ALeaveComment prId "\nRebased as b71, waiting for CI …" ] classifiedPullRequestIds state' `shouldBe` ClassifiedPullRequestIds { building = [PullRequestId 1] @@ -783,10 +792,11 @@ main = hspec $ do it "does not handle merge command in body of reopened pull request" $ do let + prId = PullRequestId 1 events = - [ PullRequestOpened (PullRequestId 1) (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") - , PullRequestClosed (PullRequestId 1) - , PullRequestOpened (PullRequestId 1) (Branch "p") masterBranch (Sha "e0f") "title" "deckard" Nothing + [ PullRequestOpened prId (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") + , PullRequestClosed prId + , PullRequestOpened prId (Branch "p") masterBranch (Sha "e0f") "title" "deckard" Nothing ] -- For this test, we assume all integrations and pushes succeed. results = defaultResults @@ -796,11 +806,11 @@ main = hspec $ do actions `shouldBe` [ AIsReviewer "deckard" - , ALeaveComment (PullRequestId 1) "\nPull request approved for merge by @deckard, rebasing now." + , AAddReaction (OnPullRequest prId) GithubApi.PlusOne , ATryIntegrate "Merge #1: title\n\nApproved-by: deckard\nPriority: Normal\nAuto-deploy: false\n" - (PullRequestId 1, Branch "refs/pull/1/head", Sha "e0f") [] False - , ALeaveComment (PullRequestId 1) "\nRebased as b71, waiting for CI …" - , ALeaveComment (PullRequestId 1) "Abandoning this pull request because it was closed." + (prId, Branch "refs/pull/1/head", Sha "e0f") [] False + , ALeaveComment prId "\nRebased as b71, waiting for CI …" + , ALeaveComment prId "Abandoning this pull request because it was closed." , ACleanupTestBranch (PullRequestId 1) ] classifiedPullRequestIds state' `shouldBe` ClassifiedPullRequestIds @@ -814,7 +824,7 @@ main = hspec $ do let -- We comment on PR #1, but the project is empty, so this comment should -- be dropped on the floor. - event = CommentAdded (PullRequestId 1) "deckard" "@bot merge" + event = CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" (state, actions) = runAction $ handleEventTest event Project.emptyProjectState -- We expect no changes to the state, and in particular, no side effects. state `shouldBe` Project.emptyProjectState @@ -900,12 +910,92 @@ main = hspec $ do -- obtained its details. actions `shouldBe` [AGetOpenPullRequests] + it "stores the comment ID of a 'merge' command" $ do + let + prId = PullRequestId 1 + commentId = CommentId 42 + state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" + + event = CommentAdded prId "deckard" (Just commentId) "@bot merge and deploy to staging" + + results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } + (state', _actions) = runActionCustom results $ handleEventTest event state + + fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` + (\pr -> (Project.approval pr >>= Project.approvalSource) == Just (OnIssueComment commentId)) + + it "stores the pull request ID of a 'merge' command if it's in the PR body" $ do + let + prId = PullRequestId 1 + event = PullRequestOpened prId (Branch "p") masterBranch (Sha "e0f") "title" "deckard" (Just "@bot merge") + -- For this test, we assume all integrations and pushes succeed. + results = defaultResults + { resultIntegrate = [Right (Sha "b71")] } + run = runActionCustom results + (state', _actions) = run $ handleEventTest event Project.emptyProjectState + + fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` + (\pr -> (Project.approval pr >>= Project.approvalSource) == Just (OnPullRequest prId)) + + it "adds a reaction to a 'merge' command in the common case" $ do + let + prId = PullRequestId 1 + commentId = CommentId 42 + state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" + + event = CommentAdded prId "deckard" (Just commentId) "@bot merge" + + results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } + (_state', actions) = runActionCustom results $ handleEventTest event state + + actions `shouldContain` [AAddReaction (OnIssueComment commentId) GithubApi.PlusOne] + + it "adds a reaction to a 'retry' command in the common case" $ do + let + prId = PullRequestId 1 + mergeCommentId = CommentId 42 + retryCommentId = CommentId 72 + state = singlePullRequestState prId (Branch "p") masterBranch (Sha "1b1") "tyrell" + + events = + [ CommentAdded prId "deckard" (Just mergeCommentId) "@bot merge" + , BuildStatusChanged (Sha "1b3") "default" (Project.BuildFailed (Just "url")) + , CommentAdded prId "deckard" (Just retryCommentId) "@bot retry" + ] + + results = defaultResults { resultIntegrate = [Right (Sha "1b3"), Right (Sha "00f")] } + (_state', actions) = runActionCustom results $ handleEventsTest events state + + actions `shouldContain` [AAddReaction (OnIssueComment retryCommentId) GithubApi.PlusOne] + + it "falls back to an ordinary comment if there are other PRs ahead in the queue" $ do + let + (prId1, prId2) = (PullRequestId 1, PullRequestId 2) + (mergeCommentId1, mergeCommentId2) = (CommentId 111, CommentId 222) + state = + Project.emptyProjectState + & Project.insertPullRequest (PullRequestId 1) (Branch "one") masterBranch (Sha "111") "First PR" (Username "person") + & Project.insertPullRequest (PullRequestId 2) (Branch "two") masterBranch (Sha "222") "Second PR" (Username "robot") + events = + [ CommentAdded prId1 "deckard" (Just mergeCommentId1) "@bot merge" + , CommentAdded prId2 "deckard" (Just mergeCommentId2) "@bot merge" + ] + results = defaultResults { resultIntegrate = [Right (Sha "11f"), Right (Sha "22f")] } + (_state', actions) = runActionCustom results $ handleEventsTest events state + + actions `shouldContain` [ALeaveComment prId2 "\nPull request approved for merge by @deckard, waiting for rebase behind one pull request."] + + -- We check that we don't add /any/ reaction, not just that we don't add :+1:. + let allPossibleReactions = [minBound .. maxBound] + for_ allPossibleReactions $ \reaction -> + actions `shouldNotContain` [AAddReaction (OnIssueComment mergeCommentId2) reaction] + it "recognizes 'merge and deploy' commands as the proper ApprovedFor value" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to staging" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to staging" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -919,14 +1009,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) it "recognizes 'merge and deploy to ' commands as the proper ApprovedFor value" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to production" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to production" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -940,7 +1030,7 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "production") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "production") 0 Nothing Normal)) -- There is no default environment to deploy to when no deployment -- environments have been configured. Earlier versions would silently ignore @@ -950,7 +1040,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (_, actions) = runActionCustomConfig (testProjectConfig{Config.deployEnvironments = Just []}) results $ handleEventTest event state @@ -962,7 +1052,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy on Friday" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy on Friday" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustomConfig (testProjectConfig{Config.deployEnvironments = Just ["production"]}) results $ handleEventTest event state @@ -980,7 +1070,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (_, actions) = runActionCustomConfig (testProjectConfig{Config.deployEnvironments = Just ["production"]}) results $ handleEventTest event state @@ -998,7 +1088,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to production" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to production" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (_, actions) = runActionCustomConfig (testProjectConfig{Config.deployEnvironments = Just ["production"]}) results $ handleEventTest event state @@ -1019,7 +1109,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to staging on Friday" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to staging on Friday" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0))} (state', actions) = runActionCustom results $ handleEventTest event state @@ -1033,14 +1123,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) it "allows 'merge and deploy to '" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy aaa to production" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy aaa to production" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1054,14 +1144,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy (OnlySubprojects ["aaa"]) $ DeployEnvironment "production") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy (OnlySubprojects ["aaa"]) $ DeployEnvironment "production") 0 Nothing Normal)) it "allows 'merge and deploy to '" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy aaa, bbb to production" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy aaa, bbb to production" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1075,14 +1165,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy (OnlySubprojects ["aaa", "bbb"]) $ DeployEnvironment "production") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy (OnlySubprojects ["aaa", "bbb"]) $ DeployEnvironment "production") 0 Nothing Normal)) it "recognizes 'merge and tag' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and tag" + event = CommentAdded prId "deckard" Nothing "@bot merge and tag" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1096,14 +1186,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.MergeAndTag 0 Nothing Normal)) it "recognizes 'merge and tag' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and tag" + event = CommentAdded prId "deckard" Nothing "@bot merge and tag" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1117,14 +1207,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.MergeAndTag 0 Nothing Normal)) it "recognizes 'merge and tag' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and tag" + event = CommentAdded prId "deckard" Nothing "@bot merge and tag" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1138,14 +1228,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.MergeAndTag 0 Nothing Normal)) it "recognizes 'merge and tag on friday' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and tag on friday" + event = CommentAdded prId "deckard" Nothing "@bot merge and tag on friday" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1159,14 +1249,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.MergeAndTag 0 Nothing Normal)) it "recognizes 'merge' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1180,14 +1270,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.Merge 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.Merge 0 Nothing Normal)) it "recognizes 'merge on Friday' command" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge on Friday" + event = CommentAdded prId "deckard" Nothing "@bot merge on Friday" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1201,7 +1291,7 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.Merge 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.Merge 0 Nothing Normal)) it "notifies when command not recognized" $ expectSimpleParseFailure "@bot mergre" "\nUnknown or invalid command found:\n\n comment:1:6:\n |\n 1 | @bot mergre\n | ^^^^^\n unexpected \"mergr\"\n expecting \"merge\", \"retry\", or white space\n[Basic usage is explained here.](https://github.com/channable/hoff/blob/master/readme.md#using-hoff)" @@ -1211,7 +1301,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "bot" "@bot merge" + event = CommentAdded prId "bot" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1229,7 +1319,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and tag" + event = CommentAdded prId "deckard" Nothing "@bot merge and tag" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1244,7 +1334,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to staging" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to staging" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1259,7 +1349,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1274,7 +1364,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge as hotfix" + event = CommentAdded prId "deckard" Nothing "@bot merge as hotfix" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1289,7 +1379,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to production as hotfix" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to production as hotfix" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (_, actions) = runActionCustom results $ handleEventTest event state @@ -1304,7 +1394,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge as hotfix" + event = CommentAdded prId "deckard" Nothing "@bot merge as hotfix" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (state', actions) = runActionCustom results $ handleEventTestFF event state @@ -1323,14 +1413,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.Merge 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.Merge 0 Nothing Normal)) it "refuses 'merge' (without hotfix) during a feature freeze period" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTestFF event state @@ -1346,7 +1436,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge as hotfix" + event = CommentAdded prId "deckard" Nothing "@bot merge as hotfix" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 3 5) (T.secondsToDiffTime 0)) } (_, actions) = runActionCustom results $ handleEventTestFF event state @@ -1362,7 +1452,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 3 4) (T.secondsToDiffTime 0)) } (state', actions) = runActionCustom results $ handleEventTestFF event state @@ -1381,14 +1471,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.Merge 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing Project.Merge 0 Nothing Normal)) it "accepts 'merge hotfix deploy to production as hotfix' during a feature freeze period" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge and deploy to production as hotfix" + event = CommentAdded prId "deckard" Nothing "@bot merge and deploy to production as hotfix" results = defaultResults { resultIntegrate = [Right (Sha "def2345")], resultGetDateTime = repeat (T.UTCTime (T.fromMondayStartWeek 2021 2 5) (T.secondsToDiffTime 0)) } (state', actions) = runActionCustom results $ handleEventTestFF event state @@ -1407,14 +1497,14 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr == Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "production") 0 Nothing Normal)) + (\pr -> Project.approval pr == Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "production") 0 Nothing Normal)) it "refuses to merge an empty rebase" $ do let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" results = defaultResults { resultIntegrate = [Left (IntegrationFailure (BaseBranch "master") EmptyRebase)] @@ -1439,7 +1529,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") (BaseBranch "m") (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "@bot merge" + event = CommentAdded prId "deckard" Nothing "@bot merge" (state', actions) = runAction $ handleEventTest event state @@ -1457,9 +1547,9 @@ main = hspec $ do state = singlePullRequestState prId (Branch "p") (BaseBranch "m") (Sha "abc1234") "tyrell" events = - [ CommentAdded prId "deckard" "@bot merge" + [ CommentAdded prId "deckard" Nothing "@bot merge" , PullRequestEdited prId "Untitled" masterBranch - , CommentAdded prId "deckard" "@bot merge"] + , CommentAdded prId "deckard" Nothing "@bot merge"] results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventsTest events state @@ -1483,7 +1573,7 @@ main = hspec $ do state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" events = - [ CommentAdded prId "deckard" "@bot merge" + [ CommentAdded prId "deckard" Nothing "@bot merge" , PullRequestEdited prId "Untitled" (BaseBranch "m") ] @@ -1510,7 +1600,7 @@ main = hspec $ do state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" events = - [ CommentAdded prId "deckard" "@bot merge" + [ CommentAdded prId "deckard" Nothing "@bot merge" , PullRequestCommitChanged prId (Sha "Untitled") ] @@ -1541,7 +1631,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "Let's do this, @bot merge and deploy to staging." + event = CommentAdded prId "deckard" Nothing "Let's do this, @bot merge and deploy to staging." results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1555,7 +1645,7 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) -- For ergonomics' sake, the command can be part of a sentence that ends -- with one or more punctuation characters, but only if the line ends after @@ -1570,7 +1660,8 @@ main = hspec $ do it "ignores comments containing a special 'Hoff: ignore' HTML comment" $ let prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = [CommentAdded prId "bot" "\nUnknown or invalid command found:\n\n comment:1:24:\n |\n 1 | @bot merge and deploy!\n | ^\n Merge commands may not be followed by anything other than a punctuation character ('.', ',', '!', '?', ':', ';').\n"] + errorMessage = "\nUnknown or invalid command found:\n\n comment:1:24:\n |\n 1 | @bot merge and deploy!\n | ^\n Merge commands may not be followed by anything other than a punctuation character ('.', ',', '!', '?', ':', ';').\n" + event = [CommentAdded prId "bot" Nothing errorMessage] (_, actions) = runActionCustom defaultResults $ handleEventsTest event state in actions `shouldBe` [] @@ -1585,13 +1676,13 @@ main = hspec $ do approvalMessage = "\nPull request approved for merge by @bot, rebasing now." event = -- This merge approval is posted by the bot iself - [ CommentAdded prId "bot" "@bot merge" + [ CommentAdded prId "bot" Nothing "@bot merge" -- The feedback message then tags the bot, but the special ignore -- comment will cause it to ignore the message - , CommentAdded prId "bot" approvalMessage - , CommentAdded prId "bot" "\nRebased as 1b2, waiting for CI …" + , CommentAdded prId "bot" Nothing approvalMessage + , CommentAdded prId "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "def2345") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded prId "bot" "\n[CI job :yellow_circle:](example.com/1b2) started." + , CommentAdded prId "bot" Nothing "\n[CI job :yellow_circle:](example.com/1b2) started." , BuildStatusChanged (Sha "def2345") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "def2345") ] @@ -1615,7 +1706,7 @@ main = hspec $ do prId = PullRequestId 1 state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" - event = CommentAdded prId "deckard" "Hi @bo. @bot merge and deploy to staging" + event = CommentAdded prId "deckard" Nothing "Hi @bo. @bot merge and deploy to staging" results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } (state', actions) = runActionCustom results $ handleEventTest event state @@ -1629,7 +1720,7 @@ main = hspec $ do ] fromJust (Project.lookupPullRequest prId state') `shouldSatisfy` - (\pr -> Project.approval pr== Just (Approval (Username "deckard") (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) + (\pr -> Project.approval pr== Just (Approval (Username "deckard") Nothing (Project.MergeAndDeploy EntireProject $ DeployEnvironment "staging") 0 Nothing Normal)) it "restarts when pushed to master" $ do let @@ -1639,7 +1730,7 @@ main = hspec $ do Project.emptyProjectState results = defaultResults {resultIntegrate = [Right (Sha "1b2"), Right (Sha "1b3")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , PushPerformed (BaseBranch "refs/heads/master") (Sha "1c1") , BuildStatusChanged (Sha "1b3") "default" (Project.BuildStarted "example.com/1b2") @@ -1678,9 +1769,9 @@ main = hspec $ do (Branch "snd") masterBranch (Sha "ab2") "... Of the ..." (Username "dewey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") , BuildStatusChanged (Sha "1b2") "default" (Project.BuildFailed (Just "example.com/1b2")) , PushPerformed (BaseBranch "refs/heads/master") (Sha "1c1") @@ -1741,11 +1832,11 @@ main = hspec $ do (Branch "trd") masterBranch (Sha "ab3") "... Performance" (Username "louie") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "3b2") "default" (Project.BuildStarted "example.com/3b2") , PushPerformed (BaseBranch "refs/heads/master") (Sha "1c1") ] @@ -1825,11 +1916,11 @@ main = hspec $ do (Branch "trd") masterBranch (Sha "ab3") "... Performance" (Username "louie") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "3b2") "default" (Project.BuildStarted "example.com/3b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1b2") @@ -1887,11 +1978,11 @@ main = hspec $ do (Branch "trd") masterBranch (Sha "ab3") "... Performance" (Username "louie") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "3b2") "default" (Project.BuildStarted "example.com/3b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1b2") @@ -1948,9 +2039,9 @@ main = hspec $ do (Branch "snd") masterBranch (Sha "ab2") "... Of the ..." (Username "dewey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1b2") @@ -2003,7 +2094,7 @@ main = hspec $ do results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } event = - [ CommentAdded prId "deckard" "@bot merge" + [ CommentAdded prId "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "def2345") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "def2345") "default" Project.BuildSucceeded , ClockTick (Time.addTime testTime 100) @@ -2024,7 +2115,7 @@ main = hspec $ do results = defaultResults { resultIntegrate = [Right (Sha "def2345")] } event = - [ CommentAdded prId "deckard" "@bot merge" + [ CommentAdded prId "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "def2345") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "def2345") "default" Project.BuildSucceeded , ClockTick (Time.addTime testTime 700) @@ -2050,10 +2141,10 @@ main = hspec $ do (Branch "snd") masterBranch (Sha "ab2") "... Of the ..." (Username "dewey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") , BuildStatusChanged (Sha "2b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1b2") @@ -2102,7 +2193,7 @@ main = hspec $ do (Branch "fst") masterBranch (Sha "ab1") "Improvements..." (Username "huey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PushPerformed (BaseBranch "refs/heads/master") (Sha "1c1") @@ -2149,7 +2240,7 @@ main = hspec $ do (Branch "fst") masterBranch (Sha "ab1") "Improvements..." (Username "huey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1b2") @@ -2198,9 +2289,9 @@ main = hspec $ do (Branch "snd") masterBranch (Sha "ab2") "... Of the ..." (Username "dewey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2b2") "default" (Project.BuildStarted "example.com/2b2") , BuildStatusChanged (Sha "2b2") "default" Project.BuildSucceeded , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded @@ -2253,7 +2344,7 @@ main = hspec $ do (Branch "fst") masterBranch (Sha "ab1") "Improvements..." (Username "huey") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestClosed (PullRequestId 1) @@ -2284,7 +2375,7 @@ main = hspec $ do it "finds a new candidate" $ do let state - = Project.setApproval (PullRequestId 1) (Just (Approval "fred" Project.Merge 0 Nothing Normal)) + = Project.setApproval (PullRequestId 1) (Just (Approval "fred" Nothing Project.Merge 0 Nothing Normal)) $ singlePullRequestState (PullRequestId 1) (Branch "p") masterBranch (Sha "f34") "sally" results = defaultResults { resultIntegrate = [Right (Sha "38c")] @@ -2302,8 +2393,8 @@ main = hspec $ do it "finds a new candidate with multiple PRs" $ do let state - = Project.setApproval (PullRequestId 2) (Just (Approval "fred" Project.Merge 0 Nothing Normal)) - $ Project.setApproval (PullRequestId 1) (Just (Approval "fred" Project.Merge 1 Nothing Normal)) + = Project.setApproval (PullRequestId 2) (Just (Approval "fred" Nothing Project.Merge 0 Nothing Normal)) + $ Project.setApproval (PullRequestId 1) (Just (Approval "fred" Nothing Project.Merge 1 Nothing Normal)) $ fst $ runAction $ handleEventsTest [ PullRequestOpened (PullRequestId 1) (Branch "p") masterBranch (Sha "f34") "Untitled" "sally" Nothing , PullRequestOpened (PullRequestId 2) (Branch "s") masterBranch (Sha "g35") "Another untitled" "rachael" Nothing @@ -2333,7 +2424,7 @@ main = hspec $ do , Project.sha = Sha "f35" , Project.title = "Add my test results" , Project.author = "rachael" - , Project.approval = Just (Approval "deckard" Project.Merge 0 Nothing Normal) + , Project.approval = Just (Approval "deckard" Nothing Project.Merge 0 Nothing Normal) , Project.integrationStatus = Project.Integrated (Sha "38d") (Project.AnyCheck Project.BuildSucceeded) , Project.integrationAttempts = [] , Project.needsFeedback = False @@ -2357,7 +2448,7 @@ main = hspec $ do , Project.sha = Sha "f35" , Project.title = "Add my test results" , Project.author = "rachael" - , Project.approval = Just (Approval "deckard" Project.MergeAndTag 0 Nothing Normal) + , Project.approval = Just (Approval "deckard" Nothing Project.MergeAndTag 0 Nothing Normal) , Project.integrationStatus = Project.Integrated (Sha "38d") (Project.AnyCheck Project.BuildSucceeded) , Project.integrationAttempts = [] , Project.needsFeedback = False @@ -2386,7 +2477,7 @@ main = hspec $ do , Project.sha = Sha "f35" , Project.title = "Add my test results" , Project.author = "rachael" - , Project.approval = Just (Approval "deckard" Project.Merge 0 Nothing Normal) + , Project.approval = Just (Approval "deckard" Nothing Project.Merge 0 Nothing Normal) , Project.integrationStatus = Project.Integrated (Sha "38d") (Project.AnyCheck Project.BuildSucceeded) , Project.integrationAttempts = [] , Project.needsFeedback = False @@ -2425,7 +2516,7 @@ main = hspec $ do , Project.sha = Sha "f35" , Project.title = "Add my test results" , Project.author = "rachael" - , Project.approval = Just (Approval "deckard" Project.MergeAndTag 0 Nothing Normal) + , Project.approval = Just (Approval "deckard" Nothing Project.MergeAndTag 0 Nothing Normal) , Project.integrationStatus = Project.Integrated (Sha "38d") (Project.AnyCheck Project.BuildSucceeded) , Project.integrationAttempts = [] , Project.needsFeedback = False @@ -2473,7 +2564,7 @@ main = hspec $ do (Username "tyrell") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "b71") "default" Project.BuildPending , BuildStatusChanged (Sha "b71") "default" Project.BuildSucceeded ] @@ -2513,7 +2604,7 @@ main = hspec $ do Project.sha = Sha "f35", Project.title = "Add Leon test results", Project.author = "rachael", - Project.approval = Just (Approval "deckard" Project.Merge 1 Nothing Normal), + Project.approval = Just (Approval "deckard" Nothing Project.Merge 1 Nothing Normal), Project.integrationStatus = Project.Integrated (Sha "38d") (Project.AnyCheck Project.BuildSucceeded), Project.integrationAttempts = [], Project.needsFeedback = False @@ -2525,7 +2616,7 @@ main = hspec $ do Project.sha = Sha "f37", Project.title = "Add my test results", Project.author = "rachael", - Project.approval = Just (Approval "deckard" Project.Merge 0 Nothing Normal), + Project.approval = Just (Approval "deckard" Nothing Project.Merge 0 Nothing Normal), Project.integrationStatus = Project.NotIntegrated, Project.integrationAttempts = [], Project.needsFeedback = False @@ -2562,18 +2653,18 @@ main = hspec $ do (Username "tyrell") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "b71") "default" Project.BuildPending , BuildStatusChanged (Sha "b71") "default" (Project.BuildStarted "https://status.example.com/b71") , BuildStatusChanged (Sha "b71") "default" $ Project.BuildFailed $ Just $ pack "https://example.com/build-status" -- User summons bot again because CI failed for an external reason. - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" -- GitHub notifies Hoff of new comments sent by Hoff: - , CommentAdded (PullRequestId 1) "bot" + , CommentAdded (PullRequestId 1) "bot" Nothing "The [build failed :x:](https://example.com/build-status).\n\n\ \If this is the result of a flaky test, then tag me again with the `retry` command. \ \Otherwise, push a new commit and tag me again." - , CommentAdded (PullRequestId 1) "bot" + , CommentAdded (PullRequestId 1) "bot" Nothing "The [build failed :x:](https://example.com/build-status).\n\n\ \If this is the result of a flaky test, then tag me again with the `retry` command. \ \Otherwise, push a new commit and tag me again." @@ -2611,10 +2702,9 @@ main = hspec $ do it "parses a PullRequestPayload correctly" $ do examplePayload <- readFile "tests/data/pull-request-payload.json" - let maybePayload :: Maybe PullRequestPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @PullRequestPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.action `shouldBe` Github.Opened payload.owner `shouldBe` "baxterthehacker" payload.repository `shouldBe` "public-repo" @@ -2629,10 +2719,9 @@ main = hspec $ do it "parses a CommentPayload from a created issue_comment correctly" $ do examplePayload <- readFile "tests/data/issue-comment-created-payload.json" - let maybePayload :: Maybe CommentPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @CommentPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.action `shouldBe` Left Github.CommentCreated payload.owner `shouldBe` "baxterthehacker" payload.repository `shouldBe` "public-repo" @@ -2642,10 +2731,9 @@ main = hspec $ do it "parses a CommentPayload from an edited issue_comment correctly" $ do examplePayload <- readFile "tests/data/issue-comment-edited-payload.json" - let maybePayload :: Maybe CommentPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @CommentPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.action `shouldBe` Left Github.CommentEdited payload.owner `shouldBe` "crtschin" payload.repository `shouldBe` "test" @@ -2655,10 +2743,9 @@ main = hspec $ do it "parses a CommentPayload from a submitted pull_request_review correctly" $ do examplePayload <- readFile "tests/data/pull-request-review-submitted-payload.json" - let maybePayload :: Maybe CommentPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @CommentPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.action `shouldBe` Right Github.ReviewSubmitted payload.owner `shouldBe` "crtschin" payload.repository `shouldBe` "test" @@ -2668,10 +2755,9 @@ main = hspec $ do it "parses a CommentPayload from a edited pull_request_review correctly" $ do examplePayload <- readFile "tests/data/pull-request-review-edited-payload.json" - let maybePayload :: Maybe CommentPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @CommentPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.action `shouldBe` Right Github.ReviewEdited payload.owner `shouldBe` "crtschin" payload.repository `shouldBe` "test" @@ -2681,10 +2767,9 @@ main = hspec $ do it "parses a CommitStatusPayload correctly" $ do examplePayload <- readFile "tests/data/status-payload.json" - let maybePayload :: Maybe CommitStatusPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @CommitStatusPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.owner `shouldBe` "baxterthehacker" payload.repository `shouldBe` "public-repo" payload.status `shouldBe` Github.Success @@ -2693,10 +2778,9 @@ main = hspec $ do it "parses a PushPayload correctly" $ do examplePayload <- readFile "tests/data/push-payload.json" - let maybePayload :: Maybe PushPayload - maybePayload = decode examplePayload - maybePayload `shouldSatisfy` isJust - let payload = fromJust maybePayload + let result = eitherDecode @PushPayload examplePayload + result `shouldSatisfy` isRight + let Right payload = result payload.owner `shouldBe` "Codertocat" payload.repository `shouldBe` "Hello-World" payload.branch `shouldBe` BaseBranch "refs/heads/master" @@ -2778,18 +2862,23 @@ main = hspec $ do , repository = "owl" , number = 1 , author = "deckard" + , id = case action of + -- If we receive a "real" comment, we have an ID. + Left _ -> Just $ CommentId 42 + -- If we receive a review, we don't have an ID we can use. + Right _ -> Nothing , body = "Must be expensive." } it "converts a comment created event" $ do let payload = testCommentPayload $ Left Github.CommentCreated Just event = convertGithubEvent $ Github.Comment payload - event `shouldBe` (CommentAdded (PullRequestId 1) "deckard" "Must be expensive.") + event `shouldBe` (CommentAdded (PullRequestId 1) "deckard" (Just $ CommentId 42) "Must be expensive.") it "converts a review submitted event" $ do let payload = testCommentPayload $ Right Github.ReviewSubmitted Just event = convertGithubEvent $ Github.Comment payload - event `shouldBe` (CommentAdded (PullRequestId 1) "deckard" "Must be expensive.") + event `shouldBe` (CommentAdded (PullRequestId 1) "deckard" Nothing "Must be expensive.") it "ignores a comment edited event" $ do let payload = testCommentPayload $ Left Github.CommentEdited @@ -2887,9 +2976,9 @@ main = hspec $ do $ Project.emptyProjectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/alt1/1b2") , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/alt2/1b2") @@ -2917,11 +3006,11 @@ main = hspec $ do $ Project.emptyProjectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/1b2) started." , BuildStatusChanged (Sha "1b2") "default" (Project.BuildFailed (Just "example.com/1b2")) , BuildStatusChanged (Sha "1b2") "default" Project.BuildPending -- ignored , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") -- ignored @@ -2955,11 +3044,11 @@ main = hspec $ do $ Project.emptyProjectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "example.com/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/1b2) started." , BuildStatusChanged (Sha "1b2") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") , BuildStatusChanged (Sha "1b2") "default" Project.BuildPending -- ignored @@ -3005,15 +3094,15 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2"), Right (Sha "1b3")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 13) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" - , CommentAdded (PullRequestId 13) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 13) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 13) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" + , CommentAdded (PullRequestId 13) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 13) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "first" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "first" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "1b2") "required" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") @@ -3071,12 +3160,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "first" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "first" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "1b2") "required" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") @@ -3117,12 +3206,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "first" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "first" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildFailed Nothing) @@ -3163,12 +3252,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "first" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "first" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") ] @@ -3205,12 +3294,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "first" (Project.BuildStarted "example.com/1b2") , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "first" Project.BuildSucceeded , BuildStatusChanged (Sha "1b2") "required" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") @@ -3251,12 +3340,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") , BuildStatusChanged (Sha "1b2") "mandatory" (Project.BuildStarted "example.com/mandatory/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." , BuildStatusChanged (Sha "1b2") "required" Project.BuildSucceeded , BuildStatusChanged (Sha "1b2") "mandatory" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 12) (Sha "1b2") @@ -3297,12 +3386,12 @@ main = hspec $ do $ projectState results = defaultResults {resultIntegrate = [Right (Sha "1b2")]} events = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" - , CommentAdded (PullRequestId 12) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 12) "bot" "\nRebased as 1b2, waiting for CI …" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 12) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 12) "bot" Nothing "\nRebased as 1b2, waiting for CI …" , BuildStatusChanged (Sha "1b2") "required" (Project.BuildStarted "example.com/required/1b2") , BuildStatusChanged (Sha "1b2") "mandatory" (Project.BuildStarted "example.com/mandatory/1b2") - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/required/1b2) started." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/required/1b2) started." ] commonAssertions actions finalState = do actions `shouldBe` @@ -3357,7 +3446,7 @@ main = hspec $ do -- These are the events and action from a typical PR with a failed -- build that has not yet been retried commonEvents = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" Project.BuildPending , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "url") , BuildStatusChanged (Sha "1b2") "default" (Project.BuildFailed (Just "url")) @@ -3401,7 +3490,7 @@ main = hspec $ do it "allows merges with failed builds using the 'retry' command" $ do runRetryTest - [ CommentAdded (PullRequestId 12) "deckard" "@bot retry" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry" , BuildStatusChanged (Sha "00f") "default" Project.BuildPending , BuildStatusChanged (Sha "00f") "default" (Project.BuildStarted "url2") , BuildStatusChanged (Sha "00f") "default" Project.BuildSucceeded @@ -3421,7 +3510,7 @@ main = hspec $ do it "rejects a plain 'retry' command on Fridays" $ do runRetryTest - [ CommentAdded (PullRequestId 12) "deckard" "@bot retry" ] + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry" ] [ AIsReviewer (Username "deckard") , ALeaveComment (PullRequestId 12) "Your merge request has been denied, because merging on Fridays is not recommended. To override this behaviour use the command `retry on Friday`." ] @@ -3429,7 +3518,7 @@ main = hspec $ do it "allows retrying merges with 'retry on friday' on Fridays" $ do runRetryTest - [ CommentAdded (PullRequestId 12) "deckard" "@bot retry on friday" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry on friday" , BuildStatusChanged (Sha "00f") "default" Project.BuildPending , BuildStatusChanged (Sha "00f") "default" (Project.BuildStarted "url2") , BuildStatusChanged (Sha "00f") "default" Project.BuildSucceeded @@ -3449,7 +3538,7 @@ main = hspec $ do it "rejects 'retry on friday' commands when it's not Friday" $ do runRetryTest - [ CommentAdded (PullRequestId 12) "deckard" "@bot retry on friday" ] + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry on friday" ] [ AIsReviewer (Username "deckard") , ALeaveComment (PullRequestId 12) "Your merge request has been denied because it is not Friday. Run 'retry' instead." ] @@ -3459,13 +3548,13 @@ main = hspec $ do it "doesn't allow retrying pending PR" $ do let events' = - [ CommentAdded (PullRequestId 12) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1b2") "default" Project.BuildPending , BuildStatusChanged (Sha "1b2") "default" (Project.BuildStarted "url") -- The above is the same as 'commonEvents', except that the build -- hasn't finished yet. Requesting a retry here should result in -- an error message. - , CommentAdded (PullRequestId 12) "deckard" "@bot retry" + , CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry" ] actions' = [ AIsReviewer (Username "deckard") @@ -3481,7 +3570,7 @@ main = hspec $ do actions `shouldBe` actions' it "doesn't allow retrying unapproved PRs" $ do - let events' = [ CommentAdded (PullRequestId 12) "deckard" "@bot retry"] + let events' = [ CommentAdded (PullRequestId 12) "deckard" Nothing "@bot retry"] actions' = [ AIsReviewer (Username "deckard") , ALeaveComment (PullRequestId 12) "Only approved PRs with failed builds can be retried.." @@ -3501,11 +3590,11 @@ main = hspec $ do (Branch "snd") masterBranch (Sha "36b") "Thirty-sixth PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 19) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 19) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "a19") "default" (Project.BuildFailed Nothing) - , CommentAdded (PullRequestId 36) "deckard" "@bot merge" + , CommentAdded (PullRequestId 36) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "b36") "default" (Project.BuildFailed Nothing) - , CommentAdded (PullRequestId 36) "deckard" "@bot merge on Friday" + , CommentAdded (PullRequestId 36) "deckard" Nothing "@bot merge on Friday" , PullRequestClosed (PullRequestId 19) , PullRequestClosed (PullRequestId 36) ] @@ -3569,11 +3658,11 @@ main = hspec $ do (Branch "trd") masterBranch (Sha "ab3") "... Performance" (Username "louie") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "ab1") "default" (Project.BuildStarted "url") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "ab2") "default" (Project.BuildStarted "url") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "ab3") "default" (Project.BuildStarted "url") , BuildStatusChanged (Sha "ab1") "default" Project.BuildSucceeded @@ -3606,9 +3695,9 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , PullRequestCommitChanged (PullRequestId 1) (Sha "4ba") ] -- For this test, we assume all integrations and pushes succeed. @@ -3688,9 +3777,9 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") ] @@ -3758,9 +3847,9 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed (Just "ci.example.com/1ab")) ] results = defaultResults { resultIntegrate = [ Right (Sha "1ab") @@ -3842,8 +3931,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" ] results = defaultResults { resultIntegrate = [ Right (Sha "1ab") , Left (IntegrationFailure (BaseBranch "testing/1") WrongFixups) @@ -3893,11 +3982,11 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "tyrell") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , PullRequestCommitChanged (PullRequestId 2) (Sha "c2d") - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" ] results = defaultResults { resultIntegrate = [ Right (Sha "1ab") , Left (IntegrationFailure (BaseBranch "testing/1") WrongFixups) @@ -3972,8 +4061,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) , BuildStatusChanged (Sha "2cd") "default" (Project.BuildSucceeded) , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") @@ -4022,8 +4111,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" -- Build of #2 finishes before build of #1 , BuildStatusChanged (Sha "2cd") "default" (Project.BuildSucceeded) , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) @@ -4073,8 +4162,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "2cd") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "22e") "default" (Project.BuildFailed Nothing) @@ -4139,8 +4228,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" -- Build of #2 finishes before build of #1 , BuildStatusChanged (Sha "2cd") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed Nothing) @@ -4207,8 +4296,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") , BuildStatusChanged (Sha "2cd") "default" (Project.BuildFailed Nothing) @@ -4257,8 +4346,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2cd") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "1ab") "default" Project.BuildSucceeded , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") @@ -4308,8 +4397,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "2cd") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "22e") "default" Project.BuildSucceeded @@ -4368,8 +4457,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2cd") "default" Project.BuildSucceeded , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed Nothing) , BuildStatusChanged (Sha "22e") "default" Project.BuildSucceeded @@ -4428,8 +4517,8 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2cd") "default" Project.BuildSucceeded , PullRequestClosed (PullRequestId 1) , BuildStatusChanged (Sha "22e") "default" Project.BuildSucceeded @@ -4495,31 +4584,31 @@ main = hspec $ do $ Project.emptyProjectState events = [ BuildStatusChanged (Sha "ab1") "default" (Project.BuildSucceeded) -- PR#1 sha, ignored - , CommentAdded (PullRequestId 1) "deckard" "@someone Thanks for your review." - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 1) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 1) "bot" "\nRebased as 1ab, waiting for CI …" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "bot" "\nPull request approved for merge behind 1 PR." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@someone Thanks for your review." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 1) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 1) "bot" Nothing "\nRebased as 1ab, waiting for CI …" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "bot" Nothing "\nPull request approved for merge behind 1 PR." , BuildStatusChanged (Sha "ef3") "default" (Project.BuildSucceeded) -- PR#3 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildPending) -- same status, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") -- dup! - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/1ab) started." - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "bot" "\nPull request approved for merge behind 2 PRs." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/1ab) started." + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "bot" Nothing "\nPull request approved for merge behind 2 PRs." , BuildStatusChanged (Sha "cd2") "default" (Project.BuildSucceeded) -- PR#2 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#1 , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") , PullRequestClosed (PullRequestId 1) - , CommentAdded (PullRequestId 2) "bot" "\nRebased as 2bc, waiting for CI …" + , CommentAdded (PullRequestId 2) "bot" Nothing "\nRebased as 2bc, waiting for CI …" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") - , CommentAdded (PullRequestId 2) "bot" "\n[CI job :yellow_circle:](example.com/2bc) started." + , CommentAdded (PullRequestId 2) "bot" Nothing "\n[CI job :yellow_circle:](example.com/2bc) started." , BuildStatusChanged (Sha "36a") "default" (Project.BuildSucceeded) -- arbitrary sha, ignored , BuildStatusChanged (Sha "2bc") "default" (Project.BuildSucceeded) -- PR#2 , PullRequestCommitChanged (PullRequestId 2) (Sha "2bc") , PullRequestClosed (PullRequestId 2) - , CommentAdded (PullRequestId 3) "bot" "\nRebased as 3cd, waiting for CI …" + , CommentAdded (PullRequestId 3) "bot" Nothing "\nRebased as 3cd, waiting for CI …" , BuildStatusChanged (Sha "3cd") "default" (Project.BuildStarted "example.com/3cd") , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- PR#3 , PullRequestCommitChanged (PullRequestId 3) (Sha "3cd") @@ -4597,31 +4686,31 @@ main = hspec $ do $ Project.emptyProjectState events = [ BuildStatusChanged (Sha "ab9") "default" (Project.BuildSucceeded) -- PR#9 sha, ignored - , CommentAdded (PullRequestId 9) "deckard" "@someone Thanks for your review." - , CommentAdded (PullRequestId 9) "deckard" "@bot merge" - , CommentAdded (PullRequestId 9) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 9) "bot" "\nRebased as 1ab, waiting for CI …" - , CommentAdded (PullRequestId 8) "deckard" "@bot merge" - , CommentAdded (PullRequestId 8) "bot" "\nPull request approved for merge behind 1 PR." + , CommentAdded (PullRequestId 9) "deckard" Nothing "@someone Thanks for your review." + , CommentAdded (PullRequestId 9) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 9) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 9) "bot" Nothing "\nRebased as 1ab, waiting for CI …" + , CommentAdded (PullRequestId 8) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 8) "bot" Nothing "\nPull request approved for merge behind 1 PR." , BuildStatusChanged (Sha "ef7") "default" (Project.BuildSucceeded) -- PR#7 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildPending) -- same status, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") - , CommentAdded (PullRequestId 9) "bot" "\n[CI job :yellow_circle:](example.com/1ab) started." - , CommentAdded (PullRequestId 7) "deckard" "@bot merge" - , CommentAdded (PullRequestId 7) "bot" "\nPull request approved for merge behind 2 PRs." + , CommentAdded (PullRequestId 9) "bot" Nothing "\n[CI job :yellow_circle:](example.com/1ab) started." + , CommentAdded (PullRequestId 7) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 7) "bot" Nothing "\nPull request approved for merge behind 2 PRs." , BuildStatusChanged (Sha "cd8") "default" (Project.BuildSucceeded) -- PR#8 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#9 , PullRequestCommitChanged (PullRequestId 9) (Sha "1ab") , PullRequestClosed (PullRequestId 9) - , CommentAdded (PullRequestId 8) "bot" "\nRebased as 2bc, waiting for CI …" + , CommentAdded (PullRequestId 8) "bot" Nothing "\nRebased as 2bc, waiting for CI …" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") - , CommentAdded (PullRequestId 8) "bot" "\n[CI job :yellow_circle:](example.com/2bc) started." + , CommentAdded (PullRequestId 8) "bot" Nothing "\n[CI job :yellow_circle:](example.com/2bc) started." , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- testing build passed on PR#7 , BuildStatusChanged (Sha "36a") "default" (Project.BuildSucceeded) -- arbitrary sha, ignored , BuildStatusChanged (Sha "2bc") "default" (Project.BuildFailed (Just "example.com/2bc")) -- PR#8 , BuildStatusChanged (Sha "2bc") "default" (Project.BuildFailed (Just "example.com/2bc")) -- dup! - , CommentAdded (PullRequestId 8) "bot" "\nThe [build failed :x:](example.com/2bc)" - , CommentAdded (PullRequestId 7) "bot" "\nRebased as 3cd, waiting for CI …" + , CommentAdded (PullRequestId 8) "bot" Nothing "\nThe [build failed :x:](example.com/2bc)" + , CommentAdded (PullRequestId 7) "bot" Nothing "\nRebased as 3cd, waiting for CI …" , BuildStatusChanged (Sha "3ef") "default" (Project.BuildStarted "example.com/3ef") , BuildStatusChanged (Sha "3ef") "default" (Project.BuildSucceeded) -- testing build passed on PR#7 , PullRequestCommitChanged (PullRequestId 7) (Sha "3ef") @@ -4712,33 +4801,33 @@ main = hspec $ do $ Project.emptyProjectState events = [ BuildStatusChanged (Sha "ab1") "default" (Project.BuildSucceeded) -- PR#1 sha, ignored - , CommentAdded (PullRequestId 1) "deckard" "@someone Thanks for your review." - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 1) "bot" "\nPull request approved for merge, rebasing now." - , CommentAdded (PullRequestId 1) "bot" "\nRebased as 1ab, waiting for CI …" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "bot" "\nPull request approved for merge behind 1 PR." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@someone Thanks for your review." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 1) "bot" Nothing "\nPull request approved for merge, rebasing now." + , CommentAdded (PullRequestId 1) "bot" Nothing "\nRebased as 1ab, waiting for CI …" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "bot" Nothing "\nPull request approved for merge behind 1 PR." , BuildStatusChanged (Sha "ef3") "default" (Project.BuildSucceeded) -- PR#3 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildPending) -- same status, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") -- dup! - , CommentAdded (PullRequestId 1) "bot" "\n[CI job :yellow_circle:](example.com/1ab) started." - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "bot" "\nPull request approved for merge behind 2 PRs." - , CommentAdded (PullRequestId 4) "deckard" "@bot merge" - , CommentAdded (PullRequestId 4) "bot" "\nPull request approved for merge behind 3 PRs." + , CommentAdded (PullRequestId 1) "bot" Nothing "\n[CI job :yellow_circle:](example.com/1ab) started." + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "bot" Nothing "\nPull request approved for merge behind 2 PRs." + , CommentAdded (PullRequestId 4) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 4) "bot" Nothing "\nPull request approved for merge behind 3 PRs." , BuildStatusChanged (Sha "cd2") "default" (Project.BuildSucceeded) -- PR#2 sha, ignored , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#1 , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") , PullRequestClosed (PullRequestId 1) - , CommentAdded (PullRequestId 2) "bot" "\nRebased as 2bc, waiting for CI …" + , CommentAdded (PullRequestId 2) "bot" Nothing "\nRebased as 2bc, waiting for CI …" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") - , CommentAdded (PullRequestId 2) "bot" "\n[CI job :yellow_circle:](example.com/2bc) started." + , CommentAdded (PullRequestId 2) "bot" Nothing "\n[CI job :yellow_circle:](example.com/2bc) started." , BuildStatusChanged (Sha "36a") "default" (Project.BuildSucceeded) -- arbitrary sha, ignored , BuildStatusChanged (Sha "2bc") "default" (Project.BuildSucceeded) -- PR#2 , PullRequestCommitChanged (PullRequestId 2) (Sha "2bc") , PullRequestClosed (PullRequestId 2) - , CommentAdded (PullRequestId 3) "bot" "\nRebased as 3cd, waiting for CI …" + , CommentAdded (PullRequestId 3) "bot" Nothing "\nRebased as 3cd, waiting for CI …" , BuildStatusChanged (Sha "3cd") "default" (Project.BuildStarted "example.com/3cd") , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- PR#3 , PullRequestCommitChanged (PullRequestId 3) (Sha "3cd") @@ -4835,12 +4924,12 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") , BuildStatusChanged (Sha "2bc") "default" (Project.BuildSucceeded) -- PR#2 - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 3) "deckard" "@bot merge" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "3cd") "default" (Project.BuildStarted "example.com/3cd") , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- PR#2 second , PullRequestCommitChanged (PullRequestId 2) (Sha "3cd") @@ -4923,15 +5012,15 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") , BuildStatusChanged (Sha "2bc") "default" (Project.BuildSucceeded) -- PR#2 , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#1 , PullRequestCommitChanged (PullRequestId 1) (Sha "1ab") , PullRequestCommitChanged (PullRequestId 2) (Sha "2bc") - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" ] -- For this test, we assume all integrations and pushes succeed. results = defaultResults { resultIntegrate = [ Right (Sha "1ab") @@ -4977,9 +5066,9 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" - , CommentAdded (PullRequestId 1) "deckard" "@bot merge and deploy to production" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge and deploy to production" , BuildStatusChanged (Sha "2bc") "default" Project.BuildSucceeded -- PR#2 ignored, due to remerge , BuildStatusChanged (Sha "1ab") "default" Project.BuildSucceeded -- PR#1 ignored, due to remerge , BuildStatusChanged (Sha "3cd") "default" Project.BuildSucceeded -- PR#2 @@ -5049,11 +5138,11 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@someone Thanks for your review." - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@someone Thanks for your review." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge with priority" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge with priority" , BuildStatusChanged (Sha "3cd") "default" (Project.BuildStarted "example.com/3cd") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#1, ignored , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- PR#3 @@ -5151,11 +5240,11 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 3) (Branch "trd") masterBranch (Sha "ef3") "Third PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@someone Thanks for your review." - , CommentAdded (PullRequestId 1) "deckard" "@bot merge" - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@someone Thanks for your review." + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") - , CommentAdded (PullRequestId 3) "deckard" "@bot merge and deploy to production with priority" + , CommentAdded (PullRequestId 3) "deckard" Nothing "@bot merge and deploy to production with priority" , BuildStatusChanged (Sha "3cd") "default" (Project.BuildStarted "example.com/3cd") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildSucceeded) -- PR#1, ignored , BuildStatusChanged (Sha "3cd") "default" (Project.BuildSucceeded) -- PR#3 @@ -5256,12 +5345,12 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed (Just "example.com/1ab")) - , CommentAdded (PullRequestId 2) "deckard" "@bot merge" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") - , CommentAdded (PullRequestId 1) "deckard" "@bot retry with priority" + , CommentAdded (PullRequestId 1) "deckard" Nothing "@bot retry with priority" , BuildStatusChanged (Sha "1cd") "default" (Project.BuildStarted "example.com/1cd") , BuildStatusChanged (Sha "1cd") "default" (Project.BuildSucceeded) -- PR#2 , PullRequestCommitChanged (PullRequestId 1) (Sha "1cd") @@ -5341,10 +5430,10 @@ main = hspec $ do $ Project.insertPullRequest (PullRequestId 2) (Branch "snd") masterBranch (Sha "cd2") "Second PR" (Username "rachael") $ Project.emptyProjectState events = - [ CommentAdded (PullRequestId 1) "deckard" "@bot merge" + [ CommentAdded (PullRequestId 1) "deckard" Nothing "@bot merge" , BuildStatusChanged (Sha "1ab") "default" (Project.BuildStarted "example.com/1ab") , BuildStatusChanged (Sha "1ab") "default" (Project.BuildFailed (Just "example.com/1ab")) - , CommentAdded (PullRequestId 2) "deckard" "@bot merge with priority" + , CommentAdded (PullRequestId 2) "deckard" Nothing "@bot merge with priority" , BuildStatusChanged (Sha "2bc") "default" (Project.BuildStarted "example.com/2bc") , BuildStatusChanged (Sha "2bc") "default" (Project.BuildSucceeded) -- PR#1 , PullRequestCommitChanged (PullRequestId 2) (Sha "2bc")