mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-16 09:45:57 +08:00
fix merge develop branch
This commit is contained in:
@@ -6,26 +6,48 @@ class CompareController < ApplicationController
|
||||
end
|
||||
|
||||
def show
|
||||
load_compare_params
|
||||
compare
|
||||
@merge_status, @merge_message = get_merge_message
|
||||
end
|
||||
|
||||
private
|
||||
def get_merge_message
|
||||
if @base.blank? || @head.blank?
|
||||
return -2, "请选择分支"
|
||||
else
|
||||
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='/projects/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}/Messagecount'>#{@exist_pullrequest.try(:title)}</a>"
|
||||
else
|
||||
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||
return -2, "分支内容相同,无需创建合并请求"
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0, "可以合并"
|
||||
end
|
||||
|
||||
def compare
|
||||
base, head = compare_params
|
||||
|
||||
# TODO: 处理fork的项目向源项目发送PR的base、head参数问题
|
||||
@compare_result ||=
|
||||
head.include?(":") ? gitea_compare(base, head) : gitea_compare(head, base)
|
||||
@head.include?(":") ? gitea_compare(@base, @head) : gitea_compare(@head, @base)
|
||||
end
|
||||
|
||||
def compare_params
|
||||
base = Addressable::URI.unescape(params[:base])
|
||||
head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
||||
def load_compare_params
|
||||
@base = Addressable::URI.unescape(params[:base])
|
||||
@head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
||||
|
||||
[base, head]
|
||||
end
|
||||
|
||||
def gitea_compare(base, head)
|
||||
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, base, head)
|
||||
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, base, head, current_user.gitea_token)
|
||||
end
|
||||
end
|
||||
|
||||
63
app/controllers/public_keys_controller.rb
Normal file
63
app/controllers/public_keys_controller.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
class PublicKeysController < ApplicationController
|
||||
before_action :require_login
|
||||
before_action :find_public_key, only: [:destroy]
|
||||
|
||||
def index
|
||||
@public_keys = current_user.public_keys
|
||||
@public_keys = kaminari_paginate(@public_keys)
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def create
|
||||
return render_error("参数错误") if public_key_params.blank?
|
||||
return render_ok({status: 10002, message: "请输入密钥"}) if public_key_params[:key].blank?
|
||||
return render_ok({status: 10001, message: "请输入标题"}) if public_key_params[:title].blank?
|
||||
@gitea_response = Gitea::User::Keys::CreateService.call(current_user.gitea_token, public_key_params)
|
||||
if @gitea_response[0] == 201
|
||||
@public_key = @gitea_response[2]
|
||||
else
|
||||
return render_error("创建ssh key失败") if @gitea_response[2]["message"].nil?
|
||||
return render_ok({status: 10002, message: "密钥格式不正确"}) if @gitea_response[2]["message"].starts_with?("Invalid key content")
|
||||
exist_public_key = Gitea::PublicKey.find_by(content: public_key_params[:key])
|
||||
return render_ok({status: 10002, message: "密钥已存在,请勿重复添加"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.owner_id == current_user.gitea_uid
|
||||
return render_ok({status: 10002, message: "密钥已被占用"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.present?
|
||||
@public_key = nil
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def destroy
|
||||
return render_not_found unless @public_key.present?
|
||||
if @public_key.destroy
|
||||
render_ok
|
||||
else
|
||||
render_error
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def page
|
||||
params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
end
|
||||
|
||||
def limit
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
||||
end
|
||||
|
||||
def public_key_params
|
||||
params.require(:public_key).permit(:key, :title)
|
||||
end
|
||||
|
||||
def find_public_key
|
||||
@public_key = current_user.public_keys.find_by_id(params[:id])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user