fixed 节点数据提取后保存数据db
This commit is contained in:
parent
e822652901
commit
117e268306
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue