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
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)
@begin_num = (page.to_i - 1) * limit.to_i
# puts @result_object
end
end
def create

View File

@ -1,5 +1,6 @@
json.total_data @result_object[:total_data].to_i
if @result_object[:data]["Runs"].present?
if @has_file
json.total_data @result_object[:total_data].to_i
if @result_object[:data]["Runs"].present?
json.runs @result_object[:data]["Runs"].each_with_index.to_a do |run, index|
json.num @result_object[:total_data].to_i - @begin_num - index
json.workflow run["WorkflowID"]
@ -19,6 +20,10 @@ if @result_object[:data]["Runs"].present?
json.time_ago time_from_now(run["Created"])
json.holding_time run["Status"] == 6 ? Time.now.to_i - run["Created"] : run["Stopped"] - run["Created"]
end
else
json.runs []
end
else
json.total_data 0
json.runs []
end