add: release use database data

This commit is contained in:
yystopf 2021-09-30 11:09:13 +08:00
parent b07781a514
commit aabfaad458
6 changed files with 33 additions and 27 deletions

View File

@ -5,11 +5,9 @@ class VersionReleasesController < ApplicationController
before_action :find_version , only: [:show, :edit, :update, :destroy]
def index
version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call
@version_releases = version_releases
@version_releases = kaminari_paginate(@repository.version_releases.order(created_at: :desc))
@user_permission = current_user.present? && (@repository.project.all_developers.include?(current_user) || current_user.admin?)
@user_admin_permission = current_user.present? && (@repository.project.all_managers.include?(current_user) || current_user.admin?)
@forge_releases = @repository.version_releases.select(:id,:version_gid, :created_at).includes(:attachments)
end
def new
@ -24,7 +22,7 @@ class VersionReleasesController < ApplicationController
end
def show
@release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid)
# @release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid)
end
def create
@ -49,6 +47,7 @@ class VersionReleasesController < ApplicationController
zipball_url: git_version_release["zipball_url"],
url: git_version_release["url"],
version_gid: git_version_release["id"],
sha: git_version_release["sha"]
}
version_release.update_attributes!(update_params)
version_release.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")

View File

@ -17,6 +17,7 @@
# created_at :datetime not null
# updated_at :datetime not null
# repository_id :integer
# sha :string(255)
#
# Indexes
#
@ -29,4 +30,9 @@ class VersionRelease < ApplicationRecord
has_many :project_trends, as: :trend, dependent: :destroy
scope :releases_size, ->{where(draft: false, prerelease: false).size}
has_many :attachments, as: :container, dependent: :destroy
def update_sha
git_release = Gitea::Versions::GetService.call(user.gitea_token, repository&.owner&.login, repository&.identifier, version_gid)
self.update(sha: git_release["sha"])
end
end

View File

@ -1,14 +1,14 @@
json.version_id version.try(:id)
json.id re["id"]
json.tag_name re["tag_name"]
json.target_commitish re["target_commitish"]
json.name re["name"]
json.sha re["sha"]
json.body re["body"]
json.url re["url"]
json.tarball_url render_tar_url(@owner, @repository, re["tag_name"])
json.zipball_url render_zip_url(@owner, @repository, re["tag_name"])
json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定")
json.id version&.version_gid
json.tag_name version&.tag_name
json.target_commitish version&.target_commitish
json.name version&.name
json.sha version&.sha
json.body version&.body
json.url version&.url
json.tarball_url render_tar_url(@owner, @repository, version&.tag_name)
json.zipball_url render_zip_url(@owner, @repository, version&.tag_name)
json.draft version&.draft ? "草稿" : (version&.prerelease ? "预发行" : "稳定")
json.created_at format_time(version.created_at.to_s.to_time)
json.published_at format_time(version.created_at.to_s.to_time)
json.user_name user.present? ? user.try(:show_real_name) : ""

View File

@ -3,18 +3,14 @@ json.user_permission @user_permission
json.user_admin_permission @user_admin_permission
# json.releases @version_releases
json.releases do
json.array! @version_releases.to_a.each do |re|
if re.present?
user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(re["author"]["id"])
version = @forge_releases.find_by(version_gid: re["id"])
if @user_permission && re["draft"]
json.partial! "version_release", locals: {version: version, user: user, re: re}
else
unless re["draft"]
json.partial! "version_release", locals: {version: version, user: user, re: re}
end
json.array! @version_releases.each do |version|
version.update_sha if version.sha.nil?
if @user_permission && version&.draft
json.partial! "version_release", locals: {version: version, user: version&.user}
else
unless version&.draft
json.partial! "version_release", locals: {version: version, user: version&.user}
end
end
end
end

View File

@ -1,2 +1,2 @@
user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(@release["author"]["id"])
json.partial! "version_release", locals: {version: @version, user: user, re: @release}
json.partial! "version_release", locals: {version: @version, user: @version&.user}

View File

@ -0,0 +1,5 @@
class AddShaToVersionReleases < ActiveRecord::Migration[5.2]
def change
add_column :version_releases, :sha, :string
end
end