Module: GraphHelper

Defined in:
app/helpers/graph_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_refs(repo, commit) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/graph_helper.rb', line 2

def get_refs(repo, commit)
  refs = ""
  # Commit::ref_names already strips the refs/XXX from important refs (e.g. refs/heads/XXX)
  # so anything leftover is internally used by GitLab
  commit_refs = commit.ref_names(repo).reject{ |name| name.starts_with?('refs/') }
  refs << commit_refs.join(' ')

  # append note count
  refs << "[#{@graph.notes[commit.id]}]" if @graph.notes[commit.id] > 0

  refs
end

#parents_zip_spaces(parents, parent_spaces) ⇒ Object


15
16
17
18
# File 'app/helpers/graph_helper.rb', line 15

def parents_zip_spaces(parents, parent_spaces)
  ids = parents.map { |p| p.id }
  ids.zip(parent_spaces)
end

#success_ratio(success_builds, failed_builds) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'app/helpers/graph_helper.rb', line 20

def success_ratio(success_builds, failed_builds)
  failed_builds = failed_builds.count(:all)
  success_builds = success_builds.count(:all)

  return 100 if failed_builds.zero?

  ratio = (success_builds.to_f / (success_builds + failed_builds)) * 100
  ratio.to_i
end