Merge remote-tracking branch 'origin/standalone_develop' into standalone_develop

This commit is contained in:
xxq250 2026-02-09 09:51:10 +08:00
commit 63a5b83e96
10 changed files with 53 additions and 13 deletions

View File

@ -51,7 +51,7 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::B
domain = GiteaService.gitea_config[:domain]
api_url = GiteaService.gitea_config[:hat_base_url]
url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs"
url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{URI.escape(params[:run_id])}/jobs/#{URI.escape(params[:job])}/logs"
file_path = [domain, api_url, url].join
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?")

View File

@ -32,16 +32,35 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
end
before_action :require_operate_above, only: [:create, :destroy, :restore]
before_action :require_operate_above, only: [:create, :delete, :destroy, :restore]
def create
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
@project.update_column(:updated_on, Time.now)
end
def delete
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, params[:branch_name], current_user&.gitea_token)
if @result_object
@project.update_column(:updated_on, Time.now)
# 有开启的pr需要一同关闭
# 1、删除本仓库中存在未关闭的pr,即本仓库分支1->分支2
# 2、如果是fork仓库考虑删除主仓库中存在未关闭的pr,即本仓库分支1->主分支2同时分两种删除1删除本仓库分支12删除主仓库分支2
close_pull_requests_by(@project, params[:branch_name])
if @project.forked_from_project_id.present?
# fork项目中删除分支
close_pull_requests_by(@project.fork_project, params[:branch_name])
end
return render_ok
else
return render_error('删除分支失败!')
end
end
def destroy
@name = params[:name].include?('.json') ? params[:name][0..-6] : params[:name]
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, URI.escape(Base64.decode64(@name)), current_user&.gitea_token)
@result_object = Api::V1::Projects::Branches::DeleteService.call(@project, Base64.decode64(@name), current_user&.gitea_token)
if @result_object
@project.update_column(:updated_on, Time.now)
# 有开启的pr需要一同关闭

View File

@ -12,7 +12,7 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController
def files
if params[:filepath].present?
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha_filepath(@project&.owner.login, @project&.identifier, params[:sha], CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha_filepath(@project&.owner.login, @project&.identifier, params[:sha], URI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
else
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha(@project&.owner.login, @project&.identifier, params[:sha], {query: {token: current_user&.gitea_token, page: page, limit: limit}})
end

View File

@ -37,7 +37,7 @@ class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController
def files
if params[:filepath].present?
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index_filepath(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index_filepath(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, URI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
else
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, {query: {isNew: "true",token: current_user&.gitea_token, page: page, limit: limit}})
end

View File

@ -11,7 +11,7 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController
@result_object = Api::V1::Projects::Tags::GetService.call(@project, Base64.decode64(@name), current_user&.gitea_token)
end
before_action :require_operate_above, only: [:create, :destroy]
before_action :require_operate_above, only: [:create, :delete, :destroy]
def create
@result_object = Api::V1::Projects::Tags::CreateService.call(@project, tag_params, current_user&.gitea_token)
@ -19,6 +19,15 @@ class Api::V1::Projects::TagsController < Api::V1::BaseController
@project.update_column(:updated_on, Time.now)
end
def delete
@result_object = Api::V1::Projects::Tags::DeleteService.call(@project, params[:tag_name], current_user&.gitea_token)
if @result_object
return render_ok
else
return render_error('删除标签失败!')
end
end
def destroy
@name = params[:name].include?('.json') ? params[:name][0..-6] : params[:name]
@result_object = Api::V1::Projects::Tags::DeleteService.call(@project, Base64.decode64(@name), current_user&.gitea_token)

View File

@ -83,7 +83,7 @@ class RepositoriesController < ApplicationController
end
def sub_entries
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s))
tip_exception('不可访问') if params[:filepath].to_s.include?("chinese_dictionary.txt")
if @project.educoder?
if params[:type] === 'file'
@ -337,7 +337,7 @@ class RepositoriesController < ApplicationController
# TODO 获取最新commit信息
def project_commits
if params[:filepath].present?
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s))
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
sha: get_ref, page: 1, limit: 1, token: @project&.owner&.gitea_token).call
else

View File

@ -39,8 +39,15 @@ class Api::V1::Projects::Branches::CreateService < ApplicationService
end
def excute_data_to_gitea
@gitea_data = $gitea_client.post_repos_branches_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil
raise Error, '创建分支失败!' unless @gitea_data.is_a?(Hash)
begin
@gitea_data = $gitea_client.post_repos_branches_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params})
rescue Gitea::Api::ServerError => e
if e.http_code == 409 && e.to_s.include?("The branch with the same tag already exists")
raise Error, '创建分支失败,分支名称与标签名称不能相同!'
else
raise Error, '创建分支失败!'
end
end
end
def check_branch_exist

View File

@ -32,7 +32,7 @@ class Api::V1::Projects::Branches::DeleteService < ApplicationService
def excute_data_to_gitea
begin
@gitea_data = $gitea_client.delete_repos_branches_by_owner_repo_branch(owner, repo, CGI.escape(branch_name), {query: request_params})
@gitea_data = $gitea_client.delete_repos_branches_by_owner_repo_branch(owner, repo, URI.encode(branch_name), {query: request_params})
rescue => e
raise Error, '保护分支无法删除!' if e.to_s.include?("branch protected")
raise Error, '删除分支失败!'

View File

@ -32,7 +32,7 @@ class Api::V1::Projects::Tags::DeleteService < ApplicationService
def excute_data_to_gitea
begin
@gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, CGI.escape(tag_name), {query: request_params})
@gitea_data = $gitea_client.delete_repos_tags_by_owner_repo_tag(owner, repo, URI.encode(tag_name), {query: request_params})
rescue => e
raise Error, '请先删除发行版!' if e.to_s.include?("409")
raise Error, '删除标签失败!'

View File

@ -235,12 +235,17 @@ defaults format: :json do
get :github
get :all
post :restore
post :delete
patch :update_default_branch
end
end
match 'branches/*name', to: "branches#destroy", via: :all, constraints: { name: /[^\/]+/ }
resources :tags, param: :name, only: [:index, :create]
resources :tags, param: :name, only: [:index, :create] do
collection do
post :delete
end
end
delete 'tags/*name', to: "tags#destroy", via: :all, constraints: { name: /[^\/]+/ }
get 'tags/*name', to: "tags#show", via: :all, constraints: { name: /[^\/]+/ }
get '/compare/:base...:head/files' => 'compare#files', :constraints => { base: /.+/, head: /.+/ }