Class: Kachikachi::PullRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/kachikachi/pull_request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, options) ⇒ PullRequest

Returns a new instance of PullRequest.



8
9
10
11
# File 'lib/kachikachi/pull_request.rb', line 8

def initialize(number, options)
  @number = number
  @options = options
end

Instance Attribute Details

#client=(value) ⇒ Object

Sets the attribute client

Parameters:

  • value

    the value to set the attribute client to.



6
7
8
# File 'lib/kachikachi/pull_request.rb', line 6

def client=(value)
  @client = value
end

#content=(value) ⇒ Object

Sets the attribute content

Parameters:

  • value

    the value to set the attribute content to.



6
7
8
# File 'lib/kachikachi/pull_request.rb', line 6

def content=(value)
  @content = value
end

#diff=(value) ⇒ Object

Sets the attribute diff

Parameters:

  • value

    the value to set the attribute diff to.



6
7
8
# File 'lib/kachikachi/pull_request.rb', line 6

def diff=(value)
  @diff = value
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/kachikachi/pull_request.rb', line 6

def number
  @number
end

Instance Method Details

#baseObject



50
51
52
# File 'lib/kachikachi/pull_request.rb', line 50

def base
  content.base
end

#patch_listObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/kachikachi/pull_request.rb', line 19

def patch_list
  patch_body = ''
  patch_list = []
  patch_file_name = ''
  body = false
  lines = diff.lines

  lines.each_with_index do |line, index|
    case line
    when /^diff\s--git\sa\/(?<file_name>.*)\sb\//
      unless patch_body.empty?
        patch_list << Patch.new(patch_file_name, patch_body, @options)
        patch_body = ''
      end

      patch_file_name = Regexp.last_match[:file_name]
      body = false
    when /^@@\s-\d+,\d+\s\+\d+,\d+\s@@/
      body = true
    else
      next unless body

      patch_body << line
      last_line = lines.count == index + 1
      patch_list << Patch.new(patch_file_name, patch_body, @options) if last_line && !patch_body.empty?
    end
  end

  patch_list
end

#target_patch_listObject



13
14
15
16
17
# File 'lib/kachikachi/pull_request.rb', line 13

def target_patch_list
  patch_list.select do |patch|
    !@options['file-regexp'] || patch.file_name =~ Regexp.new(@options['file-regexp'])
  end
end