Merge branch 'master' into 226-remove-API-calls-from-JS

Conflicts:
	app/assets/javascripts/angularjs/controllers/project_refs_controller.js
	config/routes.rb
This commit is contained in:
Vokhmin Alexey V 2013-07-23 19:23:20 +04:00
commit a098e00a1a
14 changed files with 90 additions and 26 deletions

View File

@ -43,6 +43,22 @@ RosaABF.controller('ProjectBranchesController', ['$scope', '$http', 'ApiProject'
$scope.singleton.project.branches_count = $scope.branches.length;
}
$scope.create = function(branch) {
branch.ui_container = false;
$scope.project_resource.$create_branch(
{
owner: $scope.project.owner.uname,
project: $scope.project.name,
from_ref: branch.ref,
new_ref: branch.new_ref
}, function() { // on success
$scope.getRefs();
}, function () { // on error
$scope.getRefs();
}
);
}
$scope.destroy = function(branch) {
$scope.project_resource.$delete_branch(
{owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref},

View File

@ -11,6 +11,7 @@ var ProjectRef = function(atts) {
//with some logic...
self.isTag = self.object.type == 'tag';
self.ui_container = false;
self.path = function(project) {
return '/' + project.fullname + '/tree/' + self.ref;

View File

@ -23,6 +23,11 @@ RosaABF.factory("ApiProject", ['$resource', function($resource) {
url: '/:owner/:project/branches/:ref', // ?sha=<sha>
method: 'PUT',
isArray : false
},
create_branch: {
url: '/:owner/:project/branches', // ?new_ref=<new_ref>&from_ref=<from_ref>
method: 'POST',
isArray : false
}
}
);

View File

@ -75,7 +75,10 @@ header menu ul li a {
td.actions ul {
float: right;
}
.text { font-size: 12px; }
.text {
font-size: 12px;
padding-top: 2px;
}
td {
border-bottom: 1px solid #a9c6dd;
padding: 0 20px;

View File

@ -4,8 +4,8 @@ class Projects::Git::TreesController < Projects::Git::BaseController
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy]
skip_authorize_resource :project, :only => [:destroy, :restore_branch]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch]
skip_authorize_resource :project, :only => [:destroy, :restore_branch, :create]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch, :create]
def show
unless request.xhr?
@ -41,8 +41,13 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end
def restore_branch
@project.restore_branch @treeish, params[:sha] if @treeish.present? && params[:sha].present?
render :nothing => true
status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422
render :nothing => true, :status => status
end
def create
status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422
render :nothing => true, :status => status
end
def destroy

View File

@ -37,7 +37,7 @@ module DiffHelper
end
prepare(args.merge({:filepath => filepath, :comments => comments, :in_discussion => in_discussion}))
res = "<table class='diff inline' cellspacing='0' cellpadding='0'>"
res = "<table class='diff inline' cellspacing='0' cellpadding='0' ng-non-bindable>"
res += "<tbody>"
res += renderer diff_display.data #diff_display.render(Git::Diff::InlineCallback.new comments, path)
res += tr_line_comments(comments) if in_discussion

View File

@ -42,7 +42,7 @@
%li{:class => ('selected' if act == :index && contr == :commits )}
= link_to t('project_menu.commits'), commits_path(project, treeish)
%li{:class => ('selected' if act == :branches && contr == :trees )}
= link_to t('project_menu.branches', :count => '{{singleton.project.branches_count}}'), branches_path(project, branch)
= link_to t('project_menu.branches', :count => '{{singleton.project.branches_count}}'), branch_path(project, branch)
%li.tags{:class => ('selected' if act == :tags && contr == :trees )}
= link_to t('project_menu.tags', :count => project.repo.tags.count), tags_path(project)
.both

View File

@ -21,13 +21,23 @@
%a{'ng-href' => '{{branch.path(project)}}' } {{branch.ref}}
%td.actions
%ul.actions
%li.text{'ng-show' => 'branch.ref == current_ref'}
= t('layout.projects.base_branch')
- if can?(:write, @project)
%li{'ng-hide' => 'branch.ref == current_ref'}
%li{'ng-hide' => 'branch.ref == current_ref || branch.ui_container'}
%a{:href => '', 'ng-click' => 'destroy(branch)'}
= t('layout.projects.delete_branch')
%li{'ng-hide' => 'branch.ref == current_ref'}
%li{'ng-hide' => 'branch.ui_container'}
%a{:href => '', 'ng-click' => 'branch.ui_container = true'}
= t('layout.projects.new_branch')
%li{'ng-show' => 'branch.ui_container'}
%form{'ng-submit' => 'create(branch)'}
%input{'ng-model' => 'branch.new_ref'}
%input{:type => 'submit', :value =>t('layout.create')}
%a{:href => '', 'ng-click' => 'branch.ui_container = false'}
= t('layout.cancel')
%li{'ng-hide' => 'branch.ref == current_ref || branch.ui_container'}
%a{'ng-href' => '{{branch.diff_path(project, current_ref)}}' }
= t('layout.projects.compare')
%li.text{'ng-show' => 'branch.ref == current_ref && !branch.ui_container'}
= t('layout.projects.base_branch')

View File

@ -28,6 +28,7 @@ en:
new_build_list: New build
confirm_delete: Are you sure you want to delete this project?
new: New project
new_branch: New branch
location: Location
git_repo_location: Path to git repo
current_project_header: Current project

View File

@ -28,6 +28,7 @@ ru:
new_build_list: Новая сборка
confirm_delete: Вы уверены, что хотите удалить этот проект?
new: Новый проект
new_branch: Новая ветка
location: Расположение
git_repo_location: Путь к git-репозиторию
current_project_header: Текущий проект

View File

@ -335,10 +335,11 @@ Rosa::Application.routes.draw do
# Tags
get '/tags' => "git/trees#tags", :as => :tags
# Branches
get '/branches/:treeish' => "git/trees#branches", :as => :branches
get '/branches' => "git/trees#branches", :as => :branches
delete '/branches/:treeish' => "git/trees#destroy", :as => :branches
put '/branches/:treeish' => "git/trees#restore_branch", :as => :branches
get '/branches/:treeish' => "git/trees#branches", :as => :branch
delete '/branches/:treeish' => "git/trees#destroy", :as => :branch
put '/branches/:treeish' => "git/trees#restore_branch", :as => :branch
post '/branches' => "git/trees#create", :as => :branches
# Commits
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit

View File

@ -33,16 +33,22 @@ module Modules
repo.tags.map(&:name) + repo.branches.map(&:name)
end
# TODO: return something else instead of empty string on success and error
def restore_branch(branch, sha)
repo.git.native(:branch, {}, branch, sha)
def create_branch(new_ref, from_ref, user)
return false if new_ref.blank? || from_ref.blank? || !(from_commit = repo.commit(from_ref))
status, out, err = repo.git.native(:branch, {:process_info => true}, new_ref, from_commit.id)
if status == 0
Resque.enqueue(GitHook, owner.uname, name, from_commit.id, GitHook::ZERO, "refs/heads/#{new_ref}", 'commit', "user-#{user.id}", nil)
return true
end
return false
end
def delete_branch(branch, user)
return false if default_branch == branch.name
message = repo.git.native(:branch, {}, '-D', branch.name)
if message.present?
Resque.enqueue(GitHook,owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
Resque.enqueue(GitHook, owner.uname, name, GitHook::ZERO, branch.commit.id, "refs/heads/#{branch.name}", 'commit', "user-#{user.id}", message)
end
return message.present?
end

View File

@ -47,6 +47,11 @@ describe Projects::Git::TreesController do
response.should_not be_success
end
it 'should not be able to perform create action' do
post :create, @params.merge(:treeish => '', :from_ref => 'master', :new_ref => 'master-1')
response.should_not be_success
end
end
context 'for other user' do
@ -80,6 +85,11 @@ describe Projects::Git::TreesController do
response.should_not be_success
end
it 'should not be able to perform create action' do
post :create, @params.merge(:treeish => '', :from_ref => 'master', :new_ref => 'master-1')
response.should_not be_success
end
[:tags, :branches].each do |action|
it "should be able to perform #{action} action" do
get action, @params.merge(:treeish => 'master')
@ -106,7 +116,12 @@ describe Projects::Git::TreesController do
end
it 'should be able to perform restore_branch action' do
put :restore_branch, @params.merge(:treeish => 'conflicts')
put :restore_branch, @params.merge(:treeish => 'master-1', :sha => 'master')
response.should be_success
end
it 'should be able to perform create action' do
post :create, @params.merge(:treeish => '', :from_ref => 'master', :new_ref => 'master-1')
response.should be_success
end
end

View File

@ -117,21 +117,21 @@ describe Project do
end
end
context '#restore_branch' do
context '#create_branch' do
before do
project.delete_branch(branch, user)
end
xit 'ensures that returns true on success' do
project.restore_branch(branch.name, branch.commit.id).should be_true
it 'ensures that returns true on success' do
project.create_branch(branch.name, branch.commit.id, user).should be_true
end
it 'ensures that branch has been restored' do
lambda { project.restore_branch(branch.name, branch.commit.id) }.should change{ project.repo.branches.count }.by(1)
it 'ensures that branch has been created' do
lambda { project.create_branch(branch.name, branch.commit.id, user) }.should change{ project.repo.branches.count }.by(1)
end
xit 'ensures that returns false on restore wrong branch' do
project.restore_branch(branch.name, GitHook::ZERO).should be_false
it 'ensures that returns false on create wrong branch' do
project.create_branch(branch.name, GitHook::ZERO, user).should be_false
end
end