Module: CommitsHelper

Included in:
DiffFileEntity, Gitlab::BlamePresenter
Defined in:
app/helpers/commits_helper.rb

Instance Method Summary collapse

Instance Method Details


117
118
119
# File 'app/helpers/commits_helper.rb', line 117

def cherry_pick_commit_link(commit, continue_to_path, btn_class: nil, has_tooltip: true)
  commit_action_link('cherry-pick', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip)
end

Returns a link to the commit author. If the author has a matching user and is a member of the current @project it will link to the team member page. Otherwise it will link to the author email as specified in the commit.

options:

avatar: true will prepend the avatar image
size:   size of the avatar image in px

11
12
13
# File 'app/helpers/commits_helper.rb', line 11

def commit_author_link(commit, options = {})
  commit_person_link(commit, options.merge(source: :author))
end

Returns a link formatted as a commit branch link


66
67
68
69
70
# File 'app/helpers/commits_helper.rb', line 66

def commit_branch_link(url, text)
  link_to(url, class: 'badge badge-gray ref-name branch-link') do
    sprite_icon('branch', size: 12, css_class: 'fork-svg') + "#{text}"
  end
end

Returns the sorted alphabetically links to branches, separated by a comma


73
74
75
76
77
# File 'app/helpers/commits_helper.rb', line 73

def commit_branches_links(project, branches)
  branches.sort.map do |branch|
    commit_branch_link(project_ref_path(project, branch), branch)
  end.join(' ').html_safe
end

Just like #author_link but for the committer.


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

def commit_committer_link(commit, options = {})
  commit_person_link(commit, options.merge(source: :committer))
end

#commit_default_branch(project, branches) ⇒ Object

Return Project default branch, if it present in array Else - first branch in array (mb last actual branch)


61
62
63
# File 'app/helpers/commits_helper.rb', line 61

def commit_default_branch(project, branches)
  branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop
end

#commit_signature_badge_classes(additional_classes) ⇒ Object


121
122
123
# File 'app/helpers/commits_helper.rb', line 121

def commit_signature_badge_classes(additional_classes)
  %w(btn gpg-status-box) + Array(additional_classes)
end

Returns a link formatted as a commit tag link


80
81
82
83
84
# File 'app/helpers/commits_helper.rb', line 80

def commit_tag_link(url, text)
  link_to(url, class: 'badge badge-gray ref-name') do
    sprite_icon('tag', size: 12, css_class: 'gl-mr-2 vertical-align-middle') + "#{text}"
  end
end

Returns the sorted links to tags, separated by a comma


87
88
89
90
91
92
# File 'app/helpers/commits_helper.rb', line 87

def commit_tags_links(project, tags)
  sorted = VersionSorter.rsort(tags)
  sorted.map do |tag|
    commit_tag_link(project_ref_path(project, tag), tag)
  end.join(' ').html_safe
end

#commit_to_html(commit, ref, project) ⇒ Object


20
21
22
23
24
25
# File 'app/helpers/commits_helper.rb', line 20

def commit_to_html(commit, ref, project)
  render 'projects/commits/commit.html',
    commit: commit,
    ref: ref,
    project: project
end

#commits_breadcrumbsObject

Breadcrumb links for a Project and, if applicable, a tree path


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/commits_helper.rb', line 28

def commits_breadcrumbs
  return unless @project && @ref

  # Add the root project link and the arrow icon
  crumbs = (:li, class: 'breadcrumb-item') do
    link_to(
      @project.path,
      project_commits_path(@project, @ref)
    )
  end

  if @path
    parts = @path.split('/')

    parts.each_with_index do |part, i|
      crumbs << (:li, class: 'breadcrumb-item') do
        # The text is just the individual part, but the link needs all the parts before it
        link_to(
          part,
          project_commits_path(
            @project,
            tree_join(@ref, parts[0..i].join('/'))
          )
        )
      end
    end
  end

  crumbs.html_safe
end

94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'app/helpers/commits_helper.rb', line 94

def link_to_browse_code(project, commit)
  return unless current_controller?(:commits)

  if @path.blank?
    url = project_tree_path(project, commit)
    tooltip = _("Browse Files")
  elsif @repo.blob_at(commit.id, @path)
    url = project_blob_path(project, tree_join(commit.id, @path))
    tooltip = _("Browse File")
  elsif @path.present?
    url = project_tree_path(project, tree_join(commit.id, @path))
    tooltip = _("Browse Directory")
  end

  link_to url, class: "btn btn-default has-tooltip", title: tooltip, data: { container: "body" } do
    sprite_icon('folder-open')
  end
end

113
114
115
# File 'app/helpers/commits_helper.rb', line 113

def revert_commit_link(commit, continue_to_path, btn_class: nil, has_tooltip: true)
  commit_action_link('revert', commit, continue_to_path, btn_class: btn_class, has_tooltip: has_tooltip)
end