-
Notifications
You must be signed in to change notification settings - Fork 4
Reply on merge command parse failure #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bertptrs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks alright to me but I also don't really speak Haskell. I'll tag a second reviewer.
joris-burgers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this will never leave a comment that the command was not recognized.
It can also be found by adding a test, like this one:
Lines 829 to 842 in 7f0235c
| it "doesn't allow 'merge and tag' command on Friday" $ do | |
| let | |
| prId = PullRequestId 1 | |
| state = singlePullRequestState prId (Branch "p") masterBranch (Sha "abc1234") "tyrell" | |
| event = CommentAdded prId "deckard" "@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 | |
| actions `shouldBe` | |
| [ AIsReviewer "deckard" | |
| , ALeaveComment prId "Your merge request has been denied, because merging on Fridays is not recommended. To override this behaviour use the command `merge and tag on Friday`." | |
| ] |
joris-burgers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks a lot better, I left some smaller questions.
| data ParseResult a | ||
| = Success a | ||
| | Unknown Text | ||
| | Ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice datatype, can you comment it a bit more, as well as the isSuccess function.
src/Logic.hs
Outdated
| -- The bot was mentioned but encountered an invalid command, report error and | ||
| -- take not further action | ||
| Unknown command -> do | ||
| () <- leaveComment prId ("`" <> command <> "` was not recognized as a valid command.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but could this trigger a comment loop? Say I comment @bot megre, the comment will be included in the response and the @bot would trigger Hoff again. Could that happen or are we protected against that? Otherwise we can just reply that the last comment was not recognized, people will see what they typed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be alright because it uses Text.isPrefixOf, but just to be safe, I'll strip the prefix from command before putting it in the comment.
src/Logic.hs
Outdated
| () <- leaveComment prId ("`" <> command <> "` was not recognized as a valid command.") | ||
| pure state | ||
| -- Cases where the parse was successful AND the author is a reviewer | ||
| Success command | isApproved -> case command of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I find this guard a bit subtle for the security check. Could you make it an explicit if, that way changing the order of the guards doesn't become a security concern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you could attach both guards to the same branch, i.e.
case .. of
...
Success command
| isApproved -> ...
| otherwise -> ...which IMO is the nicer style even in the absence of security concerns, as it makes it very clear which sub-cases there are for the Success case.
Also, isApproved seems to be the conjunction of the success case and the author-is-reviewer case. But you're already checking the success case by explicit pattern matching now. So just checking for isReviewer in the guard would be even cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think I'll adopt the style mentioned by @fatho :).
Regarding isReviewer, putting it in the guard makes sense, but the function returns Action, so it can't be done within the guard itself (as far as I know), so doing isSuccess and also pattern matching on the Success case is a bit of a compromise to keep the bot from performing an Action every time it reads a comment regardless of whether it parsed a command. :/
joris-burgers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor style points, but otherwise LGTM.
joris-burgers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing, otherwise LGTM.
src/Logic.hs
Outdated
| -- | consumer of `parseMergeCommand` to inspect the reason why a message | ||
| -- | was considered invalid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These pipes should only go in front on the first comment. See https://haskell-haddock.readthedocs.io/en/latest/markup.html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed :)
joris-burgers
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
Thanks for all the feedback! :) |
|
@OpsBotPrime merge |
|
Pull request approved for merge by @RileyApeldoorn, rebasing now. |
Approved-by: RileyApeldoorn Auto-deploy: false
|
Rebased as 0bd569a, waiting for CI … |
Makes hoff give feedback when an invalid command is issued.