Sha256: 6626a1f6b8a7a36af99a8ab219f63acdd76c29116b57967553396ca4f966ae52

Contents?: true

Size: 772 Bytes

Versions: 3

Compression:

Stored size: 772 Bytes

Contents

module Stash
  class PullRequest
    class Diff
      def initialize(raw_diff)
        @raw_diff = raw_diff
      end

      def added_line?(file, line)
        added_lines(file).include?(line)
      end

      private

      def added_lines(file)
        @added_lines ||= {}
        @added_lines[file] ||= begin
          file_diff(file)['hunks'].map do |hunk|
            hunk['segments'].select{ |segment| segment['type'] == 'ADDED' }.map do |segment|
              segment['lines'].map do |line|
                line['destination']
              end
            end
          end.flatten
        end
      end

      def file_diff(file)
        @raw_diff['diffs'].detect{ |diff| diff['destination']['toString'] == file } || {'hunks' => []}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stash_pull_request_commenter-0.2.0 lib/stash/pull_request/diff.rb
stash_pull_request_commenter-0.0.2 lib/stash/pull_request/diff.rb
stash_pull_request_commenter-0.0.1 lib/stash/pull_request/diff.rb