summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHannes Rosenögger <123haynes@gmail.com>2015-01-17 14:12:49 +0100
committerHannes Rosenögger <123haynes@gmail.com>2015-01-17 19:22:35 +0100
commit8243eb3f0e3ee06a793831ae0899bfe409a31903 (patch)
treeada0ee980669049f1952d36c58698731844521b7
parentada6c6080b2fa0d63003f8b29b5c32195254906d (diff)
downloadgitlab-ce-8243eb3f0e3ee06a793831ae0899bfe409a31903.tar.gz
Show tags in commit view
-rw-r--r--CHANGELOG2
-rw-r--r--app/controllers/projects/commit_controller.rb1
-rw-r--r--app/helpers/commits_helper.rb6
-rw-r--r--app/models/repository.rb17
-rw-r--r--app/views/projects/commit/_commit_box.html.haml7
5 files changed, 32 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 387d42a7aca..39079daa26a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,7 +11,7 @@ v 7.8.0
-
-
-
- -
+ - Show tags in commit view (Hannes Rosenögger)
-
-
-
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb
index dac858d8e16..470efbd2114 100644
--- a/app/controllers/projects/commit_controller.rb
+++ b/app/controllers/projects/commit_controller.rb
@@ -12,6 +12,7 @@ class Projects::CommitController < Projects::ApplicationController
@line_notes = @project.notes.for_commit_id(commit.id).inline
@branches = @project.repository.branch_names_contains(commit.id)
+ @tags = @project.repository.tag_names_contains(commit.id)
@diffs = @commit.diffs
@note = @project.build_commit_note(commit)
@notes_count = @project.notes.for_commit_id(commit.id).count
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index 36adeadd8a5..6a6d483ba66 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -65,6 +65,12 @@ module CommitsHelper
branches.sort.map { |branch| link_to(branch, project_tree_path(project, branch)) }.join(", ").html_safe
end
+ # Returns the sorted links to tags, separated by a comma
+ def commit_tags_links(project, tags)
+ sorted = VersionSorter.rsort(tags)
+ sorted.map { |tag| link_to(tag, project_commits_path(project, project.repository.find_tag(tag).name)) }.join(", ").html_safe
+ end
+
def link_to_browse_code(project, commit)
if current_controller?(:projects, :commits)
if @repo.blob_at(commit.id, @path)
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 93994123a90..e93c76790c7 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -312,4 +312,21 @@ class Repository
[]
end
end
+
+ def tag_names_contains(sha)
+ args = %W(git tag --contains #{sha})
+ names = Gitlab::Popen.popen(args, path_to_repo).first
+
+ if names.respond_to?(:split)
+ names = names.split("\n").map(&:strip)
+
+ names.each do |name|
+ name.slice! '* '
+ end
+
+ names
+ else
+ []
+ end
+ end
end
diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml
index e149f017f84..1d4658432ae 100644
--- a/app/views/projects/commit/_commit_box.html.haml
+++ b/app/views/projects/commit/_commit_box.html.haml
@@ -50,6 +50,13 @@
%span.js-details-content.hide
= commit_branches_links(@project, @branches)
+- if @tags.any?
+ .commit-info-row
+ %span.cgray
+ Tags:
+ %span
+ = commit_tags_links(@project, @tags)
+
.commit-box
%h3.commit-title
= gfm escape_once(@commit.title)