From eb4d4806f4a252cec3107fcbc8a43839df82e693 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Jul 2013 14:07:39 +0400 Subject: [PATCH 1/4] #226: updated Branches and Tags views, JS, etc. --- .../project_branches_controller.js | 64 +++++++++++++++++ .../controllers/project_refs_controller.js | 70 ------------------- .../controllers/project_tags_controller.js | 31 ++++++++ .../javascripts/angularjs/services/project.js | 23 ++++-- app/controllers/api/v1/projects_controller.rb | 3 +- .../projects/git/trees_controller.rb | 18 +++-- .../api/v1/projects/refs_list.json.jbuilder | 1 - app/views/api/v1/projects/show.json.jbuilder | 2 +- .../projects/git/trees/branches.html.haml | 3 +- .../git/trees/refs_list.json.jbuilder | 8 +++ .../projects/git/trees/show.json.jbuilder | 7 ++ app/views/projects/git/trees/tags.html.haml | 2 +- config/routes.rb | 1 + 13 files changed, 148 insertions(+), 85 deletions(-) create mode 100644 app/assets/javascripts/angularjs/controllers/project_branches_controller.js delete mode 100644 app/assets/javascripts/angularjs/controllers/project_refs_controller.js create mode 100644 app/assets/javascripts/angularjs/controllers/project_tags_controller.js create mode 100644 app/views/projects/git/trees/refs_list.json.jbuilder create mode 100644 app/views/projects/git/trees/show.json.jbuilder diff --git a/app/assets/javascripts/angularjs/controllers/project_branches_controller.js b/app/assets/javascripts/angularjs/controllers/project_branches_controller.js new file mode 100644 index 000000000..d181dbb33 --- /dev/null +++ b/app/assets/javascripts/angularjs/controllers/project_branches_controller.js @@ -0,0 +1,64 @@ +RosaABF.controller('ProjectBranchesController', ['$scope', '$http', 'ApiProject', function($scope, $http, ApiProject) { + + $scope.singleton = ApiProject.singleton; + $scope.branches = []; + + $scope.current_ref = null; + $scope.project_resource = null; + + $scope.init = function(owner_uname, project_name, ref) { + $scope.current_ref = ref; + + $scope.project_resource = ApiProject.resource.get( + {owner: owner_uname, project: project_name}, + function(results) { + $scope.project = new Project(results.project); + $scope.getBranches(); + } + ); + + } + + $scope.getBranches = function() { + + $scope.project_resource.$branches( + {owner: $scope.project.owner.uname, project: $scope.project.name}, + function(results) { + $scope.branches = []; + _.each(results.refs_list, function(ref){ + var result = new ProjectRef(ref); + if (result.ref == $scope.current_ref) { + $scope.branches.unshift(result); + } else { + $scope.branches.push(result); + } + }); + $scope.updateBranchesCount(); + } + ); + + } + + $scope.updateBranchesCount = function() { + $scope.singleton.project.branches_count = $scope.branches.length; + } + + $scope.destroy = function(branch) { + $scope.project_resource.$delete_branch( + {owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref}, + function() { // on success + var i = $scope.branches.indexOf(branch); + if(i != -1) { $scope.branches.splice(i, 1); } + + $scope.updateBranchesCount(); + // Removes branch from "Current branch/tag:" select box + $('#branch_selector option').filter(function() { + return this.value.match('.*\/branches\/' + branch.ref + '$'); + }).remove(); + }, function () { // on error + $scope.getBranches(); + } + ); + } + +}]); \ No newline at end of file diff --git a/app/assets/javascripts/angularjs/controllers/project_refs_controller.js b/app/assets/javascripts/angularjs/controllers/project_refs_controller.js deleted file mode 100644 index a7b7e1ffa..000000000 --- a/app/assets/javascripts/angularjs/controllers/project_refs_controller.js +++ /dev/null @@ -1,70 +0,0 @@ -RosaABF.controller('ProjectRefsController', ['$scope', '$http', 'ApiProject', function($scope, $http, ApiProject) { - - $scope.singleton = ApiProject.singleton; - $scope.branches = []; - $scope.tags = []; - - $scope.project_id = null; - $scope.current_ref = null; - $scope.project_resource = null; - - $scope.init = function(project_id, ref, locale) { - $scope.project_id = project_id; - $scope.current_ref = ref; - - $scope.project_resource = ApiProject.resource.get({id: $scope.project_id}, function(results) { - $scope.project = new Project(results.project); - $scope.getRefs(); - }); - - } - - $scope.getRefs = function() { - - $scope.project_resource.$refs({id: $scope.project_id}, function(results) { - $scope.tags = []; - $scope.branches = []; - _.each(results.refs_list, function(ref){ - var result = new ProjectRef(ref); - if (result.isTag) { - if (result.ref == $scope.current_ref) { - $scope.tags.unshift(result); - } else { - $scope.tags.push(result); - } - } else { - if (result.ref == $scope.current_ref) { - $scope.branches.unshift(result); - } else { - $scope.branches.push(result); - } - } - }); - $scope.updateBranchesCount(); - }); - - } - - $scope.updateBranchesCount = function() { - $scope.singleton.project.branches_count = $scope.branches.length; - } - - $scope.destroy = function(branch) { - $scope.project_resource.$delete_branch( - {owner: $scope.project.owner.uname, project: $scope.project.name, ref: branch.ref}, - function() { // on success - var i = $scope.branches.indexOf(branch); - if(i != -1) { $scope.branches.splice(i, 1); } - - $scope.updateBranchesCount(); - // Removes branch from "Current branch/tag:" select box - $('#branch_selector option').filter(function() { - return this.value.match('.*\/branches\/' + branch.ref + '$'); - }).remove(); - }, function () { // on error - $scope.getRefs(); - } - ); - } - -}]); \ No newline at end of file diff --git a/app/assets/javascripts/angularjs/controllers/project_tags_controller.js b/app/assets/javascripts/angularjs/controllers/project_tags_controller.js new file mode 100644 index 000000000..9042eb4c6 --- /dev/null +++ b/app/assets/javascripts/angularjs/controllers/project_tags_controller.js @@ -0,0 +1,31 @@ +RosaABF.controller('ProjectTagsController', ['$scope', '$http', 'ApiProject', function($scope, $http, ApiProject) { + + $scope.tags = []; + $scope.project_resource = null; + + $scope.init = function(owner_uname, project_name) { + $scope.project_resource = ApiProject.resource.get( + {owner: owner_uname, project: project_name}, + function(results) { + $scope.project = new Project(results.project); + $scope.getTags(); + } + ); + + } + + $scope.getTags = function() { + + $scope.project_resource.$tags( + {owner: $scope.project.owner.uname, project: $scope.project.name}, + function(results) { + $scope.tags = []; + _.each(results.refs_list, function(ref){ + $scope.tags.push(new ProjectRef(ref)); + }); + } + ); + + } + +}]); \ No newline at end of file diff --git a/app/assets/javascripts/angularjs/services/project.js b/app/assets/javascripts/angularjs/services/project.js index 66a55dff2..f8b65c9d3 100644 --- a/app/assets/javascripts/angularjs/services/project.js +++ b/app/assets/javascripts/angularjs/services/project.js @@ -1,11 +1,26 @@ RosaABF.factory("ApiProject", ['$resource', function($resource) { var ProjectResource = $resource( - '/api/v1/projects/:id.json', - {id: '@project.id'}, + '/:owner/:project', + {owner: '@project.owner.uname', project: '@project.name'}, { - refs: { - url: '/api/v1/projects/:id/refs_list.json', + // refs: { + // url: '/api/v1/projects/:id/refs_list.json', + // method: 'GET', + // isArray : false + // }, + update: { + url: '/api/v1/projects/:id.json', + method: 'PUT', + isArray: false + }, + tags: { + url: '/:owner/:project/tags', + method: 'GET', + isArray : false + }, + branches: { + url: '/:owner/:project/branches', method: 'GET', isArray : false }, diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 2353093f1..e115e54d1 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -23,8 +23,7 @@ class Api::V1::ProjectsController < Api::V1::BaseController end def refs_list - @refs = @project.repo.branches.sort_by(&:name) + - @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse + @refs = @project.repo.branches + @project.repo.tags.select{ |t| t.commit } end def update diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index 9cb34a9ba..8a6ed88be 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -8,10 +8,12 @@ class Projects::Git::TreesController < Projects::Git::BaseController before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch] def show - render('empty') and return if @project.is_empty? - @tree = @tree / @path if @path.present? - @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first - raise Grit::NoSuchPathError unless @commit + unless request.xhr? + render('empty') and return if @project.is_empty? + @tree = @tree / @path if @path.present? + @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first + raise Grit::NoSuchPathError unless @commit + end end def archive @@ -32,6 +34,10 @@ class Projects::Git::TreesController < Projects::Git::BaseController end def tags + if request.xhr? + @refs = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse + render :refs_list + end end def restore_branch @@ -45,6 +51,10 @@ class Projects::Git::TreesController < Projects::Git::BaseController end def branches + if request.xhr? + @refs = @project.repo.branches.sort_by(&:name) + render :refs_list + end end end diff --git a/app/views/api/v1/projects/refs_list.json.jbuilder b/app/views/api/v1/projects/refs_list.json.jbuilder index 20306f516..b41dacba7 100644 --- a/app/views/api/v1/projects/refs_list.json.jbuilder +++ b/app/views/api/v1/projects/refs_list.json.jbuilder @@ -3,7 +3,6 @@ json.refs_list @refs do |grit| json.object do json.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit') json.sha grit.commit.id - json.authored_date grit.commit.authored_date.to_i end end json.url refs_list_api_v1_project_path(@project.id, :format => :json) \ No newline at end of file diff --git a/app/views/api/v1/projects/show.json.jbuilder b/app/views/api/v1/projects/show.json.jbuilder index 7f1f963c9..fa6a13653 100644 --- a/app/views/api/v1/projects/show.json.jbuilder +++ b/app/views/api/v1/projects/show.json.jbuilder @@ -1,5 +1,5 @@ json.project do - json.partial! 'project', :project => @project + json.partial! 'api/v1/projects/project', :project => @project json.(@project, :visibility, :description, :ancestry, :has_issues, :has_wiki, :default_branch, :is_package, :average_build_time, :publish_i686_into_x86_64) json.created_at @project.created_at.to_i json.updated_at @project.updated_at.to_i diff --git a/app/views/projects/git/trees/branches.html.haml b/app/views/projects/git/trees/branches.html.haml index 912207c01..b4a0a621d 100644 --- a/app/views/projects/git/trees/branches.html.haml +++ b/app/views/projects/git/trees/branches.html.haml @@ -3,8 +3,7 @@ = render 'submenu' = render 'repo_block', :project => @project -%div{'ng-controller' => 'ProjectRefsController', - 'ng-init' => "init('#{@project.id}','#{@branch.try(:name)}')"} +%div{'ng-controller' => 'ProjectBranchesController', 'ng-init' => "init('#{@project.owner.uname}', '#{@project.name}','#{@branch.try(:name)}')"} %h3= t('layout.projects.branches') %p{'ng-show' => '!branches.length'}= t('layout.projects.no_branches') diff --git a/app/views/projects/git/trees/refs_list.json.jbuilder b/app/views/projects/git/trees/refs_list.json.jbuilder new file mode 100644 index 000000000..c53ee0a8a --- /dev/null +++ b/app/views/projects/git/trees/refs_list.json.jbuilder @@ -0,0 +1,8 @@ +json.refs_list @refs do |grit| + json.ref grit.name + json.object do + json.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit') + json.sha grit.commit.id + json.authored_date grit.commit.authored_date.to_i + end +end \ No newline at end of file diff --git a/app/views/projects/git/trees/show.json.jbuilder b/app/views/projects/git/trees/show.json.jbuilder new file mode 100644 index 000000000..d68653879 --- /dev/null +++ b/app/views/projects/git/trees/show.json.jbuilder @@ -0,0 +1,7 @@ +json.project do + json.partial! 'api/v1/projects/project', :project => @project + json.owner do + json.(@project.owner, :id, :name, :uname) + json.type @project.owner.class.name + end +end \ No newline at end of file diff --git a/app/views/projects/git/trees/tags.html.haml b/app/views/projects/git/trees/tags.html.haml index 26f05fa8d..f8a074c12 100644 --- a/app/views/projects/git/trees/tags.html.haml +++ b/app/views/projects/git/trees/tags.html.haml @@ -3,7 +3,7 @@ = render 'submenu' = render 'repo_block', :project => @project -%div{'ng-controller' => 'ProjectRefsController', 'ng-init' => "init('#{@project.id}')"} +%div{'ng-controller' => 'ProjectTagsController', 'ng-init' => "init('#{@project.owner.uname}', '#{@project.name}')"} %h3= t('layout.projects.tags') %p{'ng-show' => '!tags.length'}= t('layout.projects.no_tags') diff --git a/config/routes.rb b/config/routes.rb index be0045a48..6be62ae1e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -335,6 +335,7 @@ Rosa::Application.routes.draw do 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 # Commits From 157becb19628960af561f4f20849001d257184db Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Jul 2013 16:29:35 +0400 Subject: [PATCH 2/4] #226: removed API calls from JS --- .../controllers/pull_request_controller.js | 47 +++++++++---------- .../javascripts/angularjs/services/project.js | 10 ---- .../angularjs/services/pull_request.js | 7 +-- .../projects/pull_requests_controller.rb | 19 ++++++-- app/views/api/v1/projects/show.json.jbuilder | 2 +- .../projects/git/trees/show.json.jbuilder | 4 +- .../projects/pull_requests/_status.html.haml | 2 +- .../projects/pull_requests/show.html.haml | 2 +- .../projects/pull_requests/show.json.jbuilder | 39 +++++++++++++++ config/routes.rb | 1 + 10 files changed, 84 insertions(+), 49 deletions(-) create mode 100644 app/views/projects/pull_requests/show.json.jbuilder diff --git a/app/assets/javascripts/angularjs/controllers/pull_request_controller.js b/app/assets/javascripts/angularjs/controllers/pull_request_controller.js index 170531432..4073d41c7 100644 --- a/app/assets/javascripts/angularjs/controllers/pull_request_controller.js +++ b/app/assets/javascripts/angularjs/controllers/pull_request_controller.js @@ -1,9 +1,8 @@ RosaABF.controller('PullRequestController',['$scope', '$http', 'ApiPullRequest', 'ApiProject', 'DateTimeFormatter', function($scope, $http, ApiPullRequest, ApiProject, DateTimeFormatter) { - $scope.project_id = null; $scope.project_resource = null; - $scope.serial_id = null; + $scope.pull_params = null; $scope.pull = null; $scope.pull_resource = null; @@ -13,37 +12,36 @@ RosaABF.controller('PullRequestController',['$scope', '$http', 'ApiPullRequest', $scope.can_delete_branch = false; - $scope.init = function(project_id, serial_id) { - $scope.project_id = project_id; - $scope.serial_id = serial_id; + $scope.init = function(owner_uname, project_name, serial_id) { + $scope.pull_params = { + owner: owner_uname, + project: project_name, + serial_id: serial_id + }; $scope.getPullRequest(); } $scope.getPullRequest = function() { - $scope.pull_resource = ApiPullRequest.resource.get( - {project_id: $scope.project_id, serial_id: $scope.serial_id}, - function(results) { - $scope.pull = results.pull_request; - if ($scope.pull.merged_at) { $scope.merged_at = DateTimeFormatter.utc($scope.pull.merged_at); } - if ($scope.pull.closed_at) { $scope.closed_at = DateTimeFormatter.utc($scope.pull.closed_at); } - } - ); + $scope.pull_resource = ApiPullRequest.resource.get($scope.pull_params, function(results) { + $scope.pull = results.pull_request; + if ($scope.pull.merged_at) { $scope.merged_at = DateTimeFormatter.utc($scope.pull.merged_at); } + if ($scope.pull.closed_at) { $scope.closed_at = DateTimeFormatter.utc($scope.pull.closed_at); } + }); } // @param [from_ref] - sets only at first time $scope.getBranch = function(from_ref) { if (!$scope.project_resource) { - $scope.project_resource = ApiProject.resource.get({id: $scope.project_id}); + $scope.project_resource = ApiProject.resource.get($scope.pull_params); } // Fix: at first load // Cannot read property 'from_ref' of null if (!from_ref) { from_ref = $scope.pull.from_ref.ref; } - $scope.project_resource.$refs({id: $scope.project_id}, function(results) { + $scope.project_resource.$branches($scope.pull_params, function(results) { var branch = null; - _.each(results.refs_list, function(ref){ - var result = new ProjectRef(ref); - if (!result.isTag && result.ref == from_ref) { - branch = result; + _.each(results.refs_list, function(b){ + if (b.ref == from_ref) { + branch = new ProjectRef(b); return true; } }); @@ -52,15 +50,13 @@ RosaABF.controller('PullRequestController',['$scope', '$http', 'ApiPullRequest', } $scope.reopen = function() { - $scope.pull.status = 'reopen'; - $scope.pull_resource.$update(function() { + $scope.pull_resource.$update({pull_request_action: 'reopen'}, function() { $scope.getPullRequest(); }); } $scope.close = function() { - $scope.pull.status = 'close'; - $scope.pull_resource.$update(function() { + $scope.pull_resource.$update({pull_request_action: 'close'}, function() { $scope.getPullRequest(); }); } @@ -86,10 +82,9 @@ RosaABF.controller('PullRequestController',['$scope', '$http', 'ApiPullRequest', } $scope.branch_params = function() { - var project = $scope.pull.from_ref.project; return { - owner: project.fullname.replace(/\/.*/, ''), - project: project.name, + owner: $scope.pull_params.owner, + project: $scope.pull_params.project, ref: $scope.pull.from_ref.ref, sha: $scope.pull.from_ref.sha } diff --git a/app/assets/javascripts/angularjs/services/project.js b/app/assets/javascripts/angularjs/services/project.js index f8b65c9d3..1db0de864 100644 --- a/app/assets/javascripts/angularjs/services/project.js +++ b/app/assets/javascripts/angularjs/services/project.js @@ -4,16 +4,6 @@ RosaABF.factory("ApiProject", ['$resource', function($resource) { '/:owner/:project', {owner: '@project.owner.uname', project: '@project.name'}, { - // refs: { - // url: '/api/v1/projects/:id/refs_list.json', - // method: 'GET', - // isArray : false - // }, - update: { - url: '/api/v1/projects/:id.json', - method: 'PUT', - isArray: false - }, tags: { url: '/:owner/:project/tags', method: 'GET', diff --git a/app/assets/javascripts/angularjs/services/pull_request.js b/app/assets/javascripts/angularjs/services/pull_request.js index 65101139e..95aeb96ea 100644 --- a/app/assets/javascripts/angularjs/services/pull_request.js +++ b/app/assets/javascripts/angularjs/services/pull_request.js @@ -1,9 +1,10 @@ RosaABF.factory("ApiPullRequest", ['$resource', function($resource) { var PullRequestResource = $resource( - '/api/v1/projects/:project_id/pull_requests/:serial_id.json', + '/:owner/:project/pull_requests/:serial_id', { - project_id: '@pull_request.to_ref.project.id', + owner: '@pull_request.to_ref.project.owner_uname', + project: '@pull_request.to_ref.project.name', serial_id: '@pull_request.number' }, { @@ -12,7 +13,7 @@ RosaABF.factory("ApiPullRequest", ['$resource', function($resource) { isArray : false }, merge: { - url: '/api/v1/projects/:project_id/pull_requests/:serial_id/merge.json', + url: '/:owner/:project/pull_requests/:serial_id/merge', method: 'PUT', isArray: false } diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index bd34682fb..ed70b0fd2 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -67,22 +67,31 @@ class Projects::PullRequestsController < Projects::BaseController end end + def merge + status = @pull.merge!(current_user) ? 200 : 422 + render :nothing => true, :status => status + end + def update + status = 422 if (action = params[:pull_request_action]) && %w(close reopen).include?(params[:pull_request_action]) if @pull.send("can_#{action}?") @pull.set_user_and_time current_user @pull.send(action) @pull.check if @pull.open? + status = 200 end end - redirect_to project_pull_request_path(@pull.to_project, @pull) + render :nothing => true, :status => status end def show - if @pull.nil? - redirect_to project_issue_path(@project, @issue) - else - load_diff_commits_data + unless request.xhr? + if @pull.nil? + redirect_to project_issue_path(@project, @issue) + else + load_diff_commits_data + end end end diff --git a/app/views/api/v1/projects/show.json.jbuilder b/app/views/api/v1/projects/show.json.jbuilder index fa6a13653..7f1f963c9 100644 --- a/app/views/api/v1/projects/show.json.jbuilder +++ b/app/views/api/v1/projects/show.json.jbuilder @@ -1,5 +1,5 @@ json.project do - json.partial! 'api/v1/projects/project', :project => @project + json.partial! 'project', :project => @project json.(@project, :visibility, :description, :ancestry, :has_issues, :has_wiki, :default_branch, :is_package, :average_build_time, :publish_i686_into_x86_64) json.created_at @project.created_at.to_i json.updated_at @project.updated_at.to_i diff --git a/app/views/projects/git/trees/show.json.jbuilder b/app/views/projects/git/trees/show.json.jbuilder index d68653879..a40039220 100644 --- a/app/views/projects/git/trees/show.json.jbuilder +++ b/app/views/projects/git/trees/show.json.jbuilder @@ -1,7 +1,7 @@ json.project do - json.partial! 'api/v1/projects/project', :project => @project + json.(@project, :id, :name) + json.owner do json.(@project.owner, :id, :name, :uname) - json.type @project.owner.class.name end end \ No newline at end of file diff --git a/app/views/projects/pull_requests/_status.html.haml b/app/views/projects/pull_requests/_status.html.haml index cfb843693..84fbeb1d1 100644 --- a/app/views/projects/pull_requests/_status.html.haml +++ b/app/views/projects/pull_requests/_status.html.haml @@ -1,4 +1,4 @@ -- if can?(:merge, @pull) && @pull.can_merging? +- if can?(:merge, @pull) %a.button{:href => '', 'ng-click' => 'merge()', 'ng-show' => "pull.status == 'ready'"} = t 'projects.pull_requests.ready' .both diff --git a/app/views/projects/pull_requests/show.html.haml b/app/views/projects/pull_requests/show.html.haml index c11be9dee..f1971d3ad 100644 --- a/app/views/projects/pull_requests/show.html.haml +++ b/app/views/projects/pull_requests/show.html.haml @@ -2,7 +2,7 @@ -set_meta_tags :title => [title_object(@project), t('.title', :name => @pull.title.truncate(40), :user => @pull.user.try(:uname))] = render :partial => 'submenu' -%div{'ng-controller' => 'PullRequestController', 'ng-init' => "init('#{@project.id}', '#{@pull.serial_id}')"} +%div{'ng-controller' => 'PullRequestController', 'ng-init' => "init('#{@project.owner.uname}', '#{@project.name}', '#{@pull.serial_id}')"} %h3.bpadding10 - PullRequest::STATUSES.each do |status| diff --git a/app/views/projects/pull_requests/show.json.jbuilder b/app/views/projects/pull_requests/show.json.jbuilder new file mode 100644 index 000000000..e98b9c403 --- /dev/null +++ b/app/views/projects/pull_requests/show.json.jbuilder @@ -0,0 +1,39 @@ +json.pull_request do + + json.number @pull.serial_id + json.(@pull, :status) + json.to_ref do + json.ref @pull.to_ref + json.sha @pull.to_commit.try(:id) + json.project do + json.(@pull.to_project, :id, :name) + json.owner_uname @pull.to_project.owner.uname + end + end + json.from_ref do + json.ref @pull.from_ref + json.sha @pull.from_commit.try(:id) + json.project do + json.(@pull.from_project, :id, :name) + json.owner_uname @pull.to_project.owner.uname + end + end + + json.owner do + json.(@pull.user, :id, :name, :uname) + end + + json.assignee do + json.(@pull.issue.assignee, :id, :name, :uname) + end if @pull.issue.assignee + json.mergeable @pull.can_merging? + json.merged_at @pull.issue.closed_at.to_i if @pull.merged? + + json.closed_at @pull.issue.closed_at.to_i if @pull.merged? || @pull.closed? + json.closed_by do + json.(@pull.issue.closer, :id, :name, :uname) + end if @pull.issue.closer + json.merged_by do + json.(@pull.issue.closer, :id, :name, :uname) + end if @pull.merged? +end diff --git a/config/routes.rb b/config/routes.rb index 6be62ae1e..78807a1c6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -310,6 +310,7 @@ Rosa::Application.routes.draw do resources :hooks, :except => :show resources :pull_requests, :except => :destroy do get :autocomplete_to_project, :on => :collection + put :merge, :on => :member end post '/preview' => 'projects#preview', :as => 'md_preview' post 'refs_list' => 'projects#refs_list', :as => 'refs_list' From 202ef4fe55ea1d0993656a7cfff061511491eb65 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Jul 2013 17:04:34 +0400 Subject: [PATCH 3/4] #226: rollback and fixed specs --- .../projects/pull_requests_controller_spec.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/controllers/projects/pull_requests_controller_spec.rb b/spec/controllers/projects/pull_requests_controller_spec.rb index 2eff7d9bb..d9cda7f6e 100644 --- a/spec/controllers/projects/pull_requests_controller_spec.rb +++ b/spec/controllers/projects/pull_requests_controller_spec.rb @@ -96,7 +96,13 @@ end shared_examples_for 'user with pull request update rights' do it 'should be able to perform update action' do put :update, @update_params - response.should redirect_to(project_pull_request_path(@pull.to_project, @pull)) + response.should be_success + end + + it 'should be able to perform merge action' do + @pull.check + put :merge, @update_params + response.should be_success end let(:pull) { @project.pull_requests.find(@pull) } @@ -146,6 +152,13 @@ shared_examples_for 'user without pull request update rights' do put :update, @wrong_update_params pull.issue.body.should_not =='updating' end + + it 'should be able to perform merge action' do + @pull.check + put :merge, @update_params + response.should_not be_success + end + end shared_examples_for 'pull request when project with issues turned off' do From 762cb25a28fef854f7cc003dceeff50320d90f21 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Tue, 23 Jul 2013 19:24:54 +0400 Subject: [PATCH 4/4] #226: fixed JS --- .../angularjs/controllers/project_branches_controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/angularjs/controllers/project_branches_controller.js b/app/assets/javascripts/angularjs/controllers/project_branches_controller.js index 8435a51f3..9fc754c6d 100644 --- a/app/assets/javascripts/angularjs/controllers/project_branches_controller.js +++ b/app/assets/javascripts/angularjs/controllers/project_branches_controller.js @@ -52,9 +52,9 @@ RosaABF.controller('ProjectBranchesController', ['$scope', '$http', 'ApiProject' from_ref: branch.ref, new_ref: branch.new_ref }, function() { // on success - $scope.getRefs(); + $scope.getBranches(); }, function () { // on error - $scope.getRefs(); + $scope.getBranches(); } ); }