Refactored project archive. Improved MR usability form

This commit is contained in:
Dmitriy Zaporozhets 2012-06-13 09:03:53 +03:00
parent edd81a79c5
commit a243253b10
5 changed files with 94 additions and 51 deletions

View file

@ -73,29 +73,21 @@ class MergeRequestsController < ApplicationController
@merge_request = @project.merge_requests.new(params[:merge_request]) @merge_request = @project.merge_requests.new(params[:merge_request])
@merge_request.author = current_user @merge_request.author = current_user
respond_to do |format|
if @merge_request.save if @merge_request.save
@merge_request.reload_code @merge_request.reload_code
format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.' } redirect_to [@project, @merge_request], notice: 'Merge request was successfully created.'
format.json { render json: @merge_request, status: :created, location: @merge_request }
else else
format.html { render action: "new" } render action: "new"
format.json { render json: @merge_request.errors, status: :unprocessable_entity }
end
end end
end end
def update def update
respond_to do |format|
if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id)) if @merge_request.update_attributes(params[:merge_request].merge(:author_id_of_changes => current_user.id))
@merge_request.reload_code @merge_request.reload_code
@merge_request.mark_as_unchecked @merge_request.mark_as_unchecked
format.html { redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.' } redirect_to [@project, @merge_request], notice: 'Merge request was successfully updated.'
format.json { head :ok }
else else
format.html { render action: "edit" } render action: "edit"
format.json { render json: @merge_request.errors, status: :unprocessable_entity }
end
end end
end end
@ -122,7 +114,6 @@ class MergeRequestsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html { redirect_to project_merge_requests_url(@project) } format.html { redirect_to project_merge_requests_url(@project) }
format.json { head :ok }
end end
end end

View file

@ -27,22 +27,14 @@ class RepositoriesController < ApplicationController
render_404 and return render_404 and return
end end
ref = params[:ref] || @project.root_ref
commit = @project.commit(ref)
render_404 and return unless commit
# Build file path file_path = @project.archive_repo(params[:ref])
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)
# 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)
end
if file_path
# Send file to user # Send file to user
send_file file_path send_file file_path
else
render_404
end
end end
end end

View file

@ -117,4 +117,28 @@ module Repository
def root_ref? branch def root_ref? branch
root_ref == branch root_ref == branch
end 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 end

View file

@ -5,23 +5,43 @@
- @merge_request.errors.full_messages.each do |msg| - @merge_request.errors.full_messages.each do |msg|
%li= msg %li= msg
.control-group
= f.label :title, :class => "control-label"
.controls= f.text_area :title, :class => "input-xxlarge", :maxlength => 255, :rows => 5 %h3.padded.cgray 1. Select Branches
.control-group .row
.span6
.ui-box
%h5 From (Head Branch)
.body
.padded
= f.label :source_branch, "From", :class => "control-label" = f.label :source_branch, "From", :class => "control-label"
.controls .controls
= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") = f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
%hr
.mr_source_commit .mr_source_commit
.control-group .clearfix
.span6
.ui-box
%h5 To (Base Branch)
.body
.padded
= f.label :target_branch, "To", :class => "control-label" = f.label :target_branch, "To", :class => "control-label"
.controls .controls
= f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px") = f.select(:target_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
%hr
.mr_target_commit .mr_target_commit
.clearfix .clearfix
%h3.padded.cgray 2. Fill info
.clearfix
= f.label :assignee_id, "Assign to", :class => "control-label" = 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") .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 .form-actions
= f.submit 'Save', :class => "btn-primary btn" = f.submit 'Save', :class => "btn-primary btn"
- if @merge_request.new_record? - if @merge_request.new_record?
@ -38,14 +58,18 @@
$('select#merge_request_assignee_id').chosen(); $('select#merge_request_assignee_id').chosen();
$('select#merge_request_source_branch').chosen(); $('select#merge_request_source_branch').chosen();
$('select#merge_request_target_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() }); $.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() }); $.get("#{branch_to_project_merge_requests_path(@project)}", {ref: $(this).val() });
}); });
}); });

View file

@ -1,15 +1,24 @@
Gitlab::Application.routes.draw do Gitlab::Application.routes.draw do
#
# Search
#
get 'search' => "search#show" get 'search' => "search#show"
# Optionally, enable Resque here # Optionally, enable Resque here
require 'resque/server' require 'resque/server'
mount Resque::Server.new, at: '/info/resque' mount Resque::Server.new, at: '/info/resque'
#
# Help
#
get 'help' => 'help#index' get 'help' => 'help#index'
get 'help/permissions' => 'help#permissions' get 'help/permissions' => 'help#permissions'
get 'help/workflow' => 'help#workflow' get 'help/workflow' => 'help#workflow'
get 'help/web_hooks' => 'help#web_hooks' get 'help/web_hooks' => 'help#web_hooks'
#
# Admin Area
#
namespace :admin do namespace :admin do
resources :users do resources :users do
member do member do
@ -44,6 +53,7 @@ Gitlab::Application.routes.draw do
get "profile", :to => "profile#show" get "profile", :to => "profile#show"
get "profile/design", :to => "profile#design" get "profile/design", :to => "profile#design"
put "profile/update", :to => "profile#update" put "profile/update", :to => "profile#update"
resources :keys
# #
# Dashboard Area # Dashboard Area
@ -53,10 +63,12 @@ Gitlab::Application.routes.draw do
get "dashboard/merge_requests", :to => "dashboard#merge_requests" get "dashboard/merge_requests", :to => "dashboard#merge_requests"
resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create] resources :projects, :constraints => { :id => /[^\/]+/ }, :only => [:new, :create]
resources :keys
devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks } devise_for :users, :controllers => { :omniauth_callbacks => :omniauth_callbacks }
#
# Project Area
#
resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do resources :projects, :constraints => { :id => /[^\/]+/ }, :except => [:new, :create, :index], :path => "/" do
member do member do
get "team" get "team"