Sha256: 6b35749ab052c4e0e88445b731e47dadb18b08541b7e292e8e67ccdb1235dd34

Contents?: true

Size: 795 Bytes

Versions: 6

Compression:

Stored size: 795 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'] && diff['destination']['toString'] == file } || {'hunks' => []}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
face_control-0.5.1 lib/stash/pull_request/diff.rb
face_control-0.5.0 lib/stash/pull_request/diff.rb
face_control-0.4.0 lib/stash/pull_request/diff.rb
face_control-0.3.0 lib/stash/pull_request/diff.rb
face_control-0.2.1 lib/stash/pull_request/diff.rb
stash_pull_request_commenter-0.2.1 lib/stash/pull_request/diff.rb