Merge branch 'pre_trustie_server' into trustie_server
This commit is contained in:
commit
18377dc2e0
|
@ -18,6 +18,15 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||||
def destroy
|
def destroy
|
||||||
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:name], current_user&.gitea_token)
|
||||||
if @result_object
|
if @result_object
|
||||||
|
# 有开启的pr需要一同关闭
|
||||||
|
# 1、删除本仓库中存在未关闭的pr,即本仓库分支1->分支2
|
||||||
|
# 2、如果是fork仓库,考虑删除主仓库中存在未关闭的pr,即本仓库:分支1->主:分支2,同时分两种删除:1删除本仓库分支1,2删除主仓库分支2
|
||||||
|
close_pull_requests_by(@project, params[:name])
|
||||||
|
if @project.forked_from_project_id.present?
|
||||||
|
# fork项目中删除分支
|
||||||
|
close_pull_requests_by(@project.fork_project, params[:name])
|
||||||
|
end
|
||||||
|
|
||||||
return render_ok
|
return render_ok
|
||||||
else
|
else
|
||||||
return render_error('删除分支失败!')
|
return render_error('删除分支失败!')
|
||||||
|
@ -39,4 +48,19 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||||
def branch_params
|
def branch_params
|
||||||
params.require(:branch).permit(:new_branch_name, :old_branch_name)
|
params.require(:branch).permit(:new_branch_name, :old_branch_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def close_pull_requests_by(project, branch_name)
|
||||||
|
open_pull_requests = project.pull_requests.opening.where(head: branch_name).or(project.pull_requests.opening.where(base: branch_name))
|
||||||
|
if open_pull_requests.present?
|
||||||
|
open_pull_requests.each do |pull_request|
|
||||||
|
closed = PullRequests::CloseService.call(project.owner, project.repository, pull_request, current_user)
|
||||||
|
if closed === true
|
||||||
|
pull_request.project_trends.create!(user: current_user, project: project,action_type: ProjectTrend::CLOSE)
|
||||||
|
# 合并请求下issue处理为关闭
|
||||||
|
pull_request.issue&.update_attributes!({status_id:5})
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -81,7 +81,7 @@ class ApplicationController < ActionController::Base
|
||||||
# 判断用户的邮箱或者手机是否可用
|
# 判断用户的邮箱或者手机是否可用
|
||||||
# params[:type] 1: 注册;2:忘记密码;3:绑定
|
# params[:type] 1: 注册;2:忘记密码;3:绑定
|
||||||
def check_mail_and_phone_valid login, type
|
def check_mail_and_phone_valid login, type
|
||||||
unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/
|
unless login =~ /\A[a-zA-Z0-9]+([._\-\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ || login =~ /^1\d{10}$/
|
||||||
tip_exception(-2, "请输入正确的手机号或邮箱")
|
tip_exception(-2, "请输入正确的手机号或邮箱")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,9 @@ module Gitea
|
||||||
def render_result(response)
|
def render_result(response)
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
@result = JSON.parse(response.body)
|
@result = JSON.parse(response.body)
|
||||||
|
else
|
||||||
|
Rails.logger.error("Gitea::Repository::Entries::DeleteService error[#{response.status}]======#{response.body}")
|
||||||
|
@error = "删除失败,请确认该分支是否是保护分支。"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ module Gitea
|
||||||
if response.status == 200
|
if response.status == 200
|
||||||
@result = JSON.parse(response.body)
|
@result = JSON.parse(response.body)
|
||||||
else
|
else
|
||||||
Rails.logger.info("Gitea::Repository::Entries::UpdateService error======#{response.body}")
|
Rails.logger.error("Gitea::Repository::Entries::UpdateService error[#{response.status}]======#{response.body}")
|
||||||
@error = "更新失败"
|
@error = "更新失败,请确认该分支是否是保护分支。"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||||
def status_payload(status, body)
|
def status_payload(status, body)
|
||||||
case status
|
case status
|
||||||
when 201 then success(json_parse!(body))
|
when 201 then success(json_parse!(body))
|
||||||
when 403 then error("你没有权限操作!")
|
when 403 then error("你没有权限操作,请确认该分支是否是保护分支。")
|
||||||
when 404 then error("你操作的链接不存在!")
|
when 404 then error("你操作的链接不存在!")
|
||||||
when 422
|
when 422
|
||||||
if @body[:new_branch].present? && (@body[:new_branch].include?('/') || @body[:new_branch].include?('\'') || @body[:new_branch].include?('^') || @body[:new_branch].include?('*'))
|
if @body[:new_branch].present? && (@body[:new_branch].include?('/') || @body[:new_branch].include?('\'') || @body[:new_branch].include?('^') || @body[:new_branch].include?('*'))
|
||||||
|
@ -61,7 +61,9 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
|
||||||
else
|
else
|
||||||
error("#{filepath}文件已存在,不能重复创建!")
|
error("#{filepath}文件已存在,不能重复创建!")
|
||||||
end
|
end
|
||||||
else error("系统错误!")
|
else
|
||||||
|
Rails.logger.error("Gitea api url==#{url},status:#{status},body=#{body}")
|
||||||
|
error("系统错误!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue