添加Api(提交内容,改动)及相关方法路由

dev_blankdatabase
huang 9 years ago
parent 1cb6809bdf
commit be081f5c66

@ -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

@ -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)

@ -1,2 +1,3 @@
<%= render :partial => "pull_requests/pull_request_container" %>
<%= render :partial => "pull_requests/new" %>

@ -18,7 +18,7 @@
<%=link_to request.title, project_pull_request_path(request.id, :project_id => @project.id), :class => "linkGrey3 fb fl"%>
<!--<a href="javascript:void(0);" class="fr fontGrey2 fb"><img src="/images/comments.png" class="mr5" width="15" />0</a><span class="fr mr15 fb fontGrey2">关闭</span>-->
<div class="cl mb5"></div>
<span class="fontGrey2">#5 · <%= link_to request.author.try(:username), user_path(request.author), :class => "link-blue" %> 创建于<%= time_tag(request.created_at) %></span>
<span class="fontGrey2"><%= 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) %></span>
<span class="fr fontGrey2"><%= time_tag(request.updated_at) %>更新</span>
<div class="cl"></div>
</li>

@ -1,83 +1,2 @@
<%= render :partial => "pull_requests/pull_request_container" %>
<div id="new-merge-request" class="new-merge-request">
<div class="f14 fontGrey3 fb mb10">新的合并请求</div>
<div>
<span class="fl fontGrey2">从 <span class="fontGrey3 fb">dev_huang</span> 合并至 <span class="fontGrey3 fb">master</span></span><a href="javascript:void(0);" class="fr linkGrey2">修改分支</a>
<div class="cl"></div>
</div>
</div>
<%= render :partial => "pull_requests/form" %>
<ul class="merge-record">
<li><a href="javascript:void(0);" class="active">提交<span class="project-number-dot">1</span></a></li>
<li><a href="javascript:void(0);">改动<span class="project-number-dot">1</span></a></li>
</ul>
<div class="new-merge-row b_grey fontGrey2"><span class="ml10"> 根据最近提交时间排列</span></div>
<div class="new-merge-wrap" id="merge_record_0">
<div class="merge-commit-time">
<img width="16" class="ui-datepicker-trigger mr15" style="cursor:default; margin-top:3px; margin-left:0;" /><span class="fontGrey3">2016-08-02</span>
<p class="mt10 fontGrey2">1次提交</p>
</div>
<div class="merge-commit-detail">
<span class="fontGrey3 fb">第一次提交</span>
<p class="mt10 fontGrey2">黄井泉创建于24小时前</p>
</div>
<div class="merge-commit-code">
<span class="fontGrey3">5202e2ef</span>
<p class="mt10"><a href="javascript:void(0);" class="link-blue">浏览文件</a></p>
</div>
<div class="cl"></div>
</div>
<div id="merge_record_1" class="undis">
<div class="showing-changes-row fontGrey2" style="width:730px; margin:0 -10px;">Showing <a href="javascript:void(0)" class="linkGrey3 fb" id="changed-files">3 changed files</a> with <span class="c_green fb">3 additions</span> and <span class="c_red fb">3 deletions</span>
<ol class="mt10" id="changed-files-detail">
<li><a href="javascript:void(0)" class="linkGrey3">app/views/organizations/_org_course_homework.html.erb</a> </li>
<li><a href="javascript:void(0)" class="linkGrey3">app/views/users/_course_homework.html.erb</a> </li>
<li><a href="javascript:void(0)" class="linkGrey3">app/views/users/_user_homework_detail.html.erb</a> </li>
</ol>
</div>
<div class="showing-changes-row fontGrey2" style="width:730px; margin:0 -10px;"><a href="javascript:void(0)" class="linkGrey3"><img src="/images/vlicon/file.png" width="18" height="20" style="vertical-align:middle;" class="mr5" />app/views/organizations/_org_course_homework.html.erb</a></div>
<div class="showing-changes-detail" style="width:750px; margin:0 -10px;">
<table class="changes-detail-chart">
<tr>
<td class="diff-line-number fontGrey2">99</td>
<td class="diff-line-number fontGrey2">99</td>
<td class="fontGrey2 p10">&lt;% if activity.homework_type == 3 && activity.homework_detail_group.base_on_project == 1 %&gt;</td>
</tr>
<tr>
<td class="diff-line-number fontGrey2">100</td>
<td class="diff-line-number fontGrey2">100</td>
<td class="fontGrey2 p10">&lt;div class="mt10"&gt;</td>
</tr>
<tr>
<td class="diff-line-number fontGrey2 number-line-old">111</td>
<td class="diff-line-number fontGrey2 number-line-old"></td>
<td class="fontGrey2 p10 code-line-old">- &lt;div class="fl mr5 fontGrey3"&gt;</td>
</tr>
<tr class="code-line-new">
<td class="diff-line-number fontGrey2 number-line-new"></td>
<td class="diff-line-number fontGrey2 number-line-new">111</td>
<td class="fontGrey2 p10 code-line-new">+ &lt;div class="fl mr20 fontGrey3 w80"&gt;</td>
</tr>
</table>
</div>
</div>
<script>
$("#new-merge-request").parent().css("width","730px");
$("#changed-files").toggle(function(){
$("#changed-files-detail").show();
},function(){
$("#changed-files-detail").hide();
});
$(".merge-record li a").click(function(){
$(".merge-record li a").removeClass("active");
$(this).addClass("active");
var index = $(".merge-record li a").index(this);
$("#merge_record_0, #merge_record_1").hide();
$("#merge_record_" + index).show();
});
</script>
<% render :partial => "pull_requests/new" %>

@ -1,19 +1,19 @@
<%= render :partial => "pull_requests/pull_request_container" %>
<div id="mergeShow" class="f14 fontGrey2 merge-show">
<span class="mr10 open-status">待处理</span><span class="mr10">合并请求</span> #1 · 由黄井泉于2小时前提交 · 最后编辑时间1小时前
<span class="mr10 open-status">待处理</span><span class="mr10">合并请求</span> 由<%= 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) %>
<a href="javascript:void(0);" class="BlueCirBtnMini fr mt5">编辑</a>
<div class="cl"></div>
</div>
<div class="new-merge-row b_grey"><strong>请合并我的代码</strong><p class="mt10">Pull Request</p></div>
<div class="new-merge-row b_grey"><strong><%= @request.title %></strong><p class="mt10"><%= @request.description %></p></div>
<div class="mt10 mb15">
请求将 <span class="fontGrey3 fb">rep_quality</span> 合并至 <span class="fontGrey3 fb">develop</span>
请求将 <span class="fontGrey3 fb"><%= @request.source_branch %></span> 合并至 <span class="fontGrey3 fb"><%= @request.target_branch %></span>
<div class="merge-commit-option mt15">
<a href="javascript:void(0);" class="BlueCirBtn">接受请求</a>
<%= link_to "接受请求", accept_pull_request_project_pull_request_path(@request.id, :project_id => @project.id), :class => "BlueCirBtn" %>
</div>
</div>
<ul class="merge-record" style="border-top:1px solid #ddd;">
<li><a href="javascript:void(0);" class="active">提交<span class="project-number-dot">1</span></a></li>
<li><a href="javascript:void(0);">改动<span class="project-number-dot">1</span></a></li>
<li><%= link_to "提交<span class='project-number-dot'>1</span>".html_safe, pull_request_commits_project_pull_request_path(@request.id, :project_id => @project.id), :remote => true, :class => "active" %></li>
<li><%= link_to "改动<span class='project-number-dot'>1</span>".html_safe, pull_request_changes_project_pull_request_path(@request.id, :project_id => @project.id), :remote => true, :class => "active" %></li>
</ul>
<div class="new-merge-row b_grey fontGrey2"><span class="ml10"> 根据最近提交时间排列</span></div>
<div class="new-merge-wrap" id="merge_record_0">

@ -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

@ -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

Loading…
Cancel
Save