From be081f5c660d3cac3e2b1cb4a9f62ec005b61442 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 3 Aug 2016 13:57:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Api=EF=BC=88=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E5=86=85=E5=AE=B9=EF=BC=8C=E6=94=B9=E5=8A=A8=EF=BC=89?= =?UTF-8?q?=E5=8F=8A=E7=9B=B8=E5=85=B3=E6=96=B9=E6=B3=95=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/pull_requests_controller.rb | 24 ++++-- app/helpers/application_helper.rb | 6 ++ app/views/pull_requests/create.html.erb | 1 + app/views/pull_requests/index.html.erb | 2 +- app/views/pull_requests/new.html.erb | 83 +------------------ .../pull_requests/pull_request_changes.js.erb | 0 .../pull_requests/pull_request_commits.js.erb | 0 app/views/pull_requests/show.html.erb | 12 +-- config/routes.rb | 4 +- .../lib/gitlab/client/merge_requests.rb | 16 ++++ 10 files changed, 51 insertions(+), 97 deletions(-) create mode 100644 app/views/pull_requests/pull_request_changes.js.erb create mode 100644 app/views/pull_requests/pull_request_commits.js.erb diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index a0be304a3..8d49207ee 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -1,6 +1,6 @@ class PullRequestsController < ApplicationController before_filter :find_project_and_repository - before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pr] + before_filter :connect_gitlab, :only => [:index, :show, :create, :accept_pll_request, :pull_request_commits, :pull_request_changes] layout "base_projects" # 返回json格式 @@ -9,7 +9,6 @@ class PullRequestsController < ApplicationController end def new - end # Creates a merge request. @@ -35,9 +34,10 @@ class PullRequestsController < ApplicationController target_branch = params[:target_branch] begin request = @g.create_merge_request(@project.gpid, title, :description => description, :source_branch => source_branch, :target_branch => target_branch) - # respond_to do |format| - # format.html{redirect_to project_pull_requests_path} - # end + e.message + respond_to do |format| + format.html{redirect_to project_pull_requests_path(request.id, :source_branch => source_branch, :target_branch => target_branch)} + end rescue Exception => e @message = e.message respond_to do |format| @@ -48,7 +48,7 @@ class PullRequestsController < ApplicationController end def show - #@request = @g.merge_request(@rpoject.gpid, id) + @request = @g.merge_request(@project.gpid, params[:id]) end # Accept a merge request. @@ -61,7 +61,7 @@ class PullRequestsController < ApplicationController # @param [Integer] project The ID of a project. # @param [Integer] id The ID of a merge request. # @return [Gitlab::ObjectifiedHash] - def accept_pr + def accept_pull_request commit_id = parmas[:commit_id] status = @g.accept_pull_rquest(@project.gpid, commit_id) if status == '200' @@ -69,6 +69,16 @@ class PullRequestsController < ApplicationController end end + # 获取某次请求的提交次数 + def pull_request_commits + + end + + # 获取某次请求的改动 + def pull_request_changes + + end + private def connect_gitlab @g = Gitlab.client diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9d0439120..69da2657b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -43,6 +43,12 @@ module ApplicationHelper user.nil? ? User.find(2) : user end + # 通过系统外部用户名查找用户,如果用户不存在则用邮箱替换 + def get_user_by_login_and login + user = User.find_by_login(login) + user.nil? ? User.find(2) : user + end + # 历史数据(老版本库数据)处理完则可以修改该放放 def get_rep_identifier_by_project project identifier = Repository.where(:project_id => project.id, :type => "Repository::Gitlab").first.try(:identifier) diff --git a/app/views/pull_requests/create.html.erb b/app/views/pull_requests/create.html.erb index f51a0e654..034f30163 100644 --- a/app/views/pull_requests/create.html.erb +++ b/app/views/pull_requests/create.html.erb @@ -1,2 +1,3 @@ +<%= render :partial => "pull_requests/pull_request_container" %> <%= render :partial => "pull_requests/new" %> diff --git a/app/views/pull_requests/index.html.erb b/app/views/pull_requests/index.html.erb index 37ea937fd..56d72c5ce 100644 --- a/app/views/pull_requests/index.html.erb +++ b/app/views/pull_requests/index.html.erb @@ -18,7 +18,7 @@ <%=link_to request.title, project_pull_request_path(request.id, :project_id => @project.id), :class => "linkGrey3 fb fl"%>
- #5 · <%= link_to request.author.try(:username), user_path(request.author), :class => "link-blue" %> 创建于<%= time_tag(request.created_at) %> + <%= link_to request.author.try(:username), user_path(get_user_by_login_and(request.author.try(:username))), :class => "link-blue" %> 创建于<%= time_tag(request.created_at) %> <%= time_tag(request.updated_at) %>更新
diff --git a/app/views/pull_requests/new.html.erb b/app/views/pull_requests/new.html.erb index 3d3f9af61..e77c2d364 100644 --- a/app/views/pull_requests/new.html.erb +++ b/app/views/pull_requests/new.html.erb @@ -1,83 +1,2 @@ <%= render :partial => "pull_requests/pull_request_container" %> -
-
新的合并请求
-
- dev_huang 合并至 master修改分支 -
-
-
-<%= render :partial => "pull_requests/form" %> - -
根据最近提交时间排列
-
-
- 2016-08-02 -

1次提交

-
-
- 第一次提交 -

黄井泉创建于24小时前

-
-
- 5202e2ef -

浏览文件

-
-
-
-
- - -
- - - - - - - - - - - - - - - - - - - - - -
9999<% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %>
100100<div class="mt10">
111- <div class="fl mr5 fontGrey3">
111+ <div class="fl mr20 fontGrey3 w80">
-
-
- - \ No newline at end of file +<% render :partial => "pull_requests/new" %> \ No newline at end of file diff --git a/app/views/pull_requests/pull_request_changes.js.erb b/app/views/pull_requests/pull_request_changes.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/pull_requests/pull_request_commits.js.erb b/app/views/pull_requests/pull_request_commits.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/pull_requests/show.html.erb b/app/views/pull_requests/show.html.erb index 42c863fd0..7b489908f 100644 --- a/app/views/pull_requests/show.html.erb +++ b/app/views/pull_requests/show.html.erb @@ -1,19 +1,19 @@ <%= render :partial => "pull_requests/pull_request_container" %>
- 待处理合并请求 #1 · 由黄井泉于2小时前提交 · 最后编辑时间1小时前 + 待处理合并请求 由<%= link_to @request.author.try(:username), user_path(get_user_by_login_and(@request.author.try(:username))), :class => "link-blue" %>于<%= time_tag(@request.created_at) %>提交 · 最后编辑时间<%= time_tag(@request.updated_at) %> 编辑
-
请合并我的代码

Pull Request

+
<%= @request.title %>

<%= @request.description %>

- 请求将 rep_quality 合并至 develop + 请求将 <%= @request.source_branch %> 合并至 <%= @request.target_branch %>
- 接受请求 + <%= link_to "接受请求", accept_pull_request_project_pull_request_path(@request.id, :project_id => @project.id), :class => "BlueCirBtn" %>
根据最近提交时间排列
diff --git a/config/routes.rb b/config/routes.rb index 9194dd866..4c40a6fb7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -809,7 +809,9 @@ RedmineApp::Application.routes.draw do collection do end member do - post 'accept_pr' + post 'accept_pull_request' + get 'pull_request_commits' + get 'pull_request_changes' end end diff --git a/lib/gitlab-cli/lib/gitlab/client/merge_requests.rb b/lib/gitlab-cli/lib/gitlab/client/merge_requests.rb index ec7e1563e..d3b6714f3 100644 --- a/lib/gitlab-cli/lib/gitlab/client/merge_requests.rb +++ b/lib/gitlab-cli/lib/gitlab/client/merge_requests.rb @@ -82,6 +82,22 @@ class Gitlab::Client post("/projects/#{project}/merge_request/#{id}/comments", :body => {:note => note}) 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 merge_request_commits(project, id) + get("/projects/#{project}/merge_request/#{id}/commits") + 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 merge_request_changes(project, id) + get("/projects/#{project}/merge_request/#{id}/changes") + end + # Gets the comments on a merge request. # # @example