From f8f525bf91a728d3ffb41cb0bc81568a5f3b5b50 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 09:25:52 +0800 Subject: [PATCH 01/18] puma config --- config/puma.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/puma.rb b/config/puma.rb index e31c00feb..7b1c435c7 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,12 +4,12 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 8 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch("PORT") { 4000 } # Specifies the `environment` that Puma will run in. # @@ -21,7 +21,8 @@ environment ENV.fetch("RAILS_ENV") { "development" } # Workers do not work on JRuby or Windows (both of which do not support # processes). # -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +workers ENV.fetch("WEB_CONCURRENCY") { 8 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code From f738dbed24206f6366815c8592e428a3bc20d712 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 10:16:40 +0800 Subject: [PATCH 02/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E7=8A=B6=E6=80=81=EF=BC=8C=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E8=AE=BE=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 From 001f90aede698b30728b29010e975157d18f865d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:00:54 +0800 Subject: [PATCH 03/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index a17e20390..bc73eecae 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -2,6 +2,24 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController before_action :require_operate_above, except: [:upload_results, :run_results] def index + pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) + @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue [] + db_files = pipelines.pluck(:file_name) + @files.map { |i| i['name'] }.each do |file| + unless db_files.include?(".gitea/workflows/#{file}") + pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), + file_name: ".gitea/workflows/#{file}", + branch: @project.default_branch, + is_graphic_design: false, + project_id: @project.id) + interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch) + if interactor.success? + pipeline.yaml = decode64_content(interactor.result, @owner, @project.repository, @project.default_branch, nil) + end + pipeline.user_id = current_user.id + pipeline.save + end + end @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @pipelines = paginate @pipelines end @@ -88,7 +106,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController render_ok end - def upload_results tip_exception("参数错误") if params[:owner].blank? || params[:repo].blank? || params[:run_id].blank? @project, @owner = Project.find_with_namespace(params[:owner], params[:repo]) @@ -109,7 +126,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController tip_exception("参数错误") if params[:owner].blank? || params[:repo].blank? || params[:run_id].blank? @project, @owner = Project.find_with_namespace(params[:owner], params[:repo]) tip_exception("项目不存在") if @project.blank? - results = Action::PipelineResult.where(run_id: params[:run_id], project_id: @project.id) + results = Action::PipelineResult.where(run_id: params[:run_id], project_id: @project.id) render_ok(run_results: results.as_json(only: %i[id run_id job_name job_show_type job_result])) end From 0c438cbe216e655528d3fc9bfa62ced68511fbbb Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:04:21 +0800 Subject: [PATCH 04/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96,include=20RepositoriesHelper?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index bc73eecae..63e4dca93 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -1,4 +1,5 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController + include RepositoriesHelper before_action :require_operate_above, except: [:upload_results, :run_results] def index From 164bcb86bd66bbda12471e1d7e31cb9e93920f53 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:20:37 +0800 Subject: [PATCH 05/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 32 +++++++++++++++++++ app/models/action/pipeline.rb | 4 +++ .../v1/projects/pipelines/index.json.jbuilder | 7 ++-- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 63e4dca93..17907aa48 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -5,13 +5,17 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def index pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue [] + @action_runs = Gitea::ActionRun.where(repo_id: @project.gpid) + group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count db_files = pipelines.pluck(:file_name) + @run_result = [] @files.map { |i| i['name'] }.each do |file| unless db_files.include?(".gitea/workflows/#{file}") pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), file_name: ".gitea/workflows/#{file}", branch: @project.default_branch, is_graphic_design: false, + disable: false, project_id: @project.id) interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch) if interactor.success? @@ -20,6 +24,34 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController pipeline.user_id = current_user.id pipeline.save end + last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first + last_action_run_json = last_action_run.present? ? { + id: last_action_run.id, + schedule: last_action_run.schedule_id > 0, + title: last_action_run.title, + index: last_action_run.index, + status: last_action_run.status, + started: last_action_run.started, + stopped: last_action_run.stopped, + length: last_action_run.stopped-last_action_run.started, + created: last_action_run.created, + updated: last_action_run.updated, + } : {} + + total = 0 + success = 0 + failure = 0 + group_data.each do |k,v| + total += v if k[0] == file + success += v if k[0] == file && k[1] == 1 + failure += v if k[0] == file && k[1] == 2 + end + @run_result << { + filename: ".gitea/workflows/#{file}", + total: total, + success: success, + failure: failure + }.merge(last_action_run_json) end @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @pipelines = paginate @pipelines diff --git a/app/models/action/pipeline.rb b/app/models/action/pipeline.rb index c5a511168..7086886a1 100644 --- a/app/models/action/pipeline.rb +++ b/app/models/action/pipeline.rb @@ -36,4 +36,8 @@ class Action::Pipeline < ApplicationRecord validates :pipeline_name, presence: { message: "不能为空" } validates :json, length: { maximum: 65535, too_long: "不能超过65535个字符"} validates :yaml, length: { maximum: 65535, too_long: "不能超过65535个字符"} + + def pipeline_type + self.is_graphic_design? ? 2 : 1 + end end diff --git a/app/views/api/v1/projects/pipelines/index.json.jbuilder b/app/views/api/v1/projects/pipelines/index.json.jbuilder index 7c3f2a405..864173e3b 100644 --- a/app/views/api/v1/projects/pipelines/index.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/index.json.jbuilder @@ -1,8 +1,9 @@ json.status 0 json.message "success" -json.pipelines @pipelines.each do |pip| - json.extract! pip, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, +json.pipelines @pipelines.each do |pipeline| + json.extract! pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at - # json.project + json.pipeline_type + json.run_data @run_result.select { |result| result.filename == pipeline.file_name }.first end From 6e92086d3ee11ba366a218ee5d96cb87db33902d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:23:12 +0800 Subject: [PATCH 06/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/projects/pipelines/index.json.jbuilder b/app/views/api/v1/projects/pipelines/index.json.jbuilder index 864173e3b..0b07b047a 100644 --- a/app/views/api/v1/projects/pipelines/index.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/index.json.jbuilder @@ -5,5 +5,5 @@ json.pipelines @pipelines.each do |pipeline| json.extract! pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at json.pipeline_type - json.run_data @run_result.select { |result| result.filename == pipeline.file_name }.first + json.run_data @run_result.select { |result| result["filename"] == pipeline.file_name }.first end From b2acea82a374a1e9f87c7a903333bc894c846d0f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:23:46 +0800 Subject: [PATCH 07/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3,log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 17907aa48..16e01b853 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -53,6 +53,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController failure: failure }.merge(last_action_run_json) end + Rails.logger.info("@run_result======#{@run_result}") @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @pipelines = paginate @pipelines end From 0c5395bff6c99730d849bfdf54f756f73bdb7671 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:31:15 +0800 Subject: [PATCH 08/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3,log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/projects/pipelines/index.json.jbuilder b/app/views/api/v1/projects/pipelines/index.json.jbuilder index 0b07b047a..3f7706798 100644 --- a/app/views/api/v1/projects/pipelines/index.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/index.json.jbuilder @@ -5,5 +5,5 @@ json.pipelines @pipelines.each do |pipeline| json.extract! pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at json.pipeline_type - json.run_data @run_result.select { |result| result["filename"] == pipeline.file_name }.first + json.run_data @run_result.select { |result| result[:filename] == pipeline.file_name }.first end From cf72921eb1a970b2fca6845268b3de0af7bff6cd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:35:19 +0800 Subject: [PATCH 09/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3,=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E7=A6=81=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 16e01b853..78b0b2e76 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -11,11 +11,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @run_result = [] @files.map { |i| i['name'] }.each do |file| unless db_files.include?(".gitea/workflows/#{file}") + disabled_config = Gitea::RepoUnit.where(repo_id: @project.gpid, type: 10)&.first&.config + disabled_workflows = disabled_config.present? ? JSON.parse(disabled_config)["DisabledWorkflows"] : [] pipeline = Action::Pipeline.new(pipeline_name: file.to_s.gsub(".yml", "").gsub(".yaml", ""), file_name: ".gitea/workflows/#{file}", branch: @project.default_branch, is_graphic_design: false, - disable: false, + disable: disabled_workflows.include?(file.to_s), project_id: @project.id) interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, ".gitea/workflows/#{file}", ref: @project.default_branch) if interactor.success? From 3b04a592150f3cd01dfcc192acb770b1cc02f6be Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:44:15 +0800 Subject: [PATCH 10/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 10 +--------- .../api/v1/projects/pipelines/create.json.jbuilder | 5 +++++ 2 files changed, 6 insertions(+), 9 deletions(-) create mode 100644 app/views/api/v1/projects/pipelines/create.json.jbuilder diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 78b0b2e76..ebe1c109a 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -76,16 +76,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline = Action::Pipeline.new(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 - pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) - tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? - @pipeline.yaml = pipeline_yaml + @pipeline.is_graphic_design = params[:pipeline_type] == 2 ? true : false @pipeline.save! - sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) - tip_exception("#{@pipeline.file_name}已存在") if sha - interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) - tip_exception(interactor.error) unless interactor.success? - render_ok({ id: @pipeline.id }) end def save_yaml diff --git a/app/views/api/v1/projects/pipelines/create.json.jbuilder b/app/views/api/v1/projects/pipelines/create.json.jbuilder new file mode 100644 index 000000000..d82015ade --- /dev/null +++ b/app/views/api/v1/projects/pipelines/create.json.jbuilder @@ -0,0 +1,5 @@ +json.status 0 +json.message "success" +json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, + :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at +# json.project \ No newline at end of file From 9d3ee56b6f1ceec6966399b728a734ada906ad40 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:48:13 +0800 Subject: [PATCH 11/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E6=8E=A5=E5=8F=A3,=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E7=A6=81=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/api/v1/projects/pipelines/index.json.jbuilder b/app/views/api/v1/projects/pipelines/index.json.jbuilder index 3f7706798..fb0a74393 100644 --- a/app/views/api/v1/projects/pipelines/index.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/index.json.jbuilder @@ -4,6 +4,6 @@ json.message "success" json.pipelines @pipelines.each do |pipeline| json.extract! pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at - json.pipeline_type + json.pipeline_type pipeline.pipeline_type json.run_data @run_result.select { |result| result[:filename] == pipeline.file_name }.first end From e50a14595d490d6e7c99e9950777ffb3f715cb03 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 17 Mar 2025 11:53:23 +0800 Subject: [PATCH 12/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E7=BC=96?= =?UTF-8?q?=E6=8E=92=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index ebe1c109a..c123bb3fa 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -81,7 +81,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def save_yaml - @pipeline = Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id) + @pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : 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 From ffa4c6e870009516d22e09e23b74d549e56c383b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 11:37:19 +0800 Subject: [PATCH 13/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E4=BF=9D=E5=AD=98=E6=94=AF=E6=8C=81=E9=87=8D=E5=90=8D?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index c123bb3fa..af83fb15e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -71,9 +71,19 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end def create - size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size - tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 - @pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id) + @pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : Action::Pipeline.find_or_initialize_by(pipeline_name: params[:pipeline_name], project_id: @project.id) + if @pipeline.pipeline_name != params[:pipeline_name] + has_pipeline = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).where.not(id: @pipeline.id) + tip_exception("已经存在#{params[:pipeline_name]}流水线!") if has_pipeline.present? + if @pipeline.yaml.present? + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + if sha.present? + interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update", params[:pipeline_name]).merge(sha: sha, from_path: "#{@pipeline.pipeline_name}")) + tip_exception(interactor.error) unless interactor.success? + end + end + end + @pipeline.pipeline_name = params[:pipeline_name] @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.is_graphic_design = params[:pipeline_type] == 2 ? true : false @@ -93,6 +103,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? file = interactor.result + @pipeline.pipeline_type = @pipeline.json.present? ? 2 : 1 @pipeline.save render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) end @@ -203,9 +214,9 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController end end - def content_params(opt) + def content_params(opt, rename_file=nil) { - filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", + filepath: ".gitea/workflows/#{rename_file.present? ? rename_file : @pipeline.pipeline_name}.yml", branch: @pipeline.branch, new_branch: @pipeline.branch, content: opt == "create" ? Base64.encode64(@pipeline.yaml).gsub(/\n/, '') : @pipeline.yaml, From ec139870233d4ebcc21c4dae84bc564d39794e95 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 12:04:56 +0800 Subject: [PATCH 14/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BFpipeline=5Ftyp?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 1 + app/models/action/pipeline.rb | 4 ---- app/views/api/v1/projects/pipelines/create.json.jbuilder | 5 ++--- app/views/api/v1/projects/pipelines/show.json.jbuilder | 3 +-- db/migrate/202503180515147_add_pipelines_type.rb | 5 +++++ 5 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 db/migrate/202503180515147_add_pipelines_type.rb diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index af83fb15e..0e0956d9e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -87,6 +87,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.is_graphic_design = params[:pipeline_type] == 2 ? true : false + @pipeline.pipeline_type = params[:pipeline_type] if params[:pipeline_type].present? @pipeline.save! end diff --git a/app/models/action/pipeline.rb b/app/models/action/pipeline.rb index 7086886a1..c5a511168 100644 --- a/app/models/action/pipeline.rb +++ b/app/models/action/pipeline.rb @@ -36,8 +36,4 @@ class Action::Pipeline < ApplicationRecord validates :pipeline_name, presence: { message: "不能为空" } validates :json, length: { maximum: 65535, too_long: "不能超过65535个字符"} validates :yaml, length: { maximum: 65535, too_long: "不能超过65535个字符"} - - def pipeline_type - self.is_graphic_design? ? 2 : 1 - end end diff --git a/app/views/api/v1/projects/pipelines/create.json.jbuilder b/app/views/api/v1/projects/pipelines/create.json.jbuilder index d82015ade..83b3aabd9 100644 --- a/app/views/api/v1/projects/pipelines/create.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/create.json.jbuilder @@ -1,5 +1,4 @@ json.status 0 json.message "success" -json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, - :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at -# json.project \ No newline at end of file +json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :pipeline_type, + :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at \ No newline at end of file diff --git a/app/views/api/v1/projects/pipelines/show.json.jbuilder b/app/views/api/v1/projects/pipelines/show.json.jbuilder index d82015ade..996bd0556 100644 --- a/app/views/api/v1/projects/pipelines/show.json.jbuilder +++ b/app/views/api/v1/projects/pipelines/show.json.jbuilder @@ -1,5 +1,4 @@ json.status 0 json.message "success" -json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, +json.extract! @pipeline, :id, :pipeline_name, :pipeline_status, :description, :file_name, :is_graphic_design, :pipeline_type, :repo_name, :repo_identifier, :branch, :event, :sha, :disable, :json, :yaml, :created_at, :updated_at -# json.project \ No newline at end of file diff --git a/db/migrate/202503180515147_add_pipelines_type.rb b/db/migrate/202503180515147_add_pipelines_type.rb new file mode 100644 index 000000000..2f34900c0 --- /dev/null +++ b/db/migrate/202503180515147_add_pipelines_type.rb @@ -0,0 +1,5 @@ +class AddPipelinesType < ActiveRecord::Migration[5.2] + def change + add_column :action_pipelines, :pipeline_type, :integer, :default => 1 + end +end From 469d086cac009b74845c8579f89a334a3450761d Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 15:59:53 +0800 Subject: [PATCH 15/18] my_issues category=opened --- app/controllers/api/pm/dashboards_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 2798c3c52..36e361079 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -20,6 +20,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController pm_issue_types = params[:pm_issue_types].split(",") rescue [] @all_issues = Issue.where(pm_project_id: pm_project_ids, pm_issue_type: pm_issue_types) @issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id}) + @issues = @issues.where.not(status_id: 5) if params[:category] == "opened" @issues = kaminari_paginate(@issues.distinct.pm_includes) @my_assign_requirements_count = @all_issues.where(pm_issue_type: 1).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size From 4514b8b5ff75fb0b21d7e23ae7c2e3548962bd79 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 16:51:52 +0800 Subject: [PATCH 16/18] =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E5=BC=8F=EF=BC=8C=E5=9B=BE=E5=BD=A2=E4=BB=A3=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 0e0956d9e..92654bc3e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -95,8 +95,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline = params[:id].present? ? Action::Pipeline.find(params[:id]) : 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 - pipeline_yaml = build_pipeline_yaml_new(params[:pipeline_name], params[:pipeline_json]) + @pipeline.json = params[:pipeline_json].to_json if params[:pipeline_json].present? + pipeline_yaml = params[:pipeline_yaml].present? ? params[:pipeline_yaml] : build_pipeline_yaml_new(params[:pipeline_name], params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" From a06e55d30cd27a0691df502dc17d75bfdaff7110 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 17:06:41 +0800 Subject: [PATCH 17/18] =?UTF-8?q?fixed=20=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 92654bc3e..107bd357c 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -230,7 +230,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController } end - def del_content_params(opt) + def del_content_params { filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", base64_filepath: Base64.encode64(".gitea/workflows/#{@pipeline.pipeline_name}.yml").gsub(/\n/, ''), From b67ed4d74bfe64d857d4de785f1ec3bff2dcfa97 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 19 Mar 2025 17:23:48 +0800 Subject: [PATCH 18/18] =?UTF-8?q?fixed=20=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8A=A5=E9=94=99,=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 107bd357c..5aa62caab 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -139,8 +139,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def destroy @pipeline = Action::Pipeline.find(params[:id]) if @pipeline - interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, del_content_params.merge(identifier: @project.identifier)) - tip_exception(interactor.error) unless interactor.success? + sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + if sha.present? + interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, del_content_params(sha).merge(identifier: @project.identifier)) + tip_exception(interactor.error) unless interactor.success? + end @pipeline.destroy! end render_ok @@ -230,12 +233,12 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController } end - def del_content_params + def del_content_params(sha) { filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml", base64_filepath: Base64.encode64(".gitea/workflows/#{@pipeline.pipeline_name}.yml").gsub(/\n/, ''), branch: @pipeline.branch, - sha: get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch) + sha: sha } end