Conversation
ReinierMaas
left a comment
There was a problem hiding this comment.
The overall design looks good to me. I just have style pointers but nothing really major. Using the free monad to encapsulate getting the timestamps nicely abstracts it for the testing! And the additional tests also look extensive.
src/Logic.hs
Outdated
| isApproved <- | ||
| if isJust approvalType | ||
| then isReviewer author | ||
| else pure False | ||
| day <- dayOfWeek . utctDay <$> getDateTime | ||
| if isApproved | ||
| then -- The PR has now been approved by the author of the comment. | ||
|
|
||
| case fromJust approvalType of | ||
| approval | isMergeOnFriday approval || day /= Friday -> handleCommentAdded' projectConfig prId author state pr approval | ||
| other -> do | ||
| () <- leaveComment prId ("Merging is not allowed on Fridays. To override this behaviour use the command `" `Text.append` Pr.displayApproval other `Text.append` " on Friday`.") |
There was a problem hiding this comment.
Text can be appended with <>. I also see that the lines are quite long we normally restrict this to 100 chars width.
We can combine these multiple if and case statements. When a pull request is approved you know that the fromJust won't fail.
case isApproved of
True | your filter here -> handleCommentAdded
True -> leave comment
False -> pure stateThere was a problem hiding this comment.
Should we allow merge on Friday on other days?
fatho
left a comment
There was a problem hiding this comment.
Your first PR 🎉 Besides Reinier's remarks, I think the design can also still be simplified/future-proofed (see below).
src/Logic.hs
Outdated
| -- reversed all "merge and xxx" commands would be detected as a Merge | ||
| -- command. | ||
| cases = | ||
| [ (" merge and deploy on friday", MergeAndDeployOnFriday), |
There was a problem hiding this comment.
A minor thing: I wonder if "on" is a good choice of words here, as it could be mistaken for a scheduled merge (which we don't support). Maybe "even on"? Not really sure, would otherwise also be fine.
| if isJust approvalType | ||
| then isReviewer author | ||
| else pure False | ||
| day <- dayOfWeek . utctDay <$> getDateTime |
There was a problem hiding this comment.
This gets the date in the UTC time zone. It will be Friday two hours later in Europe/Amsterdam than in UTC when DST is in effect. Is that intentional? (And also, does it make sense to pick midnight as the boundary? Is Saturday 04:00 an okay time to merge things?)
There was a problem hiding this comment.
Thanks for the feedback. What would be your proposal for updating the nudge? Should we detect whether it is Friday Anywhere on Earth? (Start at UTC+14 / End at UTC-12)
Using AoE as the dedicated time range would already disallow the merge to proceed on Thursday afternoon in Europe/Amsterdam when DST is in effect. Which might be a valid moment for the stop merging nudge.
There was a problem hiding this comment.
Good point about the timezone! I think just detecting Friday at our location is good enough (maybe the timezone could be made configurable, but that's about it).
Is Saturday 04:00 an okay time to merge things
It is not. But the feature is intended as a guardrail against accidents, not a foolproof method of preventing all untimely merges, and I'd just assume that there won't be accidental merges on Saturday at 04:00.
We might want to just cover the whole weekend, but I think nighttime can be ignored for the moment.
There was a problem hiding this comment.
What would be your proposal for updating the nudge?
If it’s just a nudge on Fridays for people working in Europe/Amsterdam, I would just ignore the issue and keep it like this.
At the expense of scope creep, maybe a nicer solution that also covers the weekend is to provide a time range in the configuration file. It could include a start day of week + time of day and an end day of week + time of day, and a time zone in which to interpret them.
9ff2d56 to
bca056f
Compare
bca056f to
246664f
Compare
06e2040 to
0a8d68f
Compare
fatho
left a comment
There was a problem hiding this comment.
Just some small things from my side:
src/Logic.hs
Outdated
| pure state | ||
| (other, OnFriday) -> do | ||
| () <- leaveComment prId ("Your merge request has been denied because \ | ||
| \it not Friday. Run " <> |
| (other, OnFriday) -> do | ||
| () <- leaveComment prId ("Your merge request has been denied because \ | ||
| \it not Friday. Run " <> | ||
| Pr.displayApproval other <> " instead") |
There was a problem hiding this comment.
Good idea rejecting this as well so that people don't get conditioned to just always using the more powerful command 👍
src/Logic.hs
Outdated
| -- For now Friday at UTC+0 is good enough. | ||
| -- See https://github.com/channable/hoff/pull/95 for caveats and improvement ideas. |
There was a problem hiding this comment.
Can you open a new hoff issue about potentially making this more configurable (e.g. the timezone and the range)?
Then we'll also immediately have a good first issue for the next person joining :-)
ReinierMaas
left a comment
There was a problem hiding this comment.
LGTM! After resolving Fabians comments and one nit. Thanks for implementing this!
src/Logic.hs
Outdated
| -- If the pull request is not in the state, ignore the comment. | ||
| Nothing -> pure state | ||
|
|
||
| handleMergeRequested :: ProjectConfiguration -> PullRequestId -> Username -> ProjectState -> PullRequest -> ApprovedFor -> Action ProjectState |
ff60f7f to
6e79bcb
Compare
|
@OpsBotPrime merge |
|
Pull request approved for merge by @xrvdg, rebasing now. |
Approved-by: xrvdg Auto-deploy: false
|
Rebased as 991e117, waiting for CI … |
This pull request adds (non-configurable) No-Deploy-Friday-Nudge functionality (#56) to Hoff.