From 5527adb795955ece6fa6f9c8c2bedc52994a1ab7 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 15 Dec 2016 17:03:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC406=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8Cpull=20request=20=E5=86=B2=E7=AA=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=97=E5=90=8E406=E5=BC=82=E5=B8=B8=E6=8F=90?= =?UTF-8?q?=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 14 ++++++++++---- app/views/pull_requests/_show.html.erb | 4 +++- app/views/pull_requests/_show_container.html.erb | 8 ++++---- app/views/pull_requests/accept_pull_request.js.erb | 2 ++ config/locales/projects/zh.yml | 3 ++- lib/gitlab-cli/lib/gitlab/error.rb | 3 +++ lib/gitlab-cli/lib/gitlab/request.rb | 1 + 7 files changed, 25 insertions(+), 10 deletions(-) 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)