diff --git a/app/controllers/merge_requests_controller.rb b/app/controllers/merge_requests_controller.rb index 54227fc2..b0d122b5 100644 --- a/app/controllers/merge_requests_controller.rb +++ b/app/controllers/merge_requests_controller.rb @@ -73,29 +73,21 @@ class MergeRequestsController < ApplicationController @merge_request = @project.merge_requests.new(params[:merge_request]) @merge_request.author = current_user - respond_to do |format| - if @merge_request.save - @merge_request.reload_code - format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' } - format.json { render json: @merge_request, status: :created, location: @merge_request } - else - format.html { render action: "new" } - format.json { render json: @merge_request.errors, status: :unprocessable_entity } - end + if @merge_request.save + @merge_request.reload_code + redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' + else + render action: "new" end end def update - respond_to do |format| - if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) - @merge_request.reload_code - @merge_request.mark_as_unchecked - format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' } - format.json { head :ok } - else - format.html { render action: "edit" } - format.json { render json: @merge_request.errors, status: :unprocessable_entity } - end + if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) + @merge_request.reload_code + @merge_request.mark_as_unchecked + redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' + else + render action: "edit" end end @@ -122,7 +114,6 @@ class MergeRequestsController < ApplicationController respond_to do |format| format.html { redirect_to project_merge_requests_url(@project) } - format.json { head :ok } end end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 036eb371..cd20677e 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -27,22 +27,14 @@ class RepositoriesController < ApplicationController render_404 and return end - ref = params[:ref] || @project.root_ref - commit = @project.commit(ref) - render_404 and return unless commit - # Build file path - file_name = @project.code + "-" + commit.id.to_s + ".tar.gz" - storage_path = File.join(Rails.root, "tmp", "repositories", @project.code) - file_path = File.join(storage_path, file_name) + file_path = @project.archive_repo(params[:ref]) - # Create file if not exists - unless File.exists?(file_path) - FileUtils.mkdir_p storage_path - file = @project.repo.archive_to_file(ref, nil, file_path) + if file_path + # Send file to user + send_file file_path + else + render_404 end - - # Send file to user - send_file file_path end end diff --git a/app/roles/repository.rb b/app/roles/repository.rb index 85ed6b7b..f61c7782 100644 --- a/app/roles/repository.rb +++ b/app/roles/repository.rb @@ -117,4 +117,28 @@ module Repository def root_ref? branch root_ref == branch end + + # Archive Project to .tar.gz + # + # Already packed repo archives stored at + # app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz + # + def archive_repo ref + ref = ref || self.root_ref + commit = self.commit(ref) + return nil unless commit + + # Build file path + file_name = self.code + "-" + commit.id.to_s + ".tar.gz" + storage_path = File.join(Rails.root, "tmp", "repositories", self.code) + file_path = File.join(storage_path, file_name) + + # Create file if not exists + unless File.exists?(file_path) + FileUtils.mkdir_p storage_path + file = self.repo.archive_to_file(ref, nil, file_path) + end + + file_path + end end diff --git a/app/views/merge_requests/_form.html.haml b/app/views/merge_requests/_form.html.haml index 3d6febc6..82d95577 100644 --- a/app/views/merge_requests/_form.html.haml +++ b/app/views/merge_requests/_form.html.haml @@ -5,23 +5,43 @@ - @merge_request.errors.full_messages.each do |msg| %li= msg - .control-group - = f.label :title, :class => "control-label" - .controls= f.text_area :title, :class => "input-xxlarge", :maxlength => 255, :rows => 5 - .control-group - = f.label :source_branch, "From", :class => "control-label" - .controls - = f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") - .mr_source_commit - .control-group - = f.label :target_branch, "To", :class => "control-label" - .controls - = f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") - .mr_target_commit + + + %h3.padded.cgray 1. Select Branches + .row + .span6 + .ui-box + %h5 From (Head Branch) + .body + .padded + = f.label :source_branch, "From", :class => "control-label" + .controls + = f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") + %hr + .mr_source_commit + .clearfix + + .span6 + .ui-box + %h5 To (Base Branch) + .body + .padded + = f.label :target_branch, "To", :class => "control-label" + .controls + = f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") + %hr + .mr_target_commit + .clearfix + + %h3.padded.cgray 2. Fill info .clearfix = f.label :assignee_id, "Assign to", :class => "control-label" .controls= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px") + .control-group + = f.label :title, :class => "control-label" + .controls= f.text_field :title, :class => "input-xxlarge pad", :maxlength => 255, :rows => 5 + .form-actions = f.submit 'Save', :class => "btn-primary btn" - if @merge_request.new_record? @@ -38,14 +58,18 @@ $('select#merge_request_assignee_id').chosen(); $('select#merge_request_source_branch').chosen(); $('select#merge_request_target_branch').chosen(); + var source_branch = $("#merge_request_source_branch"); + var target_branch = $("#merge_request_target_branch"); + + $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: source_branch.val() }); + $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: target_branch.val() }); - - $("#merge_request_source_branch").live("change", function() { + source_branch.live("change", function() { $.get("#{branch_from_project_merge_requests_path(@project)}", {ref: $(this).val() }); }); - $("#merge_request_target_branch").live("change", function() { + target_branch.live("change", function() { $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() }); }); }); diff --git a/config/routes.rb b/config/routes.rb index c3754bc6..d1dd03ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,15 +1,24 @@ Gitlab::Application.routes.draw do + # + # Search + # get 'search' => "search#show" # Optionally, enable Resque here require 'resque/server' mount Resque::Server.new, at: '/info/resque' + # + # Help + # get 'help' => 'help#index' get 'help/permissions' => 'help#permissions' get 'help/workflow' => 'help#workflow' get 'help/web_hooks' => 'help#web_hooks' + # + # Admin Area + # namespace :admin do resources :users do member do @@ -44,6 +53,7 @@ Gitlab::Application.routes.draw do get "profile", :to => "profile#show" get "profile/design", :to => "profile#design" put "profile/update", :to => "profile#update" + resources :keys # # Dashboard Area @@ -53,10 +63,12 @@ Gitlab::Application.routes.draw do get "dashboard/merge_requests", :to => "dashboard#merge_requests" resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create] - resources :keys devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks } + # + # Project Area + # resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do member do get "team"