Skip to content

Conversation

@rlycx
Copy link

@rlycx rlycx commented Mar 11, 2022

Makes hoff give feedback when an invalid command is issued.

@rlycx rlycx linked an issue Mar 11, 2022 that may be closed by this pull request
@rlycx rlycx requested a review from bertptrs March 14, 2022 08:26
Copy link

@bertptrs bertptrs left a 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.

@bertptrs bertptrs requested a review from joris-burgers March 14, 2022 08:29
Copy link

@joris-burgers joris-burgers left a 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:

hoff/tests/Spec.hs

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`."
]

@rlycx rlycx requested a review from joris-burgers March 14, 2022 10:25
Copy link

@joris-burgers joris-burgers left a 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.

Comment on lines 372 to 375
data ParseResult a
= Success a
| Unknown Text
| Ignored

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.")

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.

Copy link
Author

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

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.

Copy link
Member

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.

Copy link
Author

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. :/

@rlycx rlycx requested a review from joris-burgers March 14, 2022 14:44
Copy link

@joris-burgers joris-burgers left a 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.

@rlycx rlycx requested a review from joris-burgers March 14, 2022 15:30
Copy link

@joris-burgers joris-burgers left a 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
Comment on lines 373 to 374
-- | consumer of `parseMergeCommand` to inspect the reason why a message
-- | was considered invalid.

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed :)

@rlycx rlycx requested a review from joris-burgers March 14, 2022 16:29
Copy link

@joris-burgers joris-burgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rlycx
Copy link
Author

rlycx commented Mar 14, 2022

Thanks for all the feedback! :)

@rlycx
Copy link
Author

rlycx commented Mar 16, 2022

@OpsBotPrime merge

@OpsBotPrime
Copy link

Pull request approved for merge by @RileyApeldoorn, rebasing now.

Approved-by: RileyApeldoorn
Auto-deploy: false
@OpsBotPrime
Copy link

Rebased as 0bd569a, waiting for CI …

@OpsBotPrime OpsBotPrime merged commit 0bd569a into master Mar 16, 2022
@OpsBotPrime OpsBotPrime deleted the report-invalid-command branch March 16, 2022 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reply on unknown commands

5 participants