diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index b6fdd1fee..b50127b51 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -188,15 +188,21 @@ class PullRequestsController < ApplicationController # @return [Gitlab::ObjectifiedHash] def accept_pull_request begin - status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) + @status = @g.accept_merge_rquest(@project.gpid, params[:id], User.current.gid) # 接受后,给用户发消息 - send_message_to_author(@project.id, status.author.try(:username), params[:id], 2) + send_message_to_author(@project.id, @status.author.try(:username), params[:id], 2) respond_to do |format| - format.js{redirect_to project_pull_request_path(status.id, :project_id => @project.id)} + format.js{redirect_to project_pull_request_path(@status.id, :project_id => @project.id)} end + rescue Gitlab::Error::Forbidden => e + @message = l(:label_pull_request_forbidden) + rescue Gitlab::Error::DataNotAccepted => e + @message = l(:label_pull_request_datanotaccepted) + rescue Gitlab::Error::NotFound => e + @message = l(:label_pull_request_notfound) rescue Exception => e - @message = e.message + puts e end end diff --git a/app/views/pull_requests/_show.html.erb b/app/views/pull_requests/_show.html.erb index b40c9d6d4..3dd3483a5 100644 --- a/app/views/pull_requests/_show.html.erb +++ b/app/views/pull_requests/_show.html.erb @@ -34,7 +34,9 @@ 改动已合并至 <%= @request.target_branch %> 分支 <% else %> - <%= render "show_container" %> +
+ <%= render "show_container" %> +
<% end %> diff --git a/app/views/pull_requests/_show_container.html.erb b/app/views/pull_requests/_show_container.html.erb index 2016a6ed8..65da01790 100644 --- a/app/views/pull_requests/_show_container.html.erb +++ b/app/views/pull_requests/_show_container.html.erb @@ -6,10 +6,10 @@
项目分支 <%= @request.source_branch %> 和 <%= @request.target_branch %> 似乎没有差异,请将新改动提交至源分支或者切换到其它目标分支
-<%# elsif !@request.merge_when_build_succeeds %> - - - +<% elsif @request.try(:merge_status) == "cannot_be_merged" %> +
+ Pull Request中存在冲突,请先解决冲突或者手动进行合并。 +
<% else %> <% if is_project_manager?(User.current.id, @project.id) %>
diff --git a/app/views/pull_requests/accept_pull_request.js.erb b/app/views/pull_requests/accept_pull_request.js.erb index b9007d7a3..a03871bf9 100644 --- a/app/views/pull_requests/accept_pull_request.js.erb +++ b/app/views/pull_requests/accept_pull_request.js.erb @@ -1,2 +1,4 @@ $("#create_pull_request_error").html('<%= escape_javascript(render :partial => "pull_requests/error_message") %>'); + + diff --git a/config/locales/projects/zh.yml b/config/locales/projects/zh.yml index 3eeb912f5..acbc722d1 100644 --- a/config/locales/projects/zh.yml +++ b/config/locales/projects/zh.yml @@ -510,4 +510,5 @@ zh: label_pull_request_conflic: 您创建的Pull Request尚未被管理员接受或者关闭,不能重新创建 label_pull_request_forbidden: 您没有权限进行该操作 - label_pull_request_notfound: 您操作的页面不存在或者已被删除 \ No newline at end of file + label_pull_request_notfound: 您操作的页面不存在或者已被删除 + label_pull_request_datanotaccepted: Pull Request中存在冲突,请先解决冲突或者手动进行合并 \ No newline at end of file diff --git a/lib/gitlab-cli/lib/gitlab/error.rb b/lib/gitlab-cli/lib/gitlab/error.rb index 96a8a39d6..ced1da100 100644 --- a/lib/gitlab-cli/lib/gitlab/error.rb +++ b/lib/gitlab-cli/lib/gitlab/error.rb @@ -27,6 +27,9 @@ module Gitlab # Raised when API endpoint returns the HTTP status code 405. class MethodNotAllowed < Error; end + # Raised when API endpoint returns the HTTP status code 406. + class DataNotAccepted < Error; end + # Raised when API endpoint returns the HTTP status code 409. class Conflict < Error; end diff --git a/lib/gitlab-cli/lib/gitlab/request.rb b/lib/gitlab-cli/lib/gitlab/request.rb index 683c11776..e1bb1094f 100644 --- a/lib/gitlab-cli/lib/gitlab/request.rb +++ b/lib/gitlab-cli/lib/gitlab/request.rb @@ -68,6 +68,7 @@ module Gitlab when 403; raise Error::Forbidden.new error_message(response) when 404; raise Error::NotFound.new error_message(response) when 405; raise Error::MethodNotAllowed.new error_message(response) + when 406; raise Error::DataNotAccepted.new error_message(response) when 409; raise Error::Conflict.new error_message(response) when 500; raise Error::InternalServerError.new error_message(response) when 502; raise Error::BadGateway.new error_message(response)