From c4728713555fcc429743a886079c3c8291683ac8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Dec 2024 10:09:40 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E8=B0=83=E6=95=B4job.id=E5=92=8C?= =?UTF-8?q?=E4=BE=9D=E8=B5=96id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 4 +++- app/models/action/node.rb | 2 +- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 898adbb01..0f20df969 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -92,7 +92,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? - result = Action::PipelineResult.find_or_initialize_by(run_id: params[:run_id], project_id: @project.id) + result = Action::PipelineResult.find_or_initialize_by(run_id: params[:run_id], step_id: params[:step_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" @@ -131,6 +131,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController next_edge_nodes = pipeline_json["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } next_step_node = pipeline_json["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first + parent_node = pipeline_json["edges"].select { |edge| edge["target"]["cell"].include?(job["id"]) }.first + node.parent_node_id = parent_node.present? ? parent_node["source"]["cell"] : "" node.sub_nodes = [] get_all_child_nodes(pipeline_json, node, next_step_node) if next_step_node.present? @job_nodes.push(node) diff --git a/app/models/action/node.rb b/app/models/action/node.rb index b92837b7b..0dce4cd68 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -38,7 +38,7 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true - attr_accessor :cust_name, :run_values, :input_values, :sub_nodes, :link_type_array, :node_id + attr_accessor :cust_name, :run_values, :input_values, :parent_node_id, :sub_nodes, :link_type_array, :node_id validates :name, presence: { message: "不能为空" } validates :full_name, length: { maximum: 200, too_long: "不能超过200个字符" } diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index 75459273d..cda797b1a 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -37,12 +37,12 @@ on: jobs: <%@job_nodes.each_with_index do |job,index| %> - job<%=index + 1 %>: + <%=job.node_id %>: name: "<%=job.label || job.name %>[<%=job.node_id %>]" # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' <% if index >0 %> - needs: job<%=index %> + needs: <%=job.parent_node_id %> <% end %> steps: <%job.sub_nodes.each do |node| %>