Merge branch 'dev_trustie' of http://gitea.trustie.net/jasder/forgeplus into dev_trustie
This commit is contained in:
commit
19bb95b1a4
|
@ -1,6 +1,7 @@
|
||||||
class HooksController < ApplicationController
|
class HooksController < ApplicationController
|
||||||
before_action :require_login, except: [:index, :show]
|
before_action :require_login
|
||||||
before_action :find_project_with_id
|
before_action :find_project_with_id
|
||||||
|
before_action :check_user
|
||||||
before_action :set_repository
|
before_action :set_repository
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -15,6 +16,7 @@ class HooksController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
#根据gitea的api
|
||||||
# hook_params = {
|
# hook_params = {
|
||||||
# active: true,
|
# active: true,
|
||||||
# type: "gitea",
|
# type: "gitea",
|
||||||
|
@ -26,6 +28,7 @@ class HooksController < ApplicationController
|
||||||
# },
|
# },
|
||||||
# events: ["create", "pull", "push"],
|
# events: ["create", "pull", "push"],
|
||||||
# }
|
# }
|
||||||
|
#根据gitea上hook的字段测试的
|
||||||
# hook_params = {
|
# hook_params = {
|
||||||
# is_active: params[:is_active] || false,
|
# is_active: params[:is_active] || false,
|
||||||
# type: params[:type],
|
# type: params[:type],
|
||||||
|
@ -53,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
|
||||||
|
@ -82,4 +87,10 @@ class HooksController < ApplicationController
|
||||||
normal_status(-1, "仓库不存在") unless @repository.present?
|
normal_status(-1, "仓库不存在") unless @repository.present?
|
||||||
normal_status(-1, "用户不存在") unless @user.present?
|
normal_status(-1, "用户不存在") unless @user.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_user
|
||||||
|
unless @project.user_id == current_user.id
|
||||||
|
tip_exception(403, "您没有权限进入")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,7 @@ class RepositoriesController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
|
@branches_count = Gitea::Repository::BranchesService.new(@project.owner, @project.identifier).call&.size
|
||||||
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner, @project.identifier).call[:total_count]
|
@commits_count = Gitea::Repository::Commits::ListService.new(@project.owner, @project.identifier).call[:total_count]
|
||||||
|
@tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size
|
||||||
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
@result = Gitea::Repository::GetService.new(@project.owner, @project.identifier).call
|
||||||
@project_fork_id = @project.try(:forked_from_project_id)
|
@project_fork_id = @project.try(:forked_from_project_id)
|
||||||
if @project_fork_id.present?
|
if @project_fork_id.present?
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Issues::ListQueryService < ApplicationService
|
||||||
issues = issues.joins(:issue_tags).where(issue_tags: {id: params[:issue_tag_id].to_i}) if params[:issue_tag_id].present? && params[:issue_tag_id].to_s != "all"
|
issues = issues.joins(:issue_tags).where(issue_tags: {id: params[:issue_tag_id].to_i}) if params[:issue_tag_id].present? && params[:issue_tag_id].to_s != "all"
|
||||||
|
|
||||||
order_type = params[:order_type] || "desc" #或者"asc"
|
order_type = params[:order_type] || "desc" #或者"asc"
|
||||||
order_name = params[:order_name] || "created_on" #或者"updated_on"
|
order_name = params[:order_name] || "updated_on" #或者"updated_on"
|
||||||
issues.reorder("issues.#{order_name} #{order_type}")
|
issues.reorder("issues.#{order_name} #{order_type}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ json.versions_count @project.versions_count #里程碑数量
|
||||||
json.version_releases_count @project.releases_size(current_user.try(:id), "all")
|
json.version_releases_count @project.releases_size(current_user.try(:id), "all")
|
||||||
json.version_releasesed_count @project.releases_size(current_user.try(:id), "released") #已发行的版本
|
json.version_releasesed_count @project.releases_size(current_user.try(:id), "released") #已发行的版本
|
||||||
json.contributor_users_count @project.contributor_users
|
json.contributor_users_count @project.contributor_users
|
||||||
json.issue_tags_count @project.issue_tags_count
|
json.issue_tags_count @tags_count
|
||||||
json.branches_count @branches_count
|
json.branches_count @branches_count
|
||||||
json.commits_count @commits_count
|
json.commits_count @commits_count
|
||||||
json.permission render_edit_project_permission(current_user, @project) if current_user
|
json.permission render_edit_project_permission(current_user, @project) if current_user
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
json.array! @tags do |tag|
|
json.array! @tags do |tag|
|
||||||
|
if tag.present?
|
||||||
json.name tag['name']
|
json.name tag['name']
|
||||||
json.id tag['id']
|
json.id tag['id']
|
||||||
json.zipball_url tag['zipball_url']
|
json.zipball_url tag['zipball_url']
|
||||||
|
@ -7,3 +8,5 @@ json.array! @tags do |tag|
|
||||||
json.sha tag['commit']['sha']
|
json.sha tag['commit']['sha']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
@ -3,8 +3,9 @@ json.user_permission @user_permission
|
||||||
# json.releases @version_releases
|
# json.releases @version_releases
|
||||||
json.releases do
|
json.releases do
|
||||||
json.array! @version_releases.to_a.each do |re|
|
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"])
|
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"]
|
||||||
|
@ -39,5 +40,12 @@ json.releases do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
json.attachments do
|
||||||
|
json.array! version.try(:attachments) do |attachment|
|
||||||
|
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class ChangeRepositoryReleasesCount < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
release_ids = VersionRelease.select(:id,:repository_id).pluck(:repository_id).uniq
|
||||||
|
release_ids.each do |i|
|
||||||
|
puts "#######____update_repository_releases_id____##############{i}"
|
||||||
|
p = Repository.includes(:version_releases).select(:id, :version_releases_count).find_by(id:i)
|
||||||
|
if p.present?
|
||||||
|
Repository.reset_counters(i, :version_releases)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue