From f738dbed24206f6366815c8592e428a3bc20d712 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 10:16:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=EF=BC=8C=E6=B5=81=E6=B0=B4=E7=BA=BF=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=97=B6=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/actions/actions_controller.rb | 6 +++++- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- app/models/gitea/repo_unit.rb | 9 +++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/models/gitea/repo_unit.rb diff --git a/app/controllers/api/v1/projects/actions/actions_controller.rb b/app/controllers/api/v1/projects/actions/actions_controller.rb index cc80b68de..65fb8139d 100644 --- a/app/controllers/api/v1/projects/actions/actions_controller.rb +++ b/app/controllers/api/v1/projects/actions/actions_controller.rb @@ -4,7 +4,9 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue [] @workflows = params[:workflows].split(",") if params[:workflows].present? @action_runs = Gitea::ActionRun.where(repo_id: @project.gpid) - @action_runs = @action_runs.where(id: params[:ids].split(",")) if params[:ids].present? + disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config + disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] + @action_runs = @action_runs.where(id: params[:ids].split(",")) if params[:ids].present? @action_runs = @action_runs.where(workflow_id: @workflows) if params[:workflows].present? group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count @result = [] @@ -14,6 +16,7 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions end last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first last_action_run_json = last_action_run.present? ? { + pipeline_id: Action::Pipeline.find_by(pipeline_name: file, project_id: @project.id), id: last_action_run.id, schedule: last_action_run.schedule_id > 0, title: last_action_run.title, @@ -47,6 +50,7 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions end @result << { filename: file, + disabled: disabled_workflows.include?(file.to_s), name: file.to_s.gsub(".yml","").gsub(".yaml","") , branch: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch, pipeline_type: pipeline_type, diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 1e1be4dc8..a17e20390 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -35,7 +35,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def save_yaml - @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) + @pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id) @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json diff --git a/app/models/gitea/repo_unit.rb b/app/models/gitea/repo_unit.rb new file mode 100644 index 000000000..c83712b0e --- /dev/null +++ b/app/models/gitea/repo_unit.rb @@ -0,0 +1,9 @@ +class Gitea::RepoUnit < Gitea::Base + self.inheritance_column = nil # FIX The single-table inheritance mechanism failed + # establish_connection :gitea_db + + self.table_name = "repo_unit" + + # belongs_to :user, class_name: '::User', primary_key: :gitea_uid, foreign_key: :owner_id, optional: true + +end