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
branch = @project.repository.branches.find { |branch| branch.name == params[:id] }
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
respond_to do |format|
......
......@@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
@activities = @repository.commits_with_refs(20)
end
def tags
@tags = @repository.tags
end
def stats
@stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref)
@graph = @stats.graph
......@@ -22,7 +18,6 @@ class Projects::RepositoriesController < Projects::ApplicationController
render_404 and return
end
storage_path = Rails.root.join("tmp", "repositories")
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
end
end
def create_rm_branch(project, user, branch)
def create_rm_ref(project, user, ref, prefix = 'refs/heads')
Event.create(
project: project,
action: Event::PUSHED,
data: {
ref: branch.name,
before: branch.commit.id,
ref: "#{prefix}/#{ref.name}",
before: ref.commit.id,
after: '00000000'
},
author_id: user.id
......
......@@ -39,6 +39,10 @@ class Repository
gitlab_shell.rm_branch(path_with_namespace, branch_name)
end
def rm_tag(tag_name)
gitlab_shell.rm_tag(path_with_namespace, tag_name)
end
def round_commit_count
if commit_count > 10000
'10000+'
......
......@@ -12,6 +12,7 @@
- if can?(current_user, :download_code, @project)
= link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do
%i.icon-download-alt
Download
- 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
%i.icon-trash
......
......@@ -11,8 +11,8 @@
Branches
%span.badge= @repository.branches.length
= nav_link(controller: :repositories, action: :tags) do
= link_to tags_project_repository_path(@project) do
= nav_link(controller: :tags) do
= link_to project_tags_path(@project) do
Tags
%span.badge= @repository.tags.length
......
......@@ -4,27 +4,32 @@
- @tags.each do |tag|
- commit = Commit.new(Gitlab::Git::Commit.new(tag.commit))
%li
%h5
%h4
= link_to project_commits_path(@project, tag.name), class: "" do
%i.icon-tag
= tag.name
%small
= truncate(tag.message || '', length: 70)
.pull-right
%span.light
%small.cdark
%i.icon-calendar
= time_ago_in_words(commit.committed_date)
ago
%div.prepend-left-20
%p.prepend-left-20
= link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace"
&ndash;
= 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
.pull-right
= link_to archive_project_repository_path(@project, ref: tag.name) do
= link_to archive_project_repository_path(@project, ref: tag.name), class: 'btn grouped btn-small' do
%i.icon-download-alt
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
%h3.nothing_here_message
......
......@@ -205,8 +205,6 @@ Gitlab::Application.routes.draw do
resource :repository, only: [:show] do
member do
get "branches"
get "tags"
get "stats"
get "archive"
end
......@@ -225,6 +223,7 @@ Gitlab::Application.routes.draw do
end
end
resources :tags, only: [:index, :create, :destroy]
resources :branches, only: [:index, :create, :destroy]
resources :protected_branches, only: [:index, :create, :destroy]
......
......@@ -96,6 +96,31 @@ module Gitlab
system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name
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
#
# 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