parent
c94bffd844
commit
d8eeb8f1b7
|
@ -9,7 +9,7 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||||
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
before_action :require_operate_above, only: [:create, :destroy]
|
before_action :require_operate_above, only: [:create, :destroy, :restore]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
|
||||||
|
@ -33,6 +33,15 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def restore
|
||||||
|
@result_object = Api::V1::Projects::Branches::RestoreService.call(@project, params[:branch_id], params[:branch_name], current_user&.gitea_token)
|
||||||
|
if @result_object
|
||||||
|
return render_ok
|
||||||
|
else
|
||||||
|
return render_error('恢复分支失败!')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
before_action :require_manager_above, only: [:update_default_branch]
|
before_action :require_manager_above, only: [:update_default_branch]
|
||||||
|
|
||||||
def update_default_branch
|
def update_default_branch
|
||||||
|
|
|
@ -18,7 +18,6 @@ class Api::V1::Projects::Branches::ListService < ApplicationService
|
||||||
load_default_branch
|
load_default_branch
|
||||||
|
|
||||||
@gitea_data[:default_branch] = @gitea_repo_data["default_branch"]
|
@gitea_data[:default_branch] = @gitea_repo_data["default_branch"]
|
||||||
|
|
||||||
@gitea_data
|
@gitea_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
class Api::V1::Projects::Branches::RestoreService < ApplicationService
|
||||||
|
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :project, :token, :owner, :repo, :branch_id, :branch_name
|
||||||
|
attr_accessor :gitea_data
|
||||||
|
|
||||||
|
validates :branch_id, :branch_name, presence: true
|
||||||
|
|
||||||
|
def initialize(project, branch_id, branch_name, token= nil)
|
||||||
|
@project = project
|
||||||
|
@owner = project&.owner&.login
|
||||||
|
@repo = project&.identifier
|
||||||
|
@branch_id = branch_id
|
||||||
|
@branch_name = branch_name
|
||||||
|
@token = token
|
||||||
|
end
|
||||||
|
|
||||||
|
def call
|
||||||
|
raise Error, errors.full_messages.join(",") unless valid?
|
||||||
|
excute_data_to_gitea
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def request_params
|
||||||
|
{
|
||||||
|
access_token: token
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def request_body
|
||||||
|
{
|
||||||
|
branch_id: branch_id,
|
||||||
|
name: branch_name,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def excute_data_to_gitea
|
||||||
|
begin
|
||||||
|
@gitea_data = $gitea_hat_client.post_repos_branches_restore_by_owner_repo(owner, repo, {query: request_params, body: request_body.to_json})
|
||||||
|
rescue => e
|
||||||
|
raise Error, '恢复分支失败!'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -23,4 +23,14 @@ json.commit_time branch['commit']['timestamp']
|
||||||
json.default_branch default_branch || nil
|
json.default_branch default_branch || nil
|
||||||
json.http_url render_http_url(@project)
|
json.http_url render_http_url(@project)
|
||||||
json.zip_url render_zip_url(@owner, @project.repository, branch['name'])
|
json.zip_url render_zip_url(@owner, @project.repository, branch['name'])
|
||||||
json.tar_url render_tar_url(@owner, @project.repository, branch['name'])
|
json.tar_url render_tar_url(@owner, @project.repository, branch['name'])
|
||||||
|
json.branch_id branch['id']
|
||||||
|
json.is_deleted branch['is_deleted']
|
||||||
|
json.deleted_unix branch['deleted_unix']
|
||||||
|
json.deleted_by do
|
||||||
|
if branch['is_deleted']
|
||||||
|
json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(branch['deleted_by']), name: branch['deleted_by']['name'] }
|
||||||
|
else
|
||||||
|
json.nil!
|
||||||
|
end
|
||||||
|
end
|
|
@ -80,6 +80,7 @@ defaults format: :json do
|
||||||
resources :branches, param: :name, only:[:index, :create, :destroy] do
|
resources :branches, param: :name, only:[:index, :create, :destroy] do
|
||||||
collection do
|
collection do
|
||||||
get :all
|
get :all
|
||||||
|
post :restore
|
||||||
patch :update_default_branch
|
patch :update_default_branch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue