summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-16 23:12:52 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-07-16 23:12:52 +0300
commit132caae73446e23a2ff8a7b1a4110efe42a36eb1 (patch)
treede590a467bfcc61a701d35a3b2acf774e6c07db4
parenta165a0b23fd6cc81e7fc0163827310f69ce0399a (diff)
downloadgitlab-ce-132caae73446e23a2ff8a7b1a4110efe42a36eb1.tar.gz
Move repo tags to own controller. add ability to remove tags
-rw-r--r--app/controllers/projects/branches_controller.rb2
-rw-r--r--app/controllers/projects/repositories_controller.rb5
-rw-r--r--app/controllers/projects/tags_controller.rb29
-rw-r--r--app/models/event.rb6
-rw-r--r--app/models/repository.rb4
-rw-r--r--app/views/projects/branches/_branch.html.haml1
-rw-r--r--app/views/projects/commits/_head.html.haml4
-rw-r--r--app/views/projects/tags/index.html.haml (renamed from app/views/projects/repositories/tags.html.haml)17
-rw-r--r--config/routes.rb3
-rw-r--r--lib/gitlab/backend/shell.rb25
10 files changed, 77 insertions, 19 deletions
diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb
index 07039624ff6..b43017f5522 100644
--- a/app/controllers/projects/branches_controller.rb
+++ b/app/controllers/projects/branches_controller.rb
@@ -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|
diff --git a/app/controllers/projects/repositories_controller.rb b/app/controllers/projects/repositories_controller.rb
index 7094a4c1ffe..7e6c7016ecf 100644
--- a/app/controllers/projects/repositories_controller.rb
+++ b/app/controllers/projects/repositories_controller.rb
@@ -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)
diff --git a/app/controllers/projects/tags_controller.rb b/app/controllers/projects/tags_controller.rb
new file mode 100644
index 00000000000..32eb37b2fcb
--- /dev/null
+++ b/app/controllers/projects/tags_controller.rb
@@ -0,0 +1,29 @@
+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
diff --git a/app/models/event.rb b/app/models/event.rb
index 50c87f84655..3ed2a6aa765 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -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
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 384836951c3..08574625012 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -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+'
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index f43b56efc3a..026948aa027 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -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
diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml
index 20b9195c4c3..06d69eb5f75 100644
--- a/app/views/projects/commits/_head.html.haml
+++ b/app/views/projects/commits/_head.html.haml
@@ -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
diff --git a/app/views/projects/repositories/tags.html.haml b/app/views/projects/tags/index.html.haml
index 5972ea6c531..3071645342f 100644
--- a/app/views/projects/repositories/tags.html.haml
+++ b/app/views/projects/tags/index.html.haml
@@ -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"
- - if can? current_user, :download_code, @project
- .pull-right
- = link_to archive_project_repository_path(@project, ref: tag.name) do
+ %span.pull-right
+ - if can? current_user, :download_code, @project
+ = 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
diff --git a/config/routes.rb b/config/routes.rb
index c5fdec14675..0bae5d44395 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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]
diff --git a/lib/gitlab/backend/shell.rb b/lib/gitlab/backend/shell.rb
index e6100b376e3..6c9532face8 100644
--- a/lib/gitlab/backend/shell.rb
+++ b/lib/gitlab/backend/shell.rb
@@ -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.