Commit 433cc965 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'display-post-receive-warnings' into 'master'

Display post receive warnings from Rails

See merge request gitlab-org/gitlab-shell!288
parents 0a0388cc 84d96bed
...@@ -24,10 +24,11 @@ class GitlabPostReceive ...@@ -24,10 +24,11 @@ class GitlabPostReceive
end end
return false unless response return false unless response
print_broadcast_message(response['broadcast_message']) if response['broadcast_message'] print_formatted_alert_message(response['broadcast_message']) if response['broadcast_message']
print_merge_request_links(response['merge_request_urls']) if response['merge_request_urls'] print_merge_request_links(response['merge_request_urls']) if response['merge_request_urls']
puts response['redirected_message'] if response['redirected_message'] puts response['redirected_message'] if response['redirected_message']
puts response['project_created_message'] if response['project_created_message'] puts response['project_created_message'] if response['project_created_message']
print_warnings(response['warnings']) if response['warnings']
response['reference_counter_decreased'] response['reference_counter_decreased']
rescue GitlabNet::ApiUnreachableError rescue GitlabNet::ApiUnreachableError
...@@ -59,7 +60,12 @@ class GitlabPostReceive ...@@ -59,7 +60,12 @@ class GitlabPostReceive
puts puts
end end
def print_broadcast_message(message) def print_warnings(warnings)
message = "WARNINGS:\n#{warnings}"
print_formatted_alert_message(message)
end
def print_formatted_alert_message(message)
# A standard terminal window is (at least) 80 characters wide. # A standard terminal window is (at least) 80 characters wide.
total_width = 80 total_width = 80
......
...@@ -64,7 +64,7 @@ describe GitlabPostReceive do ...@@ -64,7 +64,7 @@ describe GitlabPostReceive do
context 'when contains long url string at end' do context 'when contains long url string at end' do
let(:broadcast_message) { "test " * 10 + "message " * 10 + "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url" } let(:broadcast_message) { "test " * 10 + "message " * 10 + "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url" }
it 'doesnt truncate url' do it 'doesnt truncate url' do
expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response)
assert_broadcast_message_printed_keep_long_url_end(gitlab_post_receive) assert_broadcast_message_printed_keep_long_url_end(gitlab_post_receive)
assert_new_mr_printed(gitlab_post_receive) assert_new_mr_printed(gitlab_post_receive)
...@@ -76,7 +76,7 @@ describe GitlabPostReceive do ...@@ -76,7 +76,7 @@ describe GitlabPostReceive do
context 'when contains long url string at start' do context 'when contains long url string at start' do
let(:broadcast_message) { "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url " + "test " * 10 + "message " * 11} let(:broadcast_message) { "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url " + "test " * 10 + "message " * 11}
it 'doesnt truncate url' do it 'doesnt truncate url' do
expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response)
assert_broadcast_message_printed_keep_long_url_start(gitlab_post_receive) assert_broadcast_message_printed_keep_long_url_start(gitlab_post_receive)
assert_new_mr_printed(gitlab_post_receive) assert_new_mr_printed(gitlab_post_receive)
...@@ -88,7 +88,7 @@ describe GitlabPostReceive do ...@@ -88,7 +88,7 @@ describe GitlabPostReceive do
context 'when contains long url string in middle' do context 'when contains long url string in middle' do
let(:broadcast_message) { "test " * 11 + "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url " + "message " * 11} let(:broadcast_message) { "test " * 11 + "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url " + "message " * 11}
it 'doesnt truncate url' do it 'doesnt truncate url' do
expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response) expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response)
assert_broadcast_message_printed_keep_long_url_middle(gitlab_post_receive) assert_broadcast_message_printed_keep_long_url_middle(gitlab_post_receive)
assert_new_mr_printed(gitlab_post_receive) assert_new_mr_printed(gitlab_post_receive)
...@@ -96,7 +96,21 @@ describe GitlabPostReceive do ...@@ -96,7 +96,21 @@ describe GitlabPostReceive do
expect(gitlab_post_receive.exec).to eq(true) expect(gitlab_post_receive.exec).to eq(true)
end end
end end
end
context 'when warnings are present' do
let(:response) do
{
'reference_counter_decreased' => true,
'warnings' => 'My warning message'
}
end
it 'treats the warning as a broadcast message' do
expect_any_instance_of(GitlabNet).to receive(:post_receive).and_return(response)
expect(gitlab_post_receive).to receive(:print_formatted_alert_message).with("WARNINGS:\nMy warning message")
expect(gitlab_post_receive.exec).to eq(true)
end
end end
context 'when redirected message available' do context 'when redirected message available' do
...@@ -199,7 +213,7 @@ describe GitlabPostReceive do ...@@ -199,7 +213,7 @@ describe GitlabPostReceive do
expect(gitlab_post_receive).to receive(:puts).with( expect(gitlab_post_receive).to receive(:puts).with(
" message message message message message message message message" " message message message message message message message message"
).ordered ).ordered
expect(gitlab_post_receive).to receive(:puts).with( expect(gitlab_post_receive).to receive(:puts).with(
"https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url" "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url"
).ordered ).ordered
...@@ -216,7 +230,7 @@ describe GitlabPostReceive do ...@@ -216,7 +230,7 @@ describe GitlabPostReceive do
"========================================================================" "========================================================================"
).ordered ).ordered
expect(gitlab_post_receive).to receive(:puts).ordered expect(gitlab_post_receive).to receive(:puts).ordered
expect(gitlab_post_receive).to receive(:puts).with( expect(gitlab_post_receive).to receive(:puts).with(
"https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url" "https://localhost:5000/test/a/really/long/url/that/is/in/the/broadcast/message/do-not-truncate-when-url"
).ordered ).ordered
...@@ -245,7 +259,7 @@ describe GitlabPostReceive do ...@@ -245,7 +259,7 @@ describe GitlabPostReceive do
"========================================================================" "========================================================================"
).ordered ).ordered
expect(gitlab_post_receive).to receive(:puts).ordered expect(gitlab_post_receive).to receive(:puts).ordered
expect(gitlab_post_receive).to receive(:puts).with( expect(gitlab_post_receive).to receive(:puts).with(
" test test test test test test test test test test test" " test test test test test test test test test test test"
).ordered ).ordered
......
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