From 6319a1bac6236f3570f5aa8fefec07f6aec6429f Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 9 Aug 2016 10:53:44 +0800 Subject: [PATCH] =?UTF-8?q?PR=E6=B7=BB=E5=8A=A0=E8=AF=84=E8=AE=BA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 70 ++++++++++++++++++--- config/routes.rb | 1 + 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 7233bdfe7..8d11e7279 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -110,7 +110,20 @@ class PullRequestsController < ApplicationController end end - # 更新请求的状态state => cloesed + # Updates a merge request. + # + # @example + # Gitlab.update_merge_request(5, 42, :title => 'New title') + # + # @param [Integer] project The ID of a project. + # @param [Integer] id The ID of a merge request. + # @param [Hash] options A customizable set of options. + # @option options [String] :title The title of a merge request. + # @option options [String] :source_branch The source branch name. + # @option options [String] :target_branch The target branch name. + # @option options [Integer] :assignee_id The ID of a user to assign merge request. + # @option options [String] :state_event New state (close|reopen|merge). + # @return [Gitlab::ObjectifiedHash] Information about updated merge request. def update_pull_request begin @g.update_merge_request(@project.gpid, params[:id], :state_event => params[:state]) @@ -122,16 +135,57 @@ class PullRequestsController < ApplicationController end end - # 获取某次请求的提交次数 - def pull_request_commits - @type = parms[:type] - @commits = @g.merge_request_commits(@project.gpid, params[:id].to_i) + # Creates a merge request. + # + # @example + # Gitlab.create_merge_request(5, 'New merge request', + # :source_branch => 'source_branch', :target_branch => 'target_branch') + # Gitlab.create_merge_request(5, 'New merge request', + # :source_branch => 'source_branch', :target_branch => 'target_branch', :assignee_id => 42) + def create_pull_request_comment + content = params[:content] + begin + @comments = @g.create_merge_request_comment(@project.gpid, params[:id], content) + rescue Exception => e + @message = e.message + end end - # 获取某次请求的改动 + # Gets the comments on a merge request. + # + # @example + # Gitlab.merge_request_comments(5, 1) + def pull_request_comments + begin + @comments = @g.merge_request_comments(@project.gpid, params[:id]) + rescue Exception => e + @message = e.message + end + end + + # Get a list of merge request commits. + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of MR + def pull_request_commits + begin + @commits = @g.merge_request_commits(@project.gpid, params[:id]) + rescue Exception => e + @message = e.message + end + end + + # Shows information about the merge request including its files and changes. With GitLab 8.2 the return fields upvotes and downvotes are deprecated and always return 0. + # Parameters: + # id (required) - The ID of a project + # merge_request_id (required) - The ID of MR def pull_request_changes - @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) - @changes_count = @changes.count + begin + @changes = @g.merge_request_changes(@project.gpid, params[:id]).try(:changes) + @changes_count = @changes.count + rescue Exception => e + @message = e.message + end end private diff --git a/config/routes.rb b/config/routes.rb index eb822d27e..b50ee9c65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -817,6 +817,7 @@ RedmineApp::Application.routes.draw do get 'pull_request_commits' get 'pull_request_changes' get 'update_pull_request' + get 'pull_request_comments' end end