Commit 132caae7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move repo tags to own controller. add ability to remove tags

parent a165a0b2
...@@ -17,7 +17,7 @@ class Projects::BranchesController < Projects::ApplicationController ...@@ -17,7 +17,7 @@ class Projects::BranchesController < Projects::ApplicationController
branch = @project.repository.branches.find { |branch| branch.name == params[:id] } branch = @project.repository.branches.find { |branch| branch.name == params[:id] }
if branch && @project.repository.rm_branch(branch.name) if branch && @project.repository.rm_branch(branch.name)
Event.create_rm_branch(@project, current_user, branch) Event.create_rm_ref(@project, current_user, branch)
end end
respond_to do |format| respond_to do |format|
......
...@@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
@activities = @repository.commits_with_refs(20) @activities = @repository.commits_with_refs(20)
end end
def tags
@tags = @repository.tags
end
def stats def stats
@stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref)
@graph = @stats.graph @graph = @stats.graph
...@@ -22,7 +18,6 @@ class Projects::RepositoriesController < Projects::ApplicationController ...@@ -22,7 +18,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
render_404 and return render_404 and return
end end
storage_path = Rails.root.join("tmp", "repositories") storage_path = Rails.root.join("tmp", "repositories")
file_path = @repository.archive_repo(params[:ref], storage_path) file_path = @repository.archive_repo(params[:ref], storage_path)
......
class Projects::TagsController < Projects::ApplicationController
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_code_access!
before_filter :require_non_empty_project
before_filter :authorize_admin_project!, only: [:destroy, :create]
def index
@tags = Kaminari.paginate_array(@project.repository.tags).page(params[:page]).per(30)
end
def create
# TODO: implement
end
def destroy
tag = @project.repository.tags.find { |tag| tag.name == params[:id] }
if tag && @project.repository.rm_tag(tag.name)
Event.create_rm_ref(@project, current_user, tag, 'refs/tags')
end
respond_to do |format|
format.html { redirect_to project_tags_path }
format.js { render nothing: true }
end
end
end
...@@ -55,13 +55,13 @@ class Event < ActiveRecord::Base ...@@ -55,13 +55,13 @@ class Event < ActiveRecord::Base
end end
end end
def create_rm_branch(project, user, branch) def create_rm_ref(project, user, ref, prefix = 'refs/heads')
Event.create( Event.create(
project: project, project: project,
action: Event::PUSHED, action: Event::PUSHED,
data: { data: {
ref: branch.name, ref: "#{prefix}/#{ref.name}",
before: branch.commit.id, before: ref.commit.id,
after: '00000000' after: '00000000'
}, },
author_id: user.id author_id: user.id
......
...@@ -39,6 +39,10 @@ class Repository ...@@ -39,6 +39,10 @@ class Repository
gitlab_shell.rm_branch(path_with_namespace, branch_name) gitlab_shell.rm_branch(path_with_namespace, branch_name)
end end
def rm_tag(tag_name)
gitlab_shell.rm_tag(path_with_namespace, tag_name)
end
def round_commit_count def round_commit_count
if commit_count > 10000 if commit_count > 10000
'10000+' '10000+'
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
- if can?(current_user, :download_code, @project) - if can?(current_user, :download_code, @project)
= link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do = link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do
%i.icon-download-alt %i.icon-download-alt
Download
- if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref
= link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, confirm: 'Removed branch cannot be restored. Are you sure?', remote: true do = link_to project_branch_path(@project, branch.name), class: 'btn grouped btn-small remove-row', method: :delete, confirm: 'Removed branch cannot be restored. Are you sure?', remote: true do
%i.icon-trash %i.icon-trash
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
Branches Branches
%span.badge= @repository.branches.length %span.badge= @repository.branches.length
= nav_link(controller: :repositories, action: :tags) do = nav_link(controller: :tags) do
= link_to tags_project_repository_path(@project) do = link_to project_tags_path(@project) do
Tags Tags
%span.badge= @repository.tags.length %span.badge= @repository.tags.length
......
...@@ -4,27 +4,32 @@ ...@@ -4,27 +4,32 @@
- @tags.each do |tag| - @tags.each do |tag|
- commit = Commit.new(Gitlab::Git::Commit.new(tag.commit)) - commit = Commit.new(Gitlab::Git::Commit.new(tag.commit))
%li %li
%h5 %h4
= link_to project_commits_path(@project, tag.name), class: "" do = link_to project_commits_path(@project, tag.name), class: "" do
%i.icon-tag %i.icon-tag
= tag.name = tag.name
%small %small
= truncate(tag.message || '', length: 70) = truncate(tag.message || '', length: 70)
.pull-right .pull-right
%span.light %small.cdark
%i.icon-calendar
= time_ago_in_words(commit.committed_date) = time_ago_in_words(commit.committed_date)
ago ago
%div.prepend-left-20 %p.prepend-left-20
= link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace" = link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace"
&ndash; &ndash;
= link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark" = link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark"
%span.pull-right
- if can? current_user, :download_code, @project - if can? current_user, :download_code, @project
.pull-right = link_to archive_project_repository_path(@project, ref: tag.name), class: 'btn grouped btn-small' do
= link_to archive_project_repository_path(@project, ref: tag.name) do
%i.icon-download-alt %i.icon-download-alt
Download Download
- if can?(current_user, :admin_project, @project)
= link_to project_tag_path(@project, tag.name), class: 'btn grouped btn-small remove-row', method: :delete, confirm: 'Removed tag cannot be restored. Are you sure?', remote: true do
%i.icon-trash
= paginate @tags, theme: 'gitlab'
- else - else
%h3.nothing_here_message %h3.nothing_here_message
......
...@@ -205,8 +205,6 @@ Gitlab::Application.routes.draw do ...@@ -205,8 +205,6 @@ Gitlab::Application.routes.draw do
resource :repository, only: [:show] do resource :repository, only: [:show] do
member do member do
get "branches"
get "tags"
get "stats" get "stats"
get "archive" get "archive"
end end
...@@ -225,6 +223,7 @@ Gitlab::Application.routes.draw do ...@@ -225,6 +223,7 @@ Gitlab::Application.routes.draw do
end end
end end
resources :tags, only: [:index, :create, :destroy]
resources :branches, only: [:index, :create, :destroy] resources :branches, only: [:index, :create, :destroy]
resources :protected_branches, only: [:index, :create, :destroy] resources :protected_branches, only: [:index, :create, :destroy]
......
...@@ -96,6 +96,31 @@ module Gitlab ...@@ -96,6 +96,31 @@ module Gitlab
system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name
end end
# Add repository tag from passed ref
#
# path - project path with namespace
# tag_name - new tag name
# ref - HEAD for new tag
#
# Ex.
# add_tag("gitlab/gitlab-ci", "v4.0", "master")
#
def add_tag(path, tag_name, ref)
system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref
end
# Remove repository tag
#
# path - project path with namespace
# tag_name - tag name to remove
#
# Ex.
# rm_tag("gitlab/gitlab-ci", "v4.0")
#
def rm_tag(path, tag_name)
system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-tag", "#{path}.git", tag_name
end
# Add new key to gitlab-shell # Add new key to gitlab-shell
# #
# Ex. # Ex.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment