Commit a243253b10244e8a3b62c40b686b52ac61a3adc8
1 parent
edd81a79
Exists in
master
and in
4 other branches
Refactored project archive. Improved MR usability form
Showing
5 changed files
with
96 additions
and
53 deletions
Show diff stats
app/controllers/merge_requests_controller.rb
| @@ -73,29 +73,21 @@ class MergeRequestsController < ApplicationController | @@ -73,29 +73,21 @@ class MergeRequestsController < ApplicationController | ||
| 73 | @merge_request = @project.merge_requests.new(params[:merge_request]) | 73 | @merge_request = @project.merge_requests.new(params[:merge_request]) |
| 74 | @merge_request.author = current_user | 74 | @merge_request.author = current_user |
| 75 | 75 | ||
| 76 | - respond_to do |format| | ||
| 77 | - if @merge_request.save | ||
| 78 | - @merge_request.reload_code | ||
| 79 | - format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' } | ||
| 80 | - format.json { render json: @merge_request, status: :created, location: @merge_request } | ||
| 81 | - else | ||
| 82 | - format.html { render action: "new" } | ||
| 83 | - format.json { render json: @merge_request.errors, status: :unprocessable_entity } | ||
| 84 | - end | 76 | + if @merge_request.save |
| 77 | + @merge_request.reload_code | ||
| 78 | + redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' | ||
| 79 | + else | ||
| 80 | + render action: "new" | ||
| 85 | end | 81 | end |
| 86 | end | 82 | end |
| 87 | 83 | ||
| 88 | def update | 84 | def update |
| 89 | - respond_to do |format| | ||
| 90 | - if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) | ||
| 91 | - @merge_request.reload_code | ||
| 92 | - @merge_request.mark_as_unchecked | ||
| 93 | - format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' } | ||
| 94 | - format.json { head :ok } | ||
| 95 | - else | ||
| 96 | - format.html { render action: "edit" } | ||
| 97 | - format.json { render json: @merge_request.errors, status: :unprocessable_entity } | ||
| 98 | - end | 85 | + if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) |
| 86 | + @merge_request.reload_code | ||
| 87 | + @merge_request.mark_as_unchecked | ||
| 88 | + redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' | ||
| 89 | + else | ||
| 90 | + render action: "edit" | ||
| 99 | end | 91 | end |
| 100 | end | 92 | end |
| 101 | 93 | ||
| @@ -122,7 +114,6 @@ class MergeRequestsController < ApplicationController | @@ -122,7 +114,6 @@ class MergeRequestsController < ApplicationController | ||
| 122 | 114 | ||
| 123 | respond_to do |format| | 115 | respond_to do |format| |
| 124 | format.html { redirect_to project_merge_requests_url(@project) } | 116 | format.html { redirect_to project_merge_requests_url(@project) } |
| 125 | - format.json { head :ok } | ||
| 126 | end | 117 | end |
| 127 | end | 118 | end |
| 128 | 119 |
app/controllers/repositories_controller.rb
| @@ -27,22 +27,14 @@ class RepositoriesController < ApplicationController | @@ -27,22 +27,14 @@ class RepositoriesController < ApplicationController | ||
| 27 | render_404 and return | 27 | render_404 and return |
| 28 | end | 28 | end |
| 29 | 29 | ||
| 30 | - ref = params[:ref] || @project.root_ref | ||
| 31 | - commit = @project.commit(ref) | ||
| 32 | - render_404 and return unless commit | ||
| 33 | - | ||
| 34 | - # Build file path | ||
| 35 | - file_name = @project.code + "-" + commit.id.to_s + ".tar.gz" | ||
| 36 | - storage_path = File.join(Rails.root, "tmp", "repositories", @project.code) | ||
| 37 | - file_path = File.join(storage_path, file_name) | ||
| 38 | - | ||
| 39 | - # Create file if not exists | ||
| 40 | - unless File.exists?(file_path) | ||
| 41 | - FileUtils.mkdir_p storage_path | ||
| 42 | - file = @project.repo.archive_to_file(ref, nil, file_path) | ||
| 43 | - end | ||
| 44 | 30 | ||
| 45 | - # Send file to user | ||
| 46 | - send_file file_path | 31 | + file_path = @project.archive_repo(params[:ref]) |
| 32 | + | ||
| 33 | + if file_path | ||
| 34 | + # Send file to user | ||
| 35 | + send_file file_path | ||
| 36 | + else | ||
| 37 | + render_404 | ||
| 38 | + end | ||
| 47 | end | 39 | end |
| 48 | end | 40 | end |
app/roles/repository.rb
| @@ -117,4 +117,28 @@ module Repository | @@ -117,4 +117,28 @@ module Repository | ||
| 117 | def root_ref? branch | 117 | def root_ref? branch |
| 118 | root_ref == branch | 118 | root_ref == branch |
| 119 | end | 119 | end |
| 120 | + | ||
| 121 | + # Archive Project to .tar.gz | ||
| 122 | + # | ||
| 123 | + # Already packed repo archives stored at | ||
| 124 | + # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz | ||
| 125 | + # | ||
| 126 | + def archive_repo ref | ||
| 127 | + ref = ref || self.root_ref | ||
| 128 | + commit = self.commit(ref) | ||
| 129 | + return nil unless commit | ||
| 130 | + | ||
| 131 | + # Build file path | ||
| 132 | + file_name = self.code + "-" + commit.id.to_s + ".tar.gz" | ||
| 133 | + storage_path = File.join(Rails.root, "tmp", "repositories", self.code) | ||
| 134 | + file_path = File.join(storage_path, file_name) | ||
| 135 | + | ||
| 136 | + # Create file if not exists | ||
| 137 | + unless File.exists?(file_path) | ||
| 138 | + FileUtils.mkdir_p storage_path | ||
| 139 | + file = self.repo.archive_to_file(ref, nil, file_path) | ||
| 140 | + end | ||
| 141 | + | ||
| 142 | + file_path | ||
| 143 | + end | ||
| 120 | end | 144 | end |
app/views/merge_requests/_form.html.haml
| @@ -5,23 +5,43 @@ | @@ -5,23 +5,43 @@ | ||
| 5 | - @merge_request.errors.full_messages.each do |msg| | 5 | - @merge_request.errors.full_messages.each do |msg| |
| 6 | %li= msg | 6 | %li= msg |
| 7 | 7 | ||
| 8 | - .control-group | ||
| 9 | - = f.label :title, :class => "control-label" | ||
| 10 | - .controls= f.text_area :title, :class => "input-xxlarge", :maxlength => 255, :rows => 5 | ||
| 11 | - .control-group | ||
| 12 | - = f.label :source_branch, "From", :class => "control-label" | ||
| 13 | - .controls | ||
| 14 | - = f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") | ||
| 15 | - .mr_source_commit | ||
| 16 | - .control-group | ||
| 17 | - = f.label :target_branch, "To", :class => "control-label" | ||
| 18 | - .controls | ||
| 19 | - = f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") | ||
| 20 | - .mr_target_commit | 8 | + |
| 9 | + | ||
| 10 | + %h3.padded.cgray 1. Select Branches | ||
| 11 | + .row | ||
| 12 | + .span6 | ||
| 13 | + .ui-box | ||
| 14 | + %h5 From (Head Branch) | ||
| 15 | + .body | ||
| 16 | + .padded | ||
| 17 | + = f.label :source_branch, "From", :class => "control-label" | ||
| 18 | + .controls | ||
| 19 | + = f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") | ||
| 20 | + %hr | ||
| 21 | + .mr_source_commit | ||
| 22 | + .clearfix | ||
| 23 | + | ||
| 24 | + .span6 | ||
| 25 | + .ui-box | ||
| 26 | + %h5 To (Base Branch) | ||
| 27 | + .body | ||
| 28 | + .padded | ||
| 29 | + = f.label :target_branch, "To", :class => "control-label" | ||
| 30 | + .controls | ||
| 31 | + = f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") | ||
| 32 | + %hr | ||
| 33 | + .mr_target_commit | ||
| 34 | + .clearfix | ||
| 35 | + | ||
| 36 | + %h3.padded.cgray 2. Fill info | ||
| 21 | .clearfix | 37 | .clearfix |
| 22 | = f.label :assignee_id, "Assign to", :class => "control-label" | 38 | = f.label :assignee_id, "Assign to", :class => "control-label" |
| 23 | .controls= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px") | 39 | .controls= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px") |
| 24 | 40 | ||
| 41 | + .control-group | ||
| 42 | + = f.label :title, :class => "control-label" | ||
| 43 | + .controls= f.text_field :title, :class => "input-xxlarge pad", :maxlength => 255, :rows => 5 | ||
| 44 | + | ||
| 25 | .form-actions | 45 | .form-actions |
| 26 | = f.submit 'Save', :class => "btn-primary btn" | 46 | = f.submit 'Save', :class => "btn-primary btn" |
| 27 | - if @merge_request.new_record? | 47 | - if @merge_request.new_record? |
| @@ -38,14 +58,18 @@ | @@ -38,14 +58,18 @@ | ||
| 38 | $('select#merge_request_assignee_id').chosen(); | 58 | $('select#merge_request_assignee_id').chosen(); |
| 39 | $('select#merge_request_source_branch').chosen(); | 59 | $('select#merge_request_source_branch').chosen(); |
| 40 | $('select#merge_request_target_branch').chosen(); | 60 | $('select#merge_request_target_branch').chosen(); |
| 61 | + var source_branch = $("#merge_request_source_branch"); | ||
| 62 | + var target_branch = $("#merge_request_target_branch"); | ||
| 41 | 63 | ||
| 64 | + | ||
| 65 | + $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); | ||
| 66 | + $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); | ||
| 42 | 67 | ||
| 43 | - | ||
| 44 | - $("#merge_request_source_branch").live("change", function() { | 68 | + source_branch.live("change", function() { |
| 45 | $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: $(this).val() }); | 69 | $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: $(this).val() }); |
| 46 | }); | 70 | }); |
| 47 | 71 | ||
| 48 | - $("#merge_request_target_branch").live("change", function() { | 72 | + target_branch.live("change", function() { |
| 49 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); | 73 | $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); |
| 50 | }); | 74 | }); |
| 51 | }); | 75 | }); |
config/routes.rb
| 1 | Gitlab::Application.routes.draw do | 1 | Gitlab::Application.routes.draw do |
| 2 | + # | ||
| 3 | + # Search | ||
| 4 | + # | ||
| 2 | get 'search' => "search#show" | 5 | get 'search' => "search#show" |
| 3 | 6 | ||
| 4 | # Optionally, enable Resque here | 7 | # Optionally, enable Resque here |
| 5 | require 'resque/server' | 8 | require 'resque/server' |
| 6 | mount Resque::Server.new, at: '/info/resque' | 9 | mount Resque::Server.new, at: '/info/resque' |
| 7 | 10 | ||
| 11 | + # | ||
| 12 | + # Help | ||
| 13 | + # | ||
| 8 | get 'help' => 'help#index' | 14 | get 'help' => 'help#index' |
| 9 | get 'help/permissions' => 'help#permissions' | 15 | get 'help/permissions' => 'help#permissions' |
| 10 | get 'help/workflow' => 'help#workflow' | 16 | get 'help/workflow' => 'help#workflow' |
| 11 | get 'help/web_hooks' => 'help#web_hooks' | 17 | get 'help/web_hooks' => 'help#web_hooks' |
| 12 | 18 | ||
| 19 | + # | ||
| 20 | + # Admin Area | ||
| 21 | + # | ||
| 13 | namespace :admin do | 22 | namespace :admin do |
| 14 | resources :users do | 23 | resources :users do |
| 15 | member do | 24 | member do |
| @@ -44,6 +53,7 @@ Gitlab::Application.routes.draw do | @@ -44,6 +53,7 @@ Gitlab::Application.routes.draw do | ||
| 44 | get "profile", :to => "profile#show" | 53 | get "profile", :to => "profile#show" |
| 45 | get "profile/design", :to => "profile#design" | 54 | get "profile/design", :to => "profile#design" |
| 46 | put "profile/update", :to => "profile#update" | 55 | put "profile/update", :to => "profile#update" |
| 56 | + resources :keys | ||
| 47 | 57 | ||
| 48 | # | 58 | # |
| 49 | # Dashboard Area | 59 | # Dashboard Area |
| @@ -53,10 +63,12 @@ Gitlab::Application.routes.draw do | @@ -53,10 +63,12 @@ Gitlab::Application.routes.draw do | ||
| 53 | get "dashboard/merge_requests", :to => "dashboard#merge_requests" | 63 | get "dashboard/merge_requests", :to => "dashboard#merge_requests" |
| 54 | 64 | ||
| 55 | resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create] | 65 | resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create] |
| 56 | - resources :keys | ||
| 57 | 66 | ||
| 58 | devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks } | 67 | devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks } |
| 59 | 68 | ||
| 69 | + # | ||
| 70 | + # Project Area | ||
| 71 | + # | ||
| 60 | resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do | 72 | resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do |
| 61 | member do | 73 | member do |
| 62 | get "team" | 74 | get "team" |