Commit 132caae73446e23a2ff8a7b1a4110efe42a36eb1
1 parent
a165a0b2
Exists in
master
and in
4 other branches
Move repo tags to own controller. add ability to remove tags
Showing
11 changed files
with
107 additions
and
49 deletions
Show diff stats
app/controllers/projects/branches_controller.rb
@@ -17,7 +17,7 @@ class Projects::BranchesController < Projects::ApplicationController | @@ -17,7 +17,7 @@ class Projects::BranchesController < Projects::ApplicationController | ||
17 | branch = @project.repository.branches.find { |branch| branch.name == params[:id] } | 17 | branch = @project.repository.branches.find { |branch| branch.name == params[:id] } |
18 | 18 | ||
19 | if branch && @project.repository.rm_branch(branch.name) | 19 | if branch && @project.repository.rm_branch(branch.name) |
20 | - Event.create_rm_branch(@project, current_user, branch) | 20 | + Event.create_rm_ref(@project, current_user, branch) |
21 | end | 21 | end |
22 | 22 | ||
23 | respond_to do |format| | 23 | respond_to do |format| |
app/controllers/projects/repositories_controller.rb
@@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | @@ -8,10 +8,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | ||
8 | @activities = @repository.commits_with_refs(20) | 8 | @activities = @repository.commits_with_refs(20) |
9 | end | 9 | end |
10 | 10 | ||
11 | - def tags | ||
12 | - @tags = @repository.tags | ||
13 | - end | ||
14 | - | ||
15 | def stats | 11 | def stats |
16 | @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) | 12 | @stats = Gitlab::Git::Stats.new(@repository.raw, @repository.root_ref) |
17 | @graph = @stats.graph | 13 | @graph = @stats.graph |
@@ -22,7 +18,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | @@ -22,7 +18,6 @@ class Projects::RepositoriesController < Projects::ApplicationController | ||
22 | render_404 and return | 18 | render_404 and return |
23 | end | 19 | end |
24 | 20 | ||
25 | - | ||
26 | storage_path = Rails.root.join("tmp", "repositories") | 21 | storage_path = Rails.root.join("tmp", "repositories") |
27 | 22 | ||
28 | file_path = @repository.archive_repo(params[:ref], storage_path) | 23 | file_path = @repository.archive_repo(params[:ref], storage_path) |
@@ -0,0 +1,29 @@ | @@ -0,0 +1,29 @@ | ||
1 | +class Projects::TagsController < Projects::ApplicationController | ||
2 | + # Authorize | ||
3 | + before_filter :authorize_read_project! | ||
4 | + before_filter :authorize_code_access! | ||
5 | + before_filter :require_non_empty_project | ||
6 | + | ||
7 | + before_filter :authorize_admin_project!, only: [:destroy, :create] | ||
8 | + | ||
9 | + def index | ||
10 | + @tags = Kaminari.paginate_array(@project.repository.tags).page(params[:page]).per(30) | ||
11 | + end | ||
12 | + | ||
13 | + def create | ||
14 | + # TODO: implement | ||
15 | + end | ||
16 | + | ||
17 | + def destroy | ||
18 | + tag = @project.repository.tags.find { |tag| tag.name == params[:id] } | ||
19 | + | ||
20 | + if tag && @project.repository.rm_tag(tag.name) | ||
21 | + Event.create_rm_ref(@project, current_user, tag, 'refs/tags') | ||
22 | + end | ||
23 | + | ||
24 | + respond_to do |format| | ||
25 | + format.html { redirect_to project_tags_path } | ||
26 | + format.js { render nothing: true } | ||
27 | + end | ||
28 | + end | ||
29 | +end |
app/models/event.rb
@@ -55,13 +55,13 @@ class Event < ActiveRecord::Base | @@ -55,13 +55,13 @@ class Event < ActiveRecord::Base | ||
55 | end | 55 | end |
56 | end | 56 | end |
57 | 57 | ||
58 | - def create_rm_branch(project, user, branch) | 58 | + def create_rm_ref(project, user, ref, prefix = 'refs/heads') |
59 | Event.create( | 59 | Event.create( |
60 | project: project, | 60 | project: project, |
61 | action: Event::PUSHED, | 61 | action: Event::PUSHED, |
62 | data: { | 62 | data: { |
63 | - ref: branch.name, | ||
64 | - before: branch.commit.id, | 63 | + ref: "#{prefix}/#{ref.name}", |
64 | + before: ref.commit.id, | ||
65 | after: '00000000' | 65 | after: '00000000' |
66 | }, | 66 | }, |
67 | author_id: user.id | 67 | author_id: user.id |
app/models/repository.rb
@@ -39,6 +39,10 @@ class Repository | @@ -39,6 +39,10 @@ class Repository | ||
39 | gitlab_shell.rm_branch(path_with_namespace, branch_name) | 39 | gitlab_shell.rm_branch(path_with_namespace, branch_name) |
40 | end | 40 | end |
41 | 41 | ||
42 | + def rm_tag(tag_name) | ||
43 | + gitlab_shell.rm_tag(path_with_namespace, tag_name) | ||
44 | + end | ||
45 | + | ||
42 | def round_commit_count | 46 | def round_commit_count |
43 | if commit_count > 10000 | 47 | if commit_count > 10000 |
44 | '10000+' | 48 | '10000+' |
app/views/projects/branches/_branch.html.haml
@@ -12,6 +12,7 @@ | @@ -12,6 +12,7 @@ | ||
12 | - if can?(current_user, :download_code, @project) | 12 | - if can?(current_user, :download_code, @project) |
13 | = link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do | 13 | = link_to archive_project_repository_path(@project, ref: branch.name), class: 'btn grouped btn-small' do |
14 | %i.icon-download-alt | 14 | %i.icon-download-alt |
15 | + Download | ||
15 | - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref | 16 | - if can?(current_user, :admin_project, @project) && branch.name != @repository.root_ref |
16 | = 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 | 17 | = 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 |
17 | %i.icon-trash | 18 | %i.icon-trash |
app/views/projects/commits/_head.html.haml
@@ -11,8 +11,8 @@ | @@ -11,8 +11,8 @@ | ||
11 | Branches | 11 | Branches |
12 | %span.badge= @repository.branches.length | 12 | %span.badge= @repository.branches.length |
13 | 13 | ||
14 | - = nav_link(controller: :repositories, action: :tags) do | ||
15 | - = link_to tags_project_repository_path(@project) do | 14 | + = nav_link(controller: :tags) do |
15 | + = link_to project_tags_path(@project) do | ||
16 | Tags | 16 | Tags |
17 | %span.badge= @repository.tags.length | 17 | %span.badge= @repository.tags.length |
18 | 18 |
app/views/projects/repositories/tags.html.haml
@@ -1,36 +0,0 @@ | @@ -1,36 +0,0 @@ | ||
1 | -= render "projects/commits/head" | ||
2 | -- unless @tags.empty? | ||
3 | - %ul.bordered-list | ||
4 | - - @tags.each do |tag| | ||
5 | - - commit = Commit.new(Gitlab::Git::Commit.new(tag.commit)) | ||
6 | - %li | ||
7 | - %h5 | ||
8 | - = link_to project_commits_path(@project, tag.name), class: "" do | ||
9 | - %i.icon-tag | ||
10 | - = tag.name | ||
11 | - %small | ||
12 | - = truncate(tag.message || '', length: 70) | ||
13 | - .pull-right | ||
14 | - %span.light | ||
15 | - = time_ago_in_words(commit.committed_date) | ||
16 | - ago | ||
17 | - %div.prepend-left-20 | ||
18 | - = link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace" | ||
19 | - – | ||
20 | - = link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark" | ||
21 | - | ||
22 | - - if can? current_user, :download_code, @project | ||
23 | - .pull-right | ||
24 | - = link_to archive_project_repository_path(@project, ref: tag.name) do | ||
25 | - %i.icon-download-alt | ||
26 | - Download | ||
27 | - | ||
28 | - | ||
29 | -- else | ||
30 | - %h3.nothing_here_message | ||
31 | - Repository has no tags yet. | ||
32 | - %br | ||
33 | - %small | ||
34 | - Use git tag command to add a new one: | ||
35 | - %br | ||
36 | - %span.monospace git tag -a v1.4 -m 'version 1.4' |
@@ -0,0 +1,41 @@ | @@ -0,0 +1,41 @@ | ||
1 | += render "projects/commits/head" | ||
2 | +- unless @tags.empty? | ||
3 | + %ul.bordered-list | ||
4 | + - @tags.each do |tag| | ||
5 | + - commit = Commit.new(Gitlab::Git::Commit.new(tag.commit)) | ||
6 | + %li | ||
7 | + %h4 | ||
8 | + = link_to project_commits_path(@project, tag.name), class: "" do | ||
9 | + %i.icon-tag | ||
10 | + = tag.name | ||
11 | + %small | ||
12 | + = truncate(tag.message || '', length: 70) | ||
13 | + .pull-right | ||
14 | + %small.cdark | ||
15 | + %i.icon-calendar | ||
16 | + = time_ago_in_words(commit.committed_date) | ||
17 | + ago | ||
18 | + %p.prepend-left-20 | ||
19 | + = link_to commit.short_id(8), project_commit_path(@project, commit), class: "monospace" | ||
20 | + – | ||
21 | + = link_to_gfm truncate(commit.title, length: 70), project_commit_path(@project, commit.id), class: "cdark" | ||
22 | + | ||
23 | + %span.pull-right | ||
24 | + - if can? current_user, :download_code, @project | ||
25 | + = link_to archive_project_repository_path(@project, ref: tag.name), class: 'btn grouped btn-small' do | ||
26 | + %i.icon-download-alt | ||
27 | + Download | ||
28 | + - if can?(current_user, :admin_project, @project) | ||
29 | + = 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 | ||
30 | + %i.icon-trash | ||
31 | + | ||
32 | + = paginate @tags, theme: 'gitlab' | ||
33 | + | ||
34 | +- else | ||
35 | + %h3.nothing_here_message | ||
36 | + Repository has no tags yet. | ||
37 | + %br | ||
38 | + %small | ||
39 | + Use git tag command to add a new one: | ||
40 | + %br | ||
41 | + %span.monospace git tag -a v1.4 -m 'version 1.4' |
config/routes.rb
@@ -205,8 +205,6 @@ Gitlab::Application.routes.draw do | @@ -205,8 +205,6 @@ Gitlab::Application.routes.draw do | ||
205 | 205 | ||
206 | resource :repository, only: [:show] do | 206 | resource :repository, only: [:show] do |
207 | member do | 207 | member do |
208 | - get "branches" | ||
209 | - get "tags" | ||
210 | get "stats" | 208 | get "stats" |
211 | get "archive" | 209 | get "archive" |
212 | end | 210 | end |
@@ -225,6 +223,7 @@ Gitlab::Application.routes.draw do | @@ -225,6 +223,7 @@ Gitlab::Application.routes.draw do | ||
225 | end | 223 | end |
226 | end | 224 | end |
227 | 225 | ||
226 | + resources :tags, only: [:index, :create, :destroy] | ||
228 | resources :branches, only: [:index, :create, :destroy] | 227 | resources :branches, only: [:index, :create, :destroy] |
229 | resources :protected_branches, only: [:index, :create, :destroy] | 228 | resources :protected_branches, only: [:index, :create, :destroy] |
230 | 229 |
lib/gitlab/backend/shell.rb
@@ -96,6 +96,31 @@ module Gitlab | @@ -96,6 +96,31 @@ module Gitlab | ||
96 | system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name | 96 | system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-branch", "#{path}.git", branch_name |
97 | end | 97 | end |
98 | 98 | ||
99 | + # Add repository tag from passed ref | ||
100 | + # | ||
101 | + # path - project path with namespace | ||
102 | + # tag_name - new tag name | ||
103 | + # ref - HEAD for new tag | ||
104 | + # | ||
105 | + # Ex. | ||
106 | + # add_tag("gitlab/gitlab-ci", "v4.0", "master") | ||
107 | + # | ||
108 | + def add_tag(path, tag_name, ref) | ||
109 | + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "create-tag", "#{path}.git", tag_name, ref | ||
110 | + end | ||
111 | + | ||
112 | + # Remove repository tag | ||
113 | + # | ||
114 | + # path - project path with namespace | ||
115 | + # tag_name - tag name to remove | ||
116 | + # | ||
117 | + # Ex. | ||
118 | + # rm_tag("gitlab/gitlab-ci", "v4.0") | ||
119 | + # | ||
120 | + def rm_tag(path, tag_name) | ||
121 | + system "#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects", "rm-tag", "#{path}.git", tag_name | ||
122 | + end | ||
123 | + | ||
99 | # Add new key to gitlab-shell | 124 | # Add new key to gitlab-shell |
100 | # | 125 | # |
101 | # Ex. | 126 | # Ex. |