Commit 9f31fbc9831f4742618116fbc3c534fb4d3b7798
Exists in
master
and in
4 other branches
Merge pull request #5340 from Undev/feature/branches_on_commit_page_pr
Show branches list (which branches contains commit) on commit page
Showing
5 changed files
with
29 additions
and
0 deletions
Show diff stats
app/assets/javascripts/main.js.coffee
... | ... | @@ -123,6 +123,10 @@ $ -> |
123 | 123 | $(@).next('table').show() |
124 | 124 | $(@).remove() |
125 | 125 | |
126 | + $(".content").on "click", ".js-details-expand", -> | |
127 | + $(@).next('.js-details-contain').removeClass("hide") | |
128 | + $(@).remove() | |
129 | + | |
126 | 130 | (($) -> |
127 | 131 | _chosen = $.fn.chosen |
128 | 132 | $.fn.extend chosen: (options) -> | ... | ... |
app/contexts/commit_load_context.rb
... | ... | @@ -18,6 +18,7 @@ class CommitLoadContext < BaseContext |
18 | 18 | result[:note] = project.build_commit_note(commit) |
19 | 19 | result[:line_notes] = line_notes |
20 | 20 | result[:notes_count] = project.notes.for_commit_id(commit.id).count |
21 | + result[:branches] = project.repository.branch_names_contains(commit.id) | |
21 | 22 | |
22 | 23 | begin |
23 | 24 | result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff] | ... | ... |
app/controllers/projects/commit_controller.rb
... | ... | @@ -22,6 +22,7 @@ class Projects::CommitController < Projects::ApplicationController |
22 | 22 | |
23 | 23 | @note = result[:note] |
24 | 24 | @line_notes = result[:line_notes] |
25 | + @branches = result[:branches] | |
25 | 26 | @notes_count = result[:notes_count] |
26 | 27 | @target_type = :commit |
27 | 28 | @target_id = @commit.id | ... | ... |
app/helpers/commits_helper.rb
... | ... | @@ -94,6 +94,17 @@ module CommitsHelper |
94 | 94 | crumbs.html_safe |
95 | 95 | end |
96 | 96 | |
97 | + # Return Project default branch, if it present in array | |
98 | + # Else - first branch in array (mb last actual branch) | |
99 | + def commit_default_branch(project, branches) | |
100 | + branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop | |
101 | + end | |
102 | + | |
103 | + # Returns the sorted alphabetically links to branches, separated by a comma | |
104 | + def commit_branches_links(project, branches) | |
105 | + branches.sort.map { |branch| link_to(branch, project_tree_path(project, branch)) }.join(", ").html_safe | |
106 | + end | |
107 | + | |
97 | 108 | protected |
98 | 109 | |
99 | 110 | # Private: Returns a link to a person. If the person has a matching user and | ... | ... |
app/views/projects/commit/_commit_box.html.haml
... | ... | @@ -39,6 +39,18 @@ |
39 | 39 | - @commit.parents.each do |parent| |
40 | 40 | = link_to parent.id[0...10], project_commit_path(@project, parent) |
41 | 41 | |
42 | +.commit-info-row | |
43 | + %span.cgray | |
44 | + Exists in | |
45 | + %span | |
46 | + - branch = commit_default_branch(@project, @branches) | |
47 | + = link_to(branch, project_tree_path(@project, branch)) | |
48 | + - if @branches.any? | |
49 | + and in | |
50 | + = link_to("#{pluralize(@branches.count, "other branch")}", "#", class: "js-details-expand") | |
51 | + %span.js-details-contain.hide | |
52 | + = commit_branches_links(@project, @branches) | |
53 | + | |
42 | 54 | .commit-box |
43 | 55 | %h3.commit-title |
44 | 56 | = gfm escape_once(@commit.title) | ... | ... |