forked from Gitlink/forgeplus
Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop
This commit is contained in:
commit
b68c5c1351
2
Gemfile
2
Gemfile
|
@ -142,6 +142,6 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 1.5.8'
|
||||
gem 'gitea-client', '~> 1.6.1'
|
||||
|
||||
gem 'loofah', '~> 2.20.0'
|
|
@ -1,5 +1,5 @@
|
|||
class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :diff, :recent]
|
||||
before_action :require_public_and_member_above, only: [:index, :diff, :recent, :files]
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
|
||||
|
@ -10,6 +10,14 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
|||
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def files
|
||||
if params[:filepath].present?
|
||||
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha_filepath(@project&.owner.login, @project&.identifier, params[:sha], CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
|
||||
else
|
||||
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha(@project&.owner.login, @project&.identifier, params[:sha], {query: {token: current_user&.gitea_token, page: page, limit: limit}})
|
||||
end
|
||||
end
|
||||
|
||||
def recent
|
||||
hash = Api::V1::Projects::Commits::RecentService.call(@project, {keyword: params[:keyword], page: page, limit: limit}, current_user&.gitea_token)
|
||||
@result_object = hash[:result]
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
class Api::V1::Projects::CompareController < Api::V1::BaseController
|
||||
|
||||
before_action :require_public_and_member_above, only: [:files]
|
||||
|
||||
def files
|
||||
load_compare_params
|
||||
if params[:type] == "sha"
|
||||
@compare_result ||= gitea_compare_files(@base, @head)
|
||||
else
|
||||
@compare_result ||= @head.include?(":") ? gitea_compare_files(@base, @head) : gitea_compare_files(@head, @base)
|
||||
@merge_status, @merge_message = get_merge_message
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_compare_params
|
||||
@base = params[:base].include?(":") ? Addressable::URI.unescape(params[:base].split(":")[0]) + ':' + Base64.decode64(params[:base].split(":")[1]) : Base64.decode64(params[:base])
|
||||
@head = params[:head].include?(":") ? Addressable::URI.unescape(params[:head].split(":")[0]) + ':' + Base64.decode64(params[:head].split(":")[1]) : Base64.decode64(params[:head])
|
||||
end
|
||||
|
||||
def gitea_compare_files(base, head)
|
||||
if params[:filepath].present?
|
||||
$gitea_hat_client.get_repos_compare_files_by_owner_repo_baseref_headref_filepath(@project&.owner&.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
|
||||
else
|
||||
$gitea_hat_client.get_repos_compare_files_by_owner_repo_baseref_headref(@project&.owner&.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), {query: {page:page,limit:limit,token: current_user&.gitea_token}})
|
||||
end
|
||||
end
|
||||
|
||||
def get_merge_message
|
||||
if @base.blank? || @head.blank?
|
||||
return -2, "请选择分支"
|
||||
else
|
||||
return -2, "目标仓库未开启合并请求(PR)功能" unless @project.has_menu_permission("pulls")
|
||||
if @head.include?(":")
|
||||
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
|
||||
return -2, "请选择正确的仓库" unless fork_project.present?
|
||||
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
|
||||
else
|
||||
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take
|
||||
end
|
||||
if @exist_pullrequest.present?
|
||||
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
|
||||
else
|
||||
Rails.logger.info @compare_result
|
||||
if params[:filepath].present?
|
||||
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||
return -2, "分支内容相同,无需创建合并请求"
|
||||
end
|
||||
else
|
||||
if @compare_result[:total_data].to_i < 1
|
||||
return -2, "分支内容相同,无需创建合并请求"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0, "可以合并"
|
||||
end
|
||||
end
|
|
@ -6,13 +6,21 @@ class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController
|
|||
@pulls = kaminari_paginate(@pulls)
|
||||
end
|
||||
|
||||
before_action :load_pull_request, only: [:show]
|
||||
before_action :load_pull_request, only: [:show, :files]
|
||||
|
||||
def show
|
||||
@result_object = Api::V1::Projects::Pulls::GetService.call(@project, @pull_request, current_user&.gitea_token)
|
||||
@last_review = @pull_request.reviews.order(created_at: :desc).take
|
||||
end
|
||||
|
||||
def files
|
||||
if params[:filepath].present?
|
||||
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index_filepath(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
|
||||
else
|
||||
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, {query: {isNew: "true",token: current_user&.gitea_token, page: page, limit: limit}})
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def query_params
|
||||
params.permit(:status, :keyword, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :sort_by, :sort_direction)
|
||||
|
|
|
@ -18,6 +18,7 @@ class CompareController < ApplicationController
|
|||
@page_limit = page_limit <=0 ? 15 : page_limit
|
||||
@page_offset = (@page_size -1) * @page_limit
|
||||
Rails.logger.info("+========#{@page_size}-#{@page_limit}-#{@page_offset}")
|
||||
Rails.logger.info @compare_result
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -36,7 +37,7 @@ class CompareController < ApplicationController
|
|||
if @exist_pullrequest.present?
|
||||
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
|
||||
else
|
||||
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||
if @compare_result["FilesCount"].to_i == 0 && @compare_result["CommitsCount"].to_i == 0
|
||||
return -2, "分支内容相同,无需创建合并请求"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,8 +151,8 @@ class RepositoriesController < ApplicationController
|
|||
return render_error('暂未开放,敬请期待.')
|
||||
else
|
||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token)
|
||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token, {diff: true})
|
||||
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status)
|
||||
# @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, @owner&.gitea_token, {diff: true})
|
||||
render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status)#|| @commit_diff.has_key?(:status)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class Gitea::Repository::Commits::ListService < Gitea::ClientService
|
|||
|
||||
private
|
||||
def params
|
||||
{ sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "", stat: args[:page].to_i != 1 && args[:limit] !=1 }
|
||||
{ sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "", stat: args[:page].to_i != 1 && args[:limit] !=1, files: false }
|
||||
end
|
||||
|
||||
def url
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
json.filename file["filename"]
|
||||
json.old_name file["old_name"]
|
||||
json.index file["index"]
|
||||
json.type file["type"]
|
||||
json.is_bin file["is_bin"]
|
||||
json.is_created file["is_created"]
|
||||
json.is_deleted file["is_deleted"]
|
||||
json.is_lfs_file file["is_lfs_file"]
|
||||
json.is_renamed file["is_renamed"]
|
||||
json.is_submodule file["is_submodule"]
|
||||
json.additions file["additions"]
|
||||
json.deletions file["deletions"]
|
||||
json.changes file["changes"]
|
||||
json.sha file["sha"]
|
|
@ -0,0 +1,10 @@
|
|||
if params[:filepath].present?
|
||||
json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object
|
||||
else
|
||||
json.file_nums @result_object[:total_data].to_i
|
||||
json.total_addition @result_object[:data]["total_addition"]
|
||||
json.total_deletion @result_object[:data]["total_deletion"]
|
||||
json.files @result_object[:data]["files"] do |file|
|
||||
json.partial! "api/v1/projects/simple_gitea_file", file: file
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
json.author do
|
||||
json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] }
|
||||
end
|
||||
|
||||
json.committer do
|
||||
json.partial! 'repositories/commit_author', locals: { user: render_cache_commit_author(commit['Committer']), name: commit['Committer']['Name'] }
|
||||
end
|
||||
json.timestamp render_unix_time(commit['Committer']['When'])
|
||||
json.time_from_now time_from_now(commit['Committer']['When'])
|
||||
json.created_at render_format_time_with_date(commit['Committer']['When'])
|
||||
json.message commit['CommitMessage']
|
||||
json.sha commit['Sha']
|
|
@ -0,0 +1,12 @@
|
|||
if params[:filepath].present?
|
||||
json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @compare_result['Diff']
|
||||
else
|
||||
json.file_nums @compare_result[:total_data].to_i
|
||||
json.total_addition @compare_result[:data]["total_addition"]
|
||||
json.total_deletion @compare_result[:data]["total_deletion"]
|
||||
json.files @compare_result[:data]["files"] do |file|
|
||||
json.partial! "api/v1/projects/simple_gitea_file", file: file
|
||||
end
|
||||
end
|
||||
json.status @merge_status
|
||||
json.message @merge_message
|
|
@ -0,0 +1,10 @@
|
|||
if params[:filepath].present?
|
||||
json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object
|
||||
else
|
||||
json.file_nums @result_object[:total_data].to_i
|
||||
json.total_addition @result_object[:data]["total_addition"]
|
||||
json.total_deletion @result_object[:data]["total_deletion"]
|
||||
json.files @result_object[:data]["files"] do |file|
|
||||
json.partial! "api/v1/projects/simple_gitea_file", file: file
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
json.commits_count @compare_result['CommitsCount']
|
||||
json.files_count @compare_result['FilesCount']
|
||||
# json.commits @compare_result['Commits'], partial: 'pull_requests/commit', as: :commit
|
||||
json.commits do
|
||||
if @compare_result['Commits'].present?
|
||||
|
|
|
@ -3,10 +3,10 @@ if @commit.blank? #如果有状态值,则表示报错了
|
|||
json.total_count 0
|
||||
json.commits []
|
||||
else
|
||||
json.files_count @commit_diff['NumFiles']
|
||||
json.total_addition @commit_diff['TotalAddition']
|
||||
json.total_deletion @commit_diff['TotalDeletion']
|
||||
json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file, locals: {sha: @sha}
|
||||
# json.files_count @commit_diff['NumFiles']
|
||||
# json.total_addition @commit_diff['TotalAddition']
|
||||
# json.total_deletion @commit_diff['TotalDeletion']
|
||||
# json.files @commit_diff['Files'], partial: 'pull_requests/diff_file', as: :file, locals: {sha: @sha}
|
||||
|
||||
json.partial! 'commit', commit: @commit, project: @project
|
||||
json.parents @commit['parents'] do |parent|
|
||||
|
|
|
@ -167,6 +167,9 @@ defaults format: :json do
|
|||
post :save_yaml, on: :collection
|
||||
end
|
||||
resources :pulls, module: 'pulls' do
|
||||
member do
|
||||
get :files
|
||||
end
|
||||
resources :versions, only: [:index] do
|
||||
member do
|
||||
get :diff
|
||||
|
@ -197,6 +200,7 @@ defaults format: :json do
|
|||
resources :tags, param: :name, only: [:index, :show, :destroy]
|
||||
delete 'tags/*name', to: "tags#destroy", via: :all
|
||||
get 'tags/*name', to: "tags#show", via: :all
|
||||
get '/compare/:base...:head/files' => 'compare#files', :constraints => { base: /.+/, head: /.+/ }
|
||||
|
||||
resources :commits, only: [:index] do
|
||||
collection do
|
||||
|
@ -210,6 +214,7 @@ defaults format: :json do
|
|||
end
|
||||
end
|
||||
get '/commits/:sha/diff', to: 'commits#diff'
|
||||
get '/commits/:sha/files', to: 'commits#files'
|
||||
get '/git/blobs/:sha', to: 'git#blobs'
|
||||
get '/git/trees/:sha', to: 'git#trees'
|
||||
|
||||
|
|
Loading…
Reference in New Issue