Merge branch 'standalone_develop' into pm_project_develop

# Conflicts:
#	app/controllers/attachments_controller.rb
#	app/services/api/v1/issues/concerns/checkable.rb
#	app/services/api/v1/issues/concerns/loadable.rb
This commit is contained in:
2023-12-15 10:43:54 +08:00
26 changed files with 130 additions and 40 deletions

View File

@@ -12,7 +12,7 @@ module Api::V1::Issues::Concerns::Checkable
raise ApplicationService::Error, "Milestone不存在" unless Version.find_by_id(milestone_id).present?
end
def check_root_issue(issue, root_id)
def check_root_issue(issue, root_id)
raise ApplicationService::Error, "父工作项与当前工作项已存在父子关系!" if Issue.full_children_issues(issue).map{|i| i.id}.include?(root_id)
end
@@ -35,8 +35,8 @@ module Api::V1::Issues::Concerns::Checkable
def check_attachments (attachment_ids)
raise ApplicationService::Error, "请输入正确的附件ID数组" unless attachment_ids.is_a?(Array)
attachment_ids.each do |aid|
raise ApplicationService::Error, "请输入正确的附件ID" unless Attachment.exists?(id: aid) || Attachment.exists?(uuid: aid)
end
raise ApplicationService::Error, "请输入正确的附件ID" unless Attachment.where_id_or_uuid(aid).exists?
end
end
def check_atme_receivers(receivers_login)

View File

@@ -9,7 +9,7 @@ module Api::V1::Issues::Concerns::Loadable
end
def load_attachments(attachment_ids)
@attachments = Attachment.where(id: attachment_ids).or(Attachment.where(uuid: attachment_ids))
@attachments = Attachment.where("id in (?) or uuid in (?)", attachment_ids, attachment_ids)
end
def load_atme_receivers(receivers_login)

View File

@@ -144,7 +144,7 @@ class Api::V1::Issues::ListService < ApplicationService
else
scope = issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals)
scope = if sort_by == 'issue_priorities.position'
scope.reorder("issue_priorities.position #{sort_direction}, issues.created_on DESC").distinct
scope.reorder("issue_priorities.position #{sort_direction}, issues.updated_on DESC").distinct
else
scope.reorder("#{sort_by} #{sort_direction}").distinct
end

View File

@@ -0,0 +1,48 @@
class Api::V1::Projects::Tags::GetService < ApplicationService
include ActiveModel::Model
attr_reader :project, :token, :owner, :repo, :tag_name
attr_accessor :gitea_data
validates :tag_name, presence: true
def initialize(project, tag_name, token=nil)
@project = project
@owner = project&.owner&.login
@repo = project&.identifier
@tag_name = tag_name.to_s
@token = token
end
def call
raise Error, errors.full_messages.join(",") unless valid?
check_tag_exist
load_gitea_data
gitea_data
end
private
def request_params
params = {
access_token: token
}
params
end
def load_gitea_data
@gitea_data = $gitea_hat_client.get_repos_tags_by_owner_repo_tag(owner, repo, URI.escape(tag_name), {query: request_params}) rescue nil
raise Error, '获取标签失败!' unless @gitea_data.is_a?(Hash)
end
def check_tag_exist
result = $gitea_hat_client.get_repos_tag_name_set_by_owner_repo(owner, repo, {query: request_params}) rescue nil
raise Error, '查询标签名称失败!' unless result.is_a?(Array)
raise Error, '标签不存在!' if !result.include?(@tag_name)
end
end

View File

@@ -59,7 +59,11 @@ class Gitea::Repository::Entries::CreateService < Gitea::ClientService
if @body[:new_branch].present? && (@body[:new_branch].include?('/') || @body[:new_branch].include?('\'') || @body[:new_branch].include?('^') || @body[:new_branch].include?('*'))
error("不合法的分支名称!")
else
error("#{filepath}文件已存在,不能重复创建!")
if json_parse!(body)["message"].present? && json_parse!(body)["message"].starts_with?("branch already exists")
error("#{@body[:new_branch]}分支已存在!")
else
error("#{filepath}文件已存在,不能重复创建!")
end
end
else
Rails.logger.error("Gitea api url==#{url},status:#{status},body=#{body}")