Commit 4d226dec authored by Yorick Peterse's avatar Yorick Peterse

Support newlines for the chatops "run" command

We ran into this as part of
https://gitlab.com/gitlab-com/gl-infra/delivery/-/issues/1622. By
enabling the /m mode, the dot operator matches newlines. This allows the
use of newlines when using the "run" command.
parent 6a46a8f1
---
title: Support newlines for the chatops "run" command
merge_request: 56668
author:
type: changed
......@@ -5,7 +5,7 @@ module Gitlab
# Slash command for triggering chatops jobs.
class Run < BaseCommand
def self.match(text)
/\Arun\s+(?<command>\S+)(\s+(?<arguments>.+))?\z/.match(text)
/\Arun\s+(?<command>\S+)(\s+(?<arguments>.+))?\z/m.match(text)
end
def self.help_message
......
......@@ -3,6 +3,26 @@
require 'spec_helper'
RSpec.describe Gitlab::SlashCommands::Run do
describe '.match' do
it 'returns true for a run command' do
expect(described_class.match('run foo')).to be_an_instance_of(MatchData)
end
it 'returns true for a run command with arguments' do
expect(described_class.match('run foo bar baz'))
.to be_an_instance_of(MatchData)
end
it 'returns true for a command containing newlines' do
expect(described_class.match("run foo\nbar\nbaz"))
.to be_an_instance_of(MatchData)
end
it 'returns false for an unrelated command' do
expect(described_class.match('foo bar')).to be_nil
end
end
describe '.available?' do
it 'returns true when builds are enabled for the project' do
project = double(:project, builds_enabled?: true)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment