Class: CompareService

Inherits:
Object
  • Object
show all
Defined in:
app/services/compare_service.rb

Overview

Compare 2 refs for one repo or between repositories and return Compare object that responds to commits and diffs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_start_project, new_start_ref_name) ⇒ CompareService

Returns a new instance of CompareService.



10
11
12
13
# File 'app/services/compare_service.rb', line 10

def initialize(new_start_project, new_start_ref_name)
  @start_project = new_start_project
  @start_ref_name = new_start_ref_name
end

Instance Attribute Details

#start_projectObject (readonly)

Returns the value of attribute start_project.



8
9
10
# File 'app/services/compare_service.rb', line 8

def start_project
  @start_project
end

#start_ref_nameObject (readonly)

Returns the value of attribute start_ref_name.



8
9
10
# File 'app/services/compare_service.rb', line 8

def start_ref_name
  @start_ref_name
end

Instance Method Details

#execute(target_project, target_ref, base_sha: nil, straight: false) ⇒ Object



15
16
17
18
19
20
21
# File 'app/services/compare_service.rb', line 15

def execute(target_project, target_ref, base_sha: nil, straight: false)
  raw_compare = target_project.repository.compare_source_branch(target_ref, start_project.repository, start_ref_name, straight: straight)

  return unless raw_compare && raw_compare.base && raw_compare.head

  Compare.new(raw_compare, start_project, base_sha: base_sha, straight: straight)
end