8000 Allow extra whitespace in merge commands by ReinierMaas · Pull Request #108 · channable/hoff · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow extra whitespace in merge commands #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and conta 8000 ct 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

Merged
merged 3 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .semaphore/prologue.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Shared commands for the set-up phase of jobs

# This file is NOT usable with Semaphore's "commands_file" property, as this
# puts all the comments in this file in the build output and requires us to
# write all build steps on one line each. Instead, this file must be executed
# in the build pipelines where we use it.

# We don't use `set -x` here to show the run commands, because this would show
# authentication tokens in the build output. Instead, `set -v` prints the
# commands "as they are read".
# We do want to exit immediately after encountering an error.
# We also cannot use "set -u", as Semaphore's tooling uses unset variables in
# some places (which we can't change).
set -evo pipefail

# Clear disk space by removing docker related services, mounts and files.
sudo systemctl stop docker.service docker.socket

if [[ $(findmnt /var/lib/docker) ]]; then
sudo umount /var/lib/docker
fi

if [[ -e "/dev/nbd0" ]]; then
sudo qemu-nbd --disconnect /dev/nbd0
fi

# Clear disk space by removing tooling that we don't use. This is needed to run
# on the smallest machine type Semaphore offers, as this machine type has too
# little disk space to build the package due to a lot of extra tooling that we
# don't need. Removing these directories clears about 4 GiB.
sudo rm -rf \
/home/semaphore/.rbenv \
/home/semaphore/.kerl \
/home/semaphore/.nvm \
/home/semaphore/.phpbrew \
/home/semaphore/.kiex \
/opt/google \
/opt/firefox-esr \
/opt/firefox-esr-prev \
/usr/local/golang \
/mnt/docker.qcow2
3 changes: 3 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ blocks:

- "checkout"

# Free space on the disk in order to save the nix store and error on build failures.
- .semaphore/prologue.sh

# Restore `/nix` cache. Create the directory first, otherwise we encounter
# permission errors. We do this because the Semaphore cache is faster than
# both Cachix and cache.nixos.org.
Expand Down
15 changes: 11 additions & 4 deletions src/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,20 @@ isSuccess _ = False
parseMergeCommand :: TriggerConfiguration -> Text -> ParseResult (ApprovedFor, MergeWindow)
parseMergeCommand config message =
let
messageCaseFold = Text.toCaseFold $ Text.strip message
prefixCaseFold = Text.toCaseFold $ Config.commentPrefix config
mentioned = prefixCaseFold `Text.isPrefixOf` messageCaseFold
normalise :: Text -> Text
normalise msg =
-- Normalise commands with extra spaces between them (`@Bot merge and tag` | `merge and tag`)
let multiWhitespaceStripped = Text.unwords $ filter (not . Text.null) $ Text.words msg
-- Standardise the casing in order to match commands with different casing (@Bot Merge)
in Text.toCaseFold multiWhitespaceStripped

messageNormalised = normalise message
prefixNormalised = normalise $ Config.commentPrefix config
mentioned = prefixNormalised `Text.isPrefixOf` messageNormalised
-- Determines if any individual mention matches the given command message
matchWith :: Text -> Bool
matchWith msg = any (Text.isPrefixOf msg) mentions
where mentions = Text.splitOn prefixCaseFold messageCaseFold
where mentions = Text.splitOn prefixNormalised messageNormalised
-- Check if the prefix followed by ` merge [and {deploy,tag}] [on friday]` occurs within the message.
-- We opt to include the space here, instead of making it part of the
-- prefix, because having the trailing space in config is something that is
Expand Down
40 changes: 40 additions & 0 deletions tests/Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,46 @@ main = hspec $ do
fromJust (Project.lookupPullRequest prId state') `shouldSatisfy`
(\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0))

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"

results = defaultResults { resultIntegrate = [Right (Sha "def2345")] }
(state', actions) = runActionCustom results $ handleEventTest event state

actions `shouldBe`
[ AIsReviewer "deckard"
, ALeaveComment prId "Pull request approved for merge and tag by @deckard, rebasing now."
, ATryIntegrate "Merge #1: Untitled\n\nApproved-by: deckard\nAuto-deploy: false\n" (Branch "refs/pull/1/head", Sha "abc1234") False
, ALeaveComment prId "Rebased as def2345, waiting for CI \x2026"
]

fromJust (Project.lookupPullRequest prId state') `shouldSatisfy`
(\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0))

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"

results = defaultResults { resultIntegrate = [Right (Sha "def2345")] }
(state', actions) = runActionCustom results $ handleEventTest event state

actions `shouldBe`
[ AIsReviewer "deckard"
, ALeaveComment prId "Pull request approved for merge and tag by @deckard, rebasing now."
, ATryIntegrate "Merge #1: Untitled\n\nApproved-by: deckard\nAuto-deploy: false\n" (Branch "refs/pull/1/head", Sha "abc1234") False
, ALeaveComment prId "Rebased as def2345, waiting for CI \x2026"
]

fromJust (Project.lookupPullRequest prId state') `shouldSatisfy`
(\pr -> Project.approval pr == Just (Approval (Username "deckard") Project.MergeAndTag 0))

it "recognizes 'merge and tag on friday' command" $ do
let
prId = PullRequestId 1
Expand Down
0