From 117e2683069cebc69a01604db90278e8a63ab809 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 17 Dec 2024 15:05:51 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=8F=90=E5=8F=96=E5=90=8E=E4=BF=9D=E5=AD=98=E6=95=B0=E6=8D=AE?= =?UTF-8?q?db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 27 ++++++++++++++++++- app/models/action/pipeline_result.rb | 25 +++++++++++++++++ config/routes/api.rb | 2 ++ ...14121789_create_action_pipeline_results.rb | 15 +++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/models/action/pipeline_result.rb create mode 100644 db/migrate/20241214121789_create_action_pipeline_results.rb diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 71d588491..898adbb01 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -1,5 +1,5 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController - before_action :require_operate_above + before_action :require_operate_above, except: [:upload_results, :run_results] def index @pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc) @@ -87,6 +87,31 @@ 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]) + tip_exception("项目不存在") if @project.blank? + result = Action::PipelineResult.find_or_initialize_by(run_id: params[:run_id], project_id: @project.id) + result.step_id = params[:step_id] + result.job_name = params[:job_name] + result.job_show_type = params[:job_show_type] || "html" + result.job_result = params[:job_result] + if result.save! + render_ok + else + render_error("保存失败") + end + end + + def run_results + 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) + render_ok(data: results.as_json(only: %i[id run_id job_name job_show_type job_result])) + end + def show @pipeline = Action::Pipeline.find_by(id: params[:id]) @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank? diff --git a/app/models/action/pipeline_result.rb b/app/models/action/pipeline_result.rb new file mode 100644 index 000000000..e4edc024b --- /dev/null +++ b/app/models/action/pipeline_result.rb @@ -0,0 +1,25 @@ +# == Schema Information +# +# Table name: action_pipeline_results +# +# id :integer not null, primary key +# project_id :integer +# run_id :integer +# step_id :string(255) +# job_name :string(255) +# job_show_type :string(255) +# job_result :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_action_pipeline_results_on_project_id (project_id) +# index_action_pipeline_results_on_run_id (run_id) +# + +class Action::PipelineResult < ApplicationRecord + self.table_name = 'action_pipeline_results' + belongs_to :project +end + diff --git a/config/routes/api.rb b/config/routes/api.rb index 242037e09..3d6078b13 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -175,6 +175,8 @@ defaults format: :json do resources :pipelines do post :build_yaml, on: :collection post :save_yaml, on: :collection + post :upload_results, on: :collection + get :run_results, on: :collection get :test_yaml, on: :collection end resources :pulls, module: 'pulls' do diff --git a/db/migrate/20241214121789_create_action_pipeline_results.rb b/db/migrate/20241214121789_create_action_pipeline_results.rb new file mode 100644 index 000000000..4470f5cc1 --- /dev/null +++ b/db/migrate/20241214121789_create_action_pipeline_results.rb @@ -0,0 +1,15 @@ +class CreateActionPipelineResults < ActiveRecord::Migration[5.2] + def change + create_table :action_pipeline_results do |t| + t.references :project + t.integer :run_id + t.string :step_id + t.string :job_name + t.string :job_show_type + t.text :job_result + t.timestamps + end + + add_index :action_pipeline_results, :run_id + end +end