add version_releases attachments
This commit is contained in:
parent
ef1023d0f5
commit
f197f41839
|
@ -56,6 +56,8 @@ class HooksController < ApplicationController
|
||||||
|
|
||||||
hook_params = params[:hook_params]
|
hook_params = params[:hook_params]
|
||||||
Gitea::Hooks::CreateService.new(@user, @repository.try(:identifier), hook_params).call #创建gitea的hook功能
|
Gitea::Hooks::CreateService.new(@user, @repository.try(:identifier), hook_params).call #创建gitea的hook功能
|
||||||
|
Gitea::Hooks::CreateService.new(user, p.try(:identifier), hook_params).call #创建gitea的hook功能
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
@ -8,7 +8,7 @@ class VersionReleasesController < ApplicationController
|
||||||
version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call
|
version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call
|
||||||
@version_releases = version_releases
|
@version_releases = version_releases
|
||||||
@user_permission = current_user.present? && (current_user == @user || current_user.admin?)
|
@user_permission = current_user.present? && (current_user == @user || current_user.admin?)
|
||||||
|
@forge_releases = @repository.version_releases.select(:id,:version_gid).includes(:attachments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
@ -34,14 +34,7 @@ class VersionReleasesController < ApplicationController
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
version_params = {
|
version_params = releases_params
|
||||||
body: params[:body],
|
|
||||||
draft: params[:draft] || false,
|
|
||||||
name: params[:name].to_s.first(32),
|
|
||||||
prerelease: params[:prerelease] || false,
|
|
||||||
tag_name: params[:tag_name],
|
|
||||||
target_commitish: params[:target_commitish] || "master" #分支
|
|
||||||
}
|
|
||||||
version_release = VersionRelease.new(version_params.merge(user_id: current_user.id, repository_id: @repository.id))
|
version_release = VersionRelease.new(version_params.merge(user_id: current_user.id, repository_id: @repository.id))
|
||||||
if version_release.save!
|
if version_release.save!
|
||||||
git_version_release = Gitea::Versions::CreateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params).call
|
git_version_release = Gitea::Versions::CreateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params).call
|
||||||
|
@ -54,6 +47,9 @@ class VersionReleasesController < ApplicationController
|
||||||
}
|
}
|
||||||
version_release.update_attributes!(update_params)
|
version_release.update_attributes!(update_params)
|
||||||
version_release.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
version_release.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
|
if params[:attachment_ids].present?
|
||||||
|
create_attachments(params[:attachment_ids], version_release)
|
||||||
|
end
|
||||||
normal_status(0, "发布成功")
|
normal_status(0, "发布成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "发布失败")
|
normal_status(-1, "发布失败")
|
||||||
|
@ -70,7 +66,7 @@ class VersionReleasesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@version_attachments = @version.attachments
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@ -81,19 +77,15 @@ class VersionReleasesController < ApplicationController
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
version_params = {
|
version_params = releases_params
|
||||||
body: params[:body],
|
|
||||||
draft: params[:draft] || false,
|
|
||||||
name: params[:name],
|
|
||||||
prerelease: params[:prerelease],
|
|
||||||
tag_name: params[:tag_name],
|
|
||||||
target_commitish: params[:target_commitish] || "master" #分支
|
|
||||||
}
|
|
||||||
if @version.update_attributes!(version_params)
|
if @version.update_attributes!(version_params)
|
||||||
|
create_attachments(params[:attachment_ids], @version) if params[:attachment_ids].present?
|
||||||
git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call
|
git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call
|
||||||
unless git_version_release
|
unless git_version_release
|
||||||
raise Error, "更新失败"
|
raise Error, "更新失败"
|
||||||
end
|
end
|
||||||
|
|
||||||
normal_status(0, "更新成功")
|
normal_status(0, "更新成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "更新失败")
|
normal_status(-1, "更新失败")
|
||||||
|
@ -148,4 +140,27 @@ class VersionReleasesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def releases_params
|
||||||
|
{
|
||||||
|
body: params[:body],
|
||||||
|
draft: params[:draft] || false,
|
||||||
|
name: params[:name],
|
||||||
|
prerelease: params[:prerelease],
|
||||||
|
tag_name: params[:tag_name],
|
||||||
|
target_commitish: params[:target_commitish] || "master" #分支
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_attachments(attachment_ids, target)
|
||||||
|
attachment_ids.each do |id|
|
||||||
|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||||
|
unless attachment.blank?
|
||||||
|
attachment.container = target
|
||||||
|
attachment.author_id = current_user.id
|
||||||
|
attachment.description = ""
|
||||||
|
attachment.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,5 +3,5 @@ class VersionRelease < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
has_many :project_trends, as: :trend, dependent: :destroy
|
has_many :project_trends, as: :trend, dependent: :destroy
|
||||||
scope :releases_size, ->{where(draft: false, prerelease: false).size}
|
scope :releases_size, ->{where(draft: false, prerelease: false).size}
|
||||||
# has_many :attachments, as: :container, dependent: :destroy
|
has_many :attachments, as: :container, dependent: :destroy
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,7 @@ json.issue_status @issue.issue_status.try(:name)
|
||||||
json.priority @issue.priority.try(:name)
|
json.priority @issue.priority.try(:name)
|
||||||
json.version @issue.version.try(:name)
|
json.version @issue.version.try(:name)
|
||||||
json.issue_tags @issue.get_issue_tags
|
json.issue_tags @issue.get_issue_tags
|
||||||
json.done_ratio @issue.done_ratio.to_s + "%"
|
json.done_ratio @issue.done_ratio.to_s + "%"
|
||||||
json.issue_type @issue.issue_type == "1" ? "普通" : "悬赏"
|
json.issue_type @issue.issue_type == "1" ? "普通" : "悬赏"
|
||||||
json.token @issue.issue_type == "2" ? @issue.token : ""
|
json.token @issue.issue_type == "2" ? @issue.token : ""
|
||||||
json.join_users @join_users
|
json.join_users @join_users
|
||||||
|
|
|
@ -1 +1,7 @@
|
||||||
json.extract! @version, :id, :name, :body, :tag_name, :target_commitish, :draft, :prerelease,:version_gid
|
json.extract! @version, :id, :name, :body, :tag_name, :target_commitish, :draft, :prerelease,:version_gid
|
||||||
|
|
||||||
|
json.attachments do
|
||||||
|
json.array! @version_attachments do |attachment|
|
||||||
|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,7 +4,7 @@ json.user_permission @user_permission
|
||||||
json.releases do
|
json.releases do
|
||||||
json.array! @version_releases.to_a.each do |re|
|
json.array! @version_releases.to_a.each do |re|
|
||||||
user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(re["author"]["id"])
|
user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(re["author"]["id"])
|
||||||
version = VersionRelease.select(:id).find_by_version_gid(re["id"])
|
version = @forge_releases.find_by(version_gid: re["id"])
|
||||||
if @user_permission && re["draft"]
|
if @user_permission && re["draft"]
|
||||||
json.version_id version.try(:id)
|
json.version_id version.try(:id)
|
||||||
json.id re["id"]
|
json.id re["id"]
|
||||||
|
@ -38,6 +38,10 @@ json.releases do
|
||||||
json.image_url user.present? ? url_to_avatar(user) : ""
|
json.image_url user.present? ? url_to_avatar(user) : ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
json.attachments do
|
||||||
|
json.array! version.attachments do |attachment|
|
||||||
|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue