From 7ff07e9c29b25d25588ff9b88ba4b70b5b1fe7e3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 21 Apr 2025 16:05:29 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E7=BB=84=E7=BB=87=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E8=BF=90=E8=A1=8C=E6=95=B0=E6=8D=AE=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E6=9C=89=E6=96=87=E4=BB=B6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/actions/runs_controller.rb | 9 ++-- .../projects/actions/runs/index.json.jbuilder | 43 +++++++++++-------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/app/controllers/api/v1/projects/actions/runs_controller.rb b/app/controllers/api/v1/projects/actions/runs_controller.rb index cdde508a1..162aa84cb 100644 --- a/app/controllers/api/v1/projects/actions/runs_controller.rb +++ b/app/controllers/api/v1/projects/actions/runs_controller.rb @@ -1,9 +1,12 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController def index - @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 + @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 + end end def create diff --git a/app/views/api/v1/projects/actions/runs/index.json.jbuilder b/app/views/api/v1/projects/actions/runs/index.json.jbuilder index e0a8aa189..3014aa6d7 100644 --- a/app/views/api/v1/projects/actions/runs/index.json.jbuilder +++ b/app/views/api/v1/projects/actions/runs/index.json.jbuilder @@ -1,24 +1,29 @@ -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"] - json.index run["Index"] - json.title run["Title"] - json.trigger_user do - json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(run['TriggerUser']), name: run['TriggerUser']['Name'] } - end +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"] + json.index run["Index"] + json.title run["Title"] + json.trigger_user do + json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(run['TriggerUser']), name: run['TriggerUser']['Name'] } + end - if run["Ref"].starts_with?("refs/tags") - json.ref run["Ref"].gsub!("/refs/tags/", "") - else - json.ref run["Ref"].gsub!("refs/heads/", "") - end + if run["Ref"].starts_with?("refs/tags") + json.ref run["Ref"].gsub!("/refs/tags/", "") + else + json.ref run["Ref"].gsub!("refs/heads/", "") + end - json.status run["Status"] - json.time_ago time_from_now(run["Created"]) - json.holding_time run["Status"] == 6 ? Time.now.to_i - run["Created"] : run["Stopped"] - run["Created"] + json.status run["Status"] + 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.runs [] + json.total_data 0 + json.runs [] end \ No newline at end of file