Class: Banzai::ReferenceParser::CommitParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/banzai/reference_parser/commit_parser.rb

Constant Summary collapse

COMMITS_LIMIT =
1000

Instance Method Summary collapse

Methods inherited from BaseParser

#can?, #collection_cache_key, #collection_objects_for_ids, data_attribute, #find_projects_for_hash_keys, #gather_attributes_per_project, #gather_references, #grouped_objects_for_nodes, #initialize, #nodes_user_can_reference, #nodes_visible_to_user, #process, #project_for_node, #projects_for_nodes, reference_class, #references_relation, #unique_attribute_values

Constructor Details

This class inherits a constructor from Banzai::ReferenceParser::BaseParser

Instance Method Details

#commit_ids_per_project(nodes) ⇒ Object



19
20
21
# File 'lib/banzai/reference_parser/commit_parser.rb', line 19

def commit_ids_per_project(nodes)
  gather_attributes_per_project(nodes, self.class.data_attribute)
end

#find_commits(project, ids) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/banzai/reference_parser/commit_parser.rb', line 23

def find_commits(project, ids)
  return [] unless project.valid_repo?

  ids = ids.take(COMMITS_LIMIT)

  project.commits_by(oids: ids)
end

#referenced_by(nodes, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/banzai/reference_parser/commit_parser.rb', line 10

def referenced_by(nodes, options = {})
  commit_ids = commit_ids_per_project(nodes)
  projects = find_projects_for_hash_keys(commit_ids)

  projects.flat_map do |project|
    find_commits(project, commit_ids[project.id])
  end
end