Skip to content

Commit

Permalink
Move repo tags to own controller. add ability to remove tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Jul 16, 2013
1 parent a165a0b commit 132caae
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/controllers/projects/branches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def destroy
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|
Expand Down
5 changes: 0 additions & 5 deletions app/controllers/projects/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ def show
@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
Expand All @@ -22,7 +18,6 @@ def archive
render_404 and return
end


storage_path = Rails.root.join("tmp", "repositories")

file_path = @repository.archive_repo(params[:ref], storage_path)
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/projects/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def determine_action(record)
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
Expand Down
4 changes: 4 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def rm_branch(branch_name)
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+'
Expand Down
1 change: 1 addition & 0 deletions app/views/projects/branches/_branch.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/views/projects/commits/_head.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@

resource :repository, only: [:show] do
member do
get "branches"
get "tags"
get "stats"
get "archive"
end
Expand All @@ -225,6 +223,7 @@
end
end

resources :tags, only: [:index, :create, :destroy]
resources :branches, only: [:index, :create, :destroy]
resources :protected_branches, only: [:index, :create, :destroy]

Expand Down
25 changes: 25 additions & 0 deletions lib/gitlab/backend/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ def rm_branch(path, branch_name)
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.
Expand Down

0 comments on commit 132caae

Please sign in to comment.