diff options
| author | Douwe Maan <douwe@gitlab.com> | 2018-06-04 08:31:21 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2018-06-04 08:31:21 +0000 |
| commit | 6a15f1db609acd6b7dadb2a88d4f5aff3500f160 (patch) | |
| tree | 179448aaf0f7bf6f975ed7bb0cf261f5f8d89054 /lib | |
| parent | 4bc16881347b53709c0f28a3ac2ed3a96d7051b9 (diff) | |
| parent | b0b8627d1e1ee0748f1468ce9489357dab482fbb (diff) | |
| download | gitlab-shell-6a15f1db609acd6b7dadb2a88d4f5aff3500f160.tar.gz | |
Merge branch 'issue-29006' into 'master'v7.1.4
allow long strings to remain intact while parsing broadcast message
See merge request gitlab-org/gitlab-shell!202
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab_post_receive.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/gitlab_post_receive.rb b/lib/gitlab_post_receive.rb index 6009b19..cb9931d 100644 --- a/lib/gitlab_post_receive.rb +++ b/lib/gitlab_post_receive.rb @@ -75,10 +75,14 @@ class GitlabPostReceive # Automatically wrap message at text_width (= 68) characters: # Splits the message up into the longest possible chunks matching # "<between 0 and text_width characters><space or end-of-line>". - # The last result is always an empty string (0 chars and the end-of-line), - # so drop that. - # message.scan returns a nested array of capture groups, so flatten. - lines = message.scan(/(.{,#{text_width}})(?:\s|$)/)[0...-1].flatten + + msg_start_idx = 0 + lines = [] + while msg_start_idx < message.length + parsed_line = parse_broadcast_msg(message[msg_start_idx..-1], text_width) + msg_start_idx += parsed_line.length + lines.push(parsed_line.strip) + end puts puts "=" * total_width @@ -95,4 +99,22 @@ class GitlabPostReceive puts puts "=" * total_width end + + private + + def parse_broadcast_msg(msg, text_length) + msg ||= "" + # just return msg if shorter than or equal to text length + return msg if msg.length <= text_length + + # search for word break shorter than text length + truncate_to_space = msg.match(/\A(.{,#{text_length}})(?=\s|$)(\s*)/).to_s + + if truncate_to_space.empty? + # search for word break longer than text length + truncate_to_space = msg.match(/\A\S+/).to_s + end + + truncate_to_space + end end |
