version release

dev_forge
SylorHuang 5 years ago
parent 26e2093f77
commit fd0398e3ca

@ -13,6 +13,18 @@ class VersionReleasesController < ApplicationController
@version_releases = version_releases.order("created_at desc").page(page).limit(@limit) @version_releases = version_releases.order("created_at desc").page(page).limit(@limit)
end end
def new
#获取所有的分支
@all_branches = []
get_all_branches = Gitea::Repository::BranchesService.new(@user, @repository.try(:identifier)).call
if get_all_branches && get_all_branches.size > 0
get_all_branches.each do |b|
@all_branches.push(b["name"])
end
end
end
def create def create
if params[:name].nil? if params[:name].nil?
normal_status(-1, "名称不能为空") normal_status(-1, "名称不能为空")
@ -20,31 +32,38 @@ class VersionReleasesController < ApplicationController
normal_status(-1, "标签名称不能为空") normal_status(-1, "标签名称不能为空")
else else
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
version_params = { begin
body: params[:body], version_params = {
draft: params[:draft] || false, body: params[:body],
name: params[:name], draft: params[:draft] || false,
prerelease: params[:prerelease], name: params[:name],
tag_name: params[:tag_name], prerelease: params[:prerelease],
target_commitish: params[:target_commitish] || "master" #分支 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)) }
if version_release.save! version_release = VersionRelease.new(version_params.merge(user_id: current_user.id, repository_id: @repository.id))
git_version_release = Gitea::Versions::CreateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params).call if version_release.save!
git_version_release = Gitea::Versions::CreateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params).call
if git_version_release if git_version_release
update_params = { update_params = {
tarball_url: git_version_release["tarball_url"], tarball_url: git_version_release["tarball_url"],
zipball_url: git_version_release["zipball_url"], zipball_url: git_version_release["zipball_url"],
url: git_version_release["url"], url: git_version_release["url"],
version_gid: git_version_release["id"], version_gid: git_version_release["id"],
} }
version_release.update_attributes!(update_params) version_release.update_attributes!(update_params)
normal_status(0, "发布成功")
else
normal_status(-1, "发布失败")
end
else
normal_status(-1, "发布失败")
end end
rescue => e
puts "create version release error: #{e.message}"
raise Error, e.message
end end
rescue => e
puts "create version release error: #{e.message}"
raise Error, e.message
end end
end end
end end
@ -60,52 +79,54 @@ class VersionReleasesController < ApplicationController
normal_status(-1, "标签名称不能为空") normal_status(-1, "标签名称不能为空")
else else
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
version_params = { begin
body: params[:body], version_params = {
draft: params[:draft] || false, body: params[:body],
name: params[:name], draft: params[:draft] || false,
prerelease: params[:prerelease], name: params[:name],
tag_name: params[:tag_name], prerelease: params[:prerelease],
target_commitish: params[:target_commitish] || "master" #分支 tag_name: params[:tag_name],
} target_commitish: params[:target_commitish] || "master" #分支
if @version.update_attributes!(version_params) }
git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call if @version.update_attributes!(version_params)
unless git_version_release git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call
raise Error, "更新失败" unless git_version_release
raise Error, "更新失败"
end
normal_status(0, "更新成功")
else
normal_status(-1, "更新失败")
end end
rescue => e
puts "update version release error: #{e.message}"
raise Error, e.message
end end
rescue => e
puts "update version release error: #{e.message}"
raise Error, e.message
end end
end end
end end
def destroy def destroy
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
if @version.destroy begin
git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call if @version.destroy
unless git_version_release git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @repository.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call
raise Error, "删除失败" unless git_version_release
raise Error, "删除失败"
end
normal_status(0, "删除成功")
else
normal_status(-1, "删除失败")
end end
rescue => e
puts "destroy version release error: #{e.message}"
raise Error, e.message
end end
rescue => e
puts "destroy version release error: #{e.message}"
raise Error, e.message
end end
end end
private private
# def set_project
# @project = Project.find_by_id(params[:project_id])
# @repository = @project.repository #项目的仓库
# unless @project.present? && @repository.present?
# normal_status(-1, "仓库不存在")
# end
# end
def set_user_and_project def set_user_and_project
@project = Project.find_by_id(params[:project_id]) @project = Project.find_by_id(params[:project_id])
@repository = @project.repository #项目的仓库 @repository = @project.repository #项目的仓库

@ -0,0 +1,2 @@
json.partial! "commons/success"
json.branches @all_branches

@ -46,7 +46,7 @@ Rails.application.routes.draw do
resources :licenses, only: [:index, :show] resources :licenses, only: [:index, :show]
resources :projects, only: [:index, :create, :show] do resources :projects, only: [:index, :create, :show] do
resources :version_releases, only: [:index, :create, :edit, :update, :destroy] resources :version_releases, only: [:index,:new, :create, :edit, :update, :destroy]
resources :project_trends, only: [:index, :create] resources :project_trends, only: [:index, :create]
resources :issues do resources :issues do
collection do collection do

Loading…
Cancel
Save