diff options
author | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-18 18:25:11 +0000 |
---|---|---|
committer | Douglas Barbosa Alexandre <dbalexandre@gmail.com> | 2019-03-18 18:25:11 +0000 |
commit | 81e63951ffc2cadefb26682b6c58ee6ee510a73c (patch) | |
tree | 790b1b67c2f2ce2fbb31ea8b46aa83e42b068f55 /lib | |
parent | 1b74d8bcfb7c2dd8cc9aaf444ab58b892dd77920 (diff) | |
parent | 08f789736e4d5bfedabc127153d9192dffe5ee1e (diff) | |
download | gitlab-ce-81e63951ffc2cadefb26682b6c58ee6ee510a73c.tar.gz |
Merge branch 'osw-suggestion-diff-lines-strategy' into 'master'
Implement suggestion diff lines parser
See merge request gitlab-org/gitlab-ce!26069
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/suggestion_diff.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/diff/suggestion_diff.rb b/lib/gitlab/diff/suggestion_diff.rb new file mode 100644 index 00000000000..ee153c226b7 --- /dev/null +++ b/lib/gitlab/diff/suggestion_diff.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Gitlab + module Diff + class SuggestionDiff + include Gitlab::Utils::StrongMemoize + + delegate :from_content, :to_content, :from_line, to: :@suggestible + + def initialize(suggestible) + @suggestible = suggestible + end + + def diff_lines + Gitlab::Diff::Parser.new.parse(raw_diff.each_line).to_a + end + + private + + def raw_diff + "#{diff_header}\n#{from_content_as_diff}#{to_content_as_diff}" + end + + def diff_header + "@@ -#{from_line} +#{from_line}" + end + + def from_content_as_diff + from_content.lines.map { |line| line.prepend('-') }.join + end + + def to_content_as_diff + to_content.lines.map { |line| line.prepend('+') }.join + end + end + end +end |