fixed 组织流水线运行数据判断是否有文件存在

This commit is contained in:
xxq250 2025-04-21 16:05:29 +08:00
parent 88415e256d
commit 7ff07e9c29
2 changed files with 30 additions and 22 deletions

View File

@ -1,9 +1,12 @@
class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController
def index def index
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows/#{params[:workflow]}") rescue []
@has_file = @files.select { |i| i['name'] == params[:workflow] }.present?
if @has_file
@result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token) @result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token)
@begin_num = (page.to_i - 1) * limit.to_i @begin_num = (page.to_i - 1) * limit.to_i
# puts @result_object end
end end
def create def create

View File

@ -1,3 +1,4 @@
if @has_file
json.total_data @result_object[:total_data].to_i json.total_data @result_object[:total_data].to_i
if @result_object[:data]["Runs"].present? if @result_object[:data]["Runs"].present?
json.runs @result_object[:data]["Runs"].each_with_index.to_a do |run, index| json.runs @result_object[:data]["Runs"].each_with_index.to_a do |run, index|
@ -22,3 +23,7 @@ if @result_object[:data]["Runs"].present?
else else
json.runs [] json.runs []
end end
else
json.total_data 0
json.runs []
end