From 0ca548f3a677b1f62bae0ed09c09511e23e07bc1 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 3 Dec 2024 11:13:54 +0800 Subject: [PATCH 01/56] =?UTF-8?q?fixed=20action=E8=8A=82=E7=82=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E5=92=8C=E9=93=BE=E6=8E=A5=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 6 ++++-- app/models/action/node.rb | 5 ++++- db/migrate/202412030203041_add_action_nodes_type.rb | 7 +++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 db/migrate/202412030203041_add_action_nodes_type.rb diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index d85a6094a..ebccf8efe 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -61,9 +61,11 @@ class Action::NodesController < ApplicationController def node_params if params.require(:action_node) - params.require(:action_node).permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) + params.require(:action_node).permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, + :is_local, :local_url, :yaml, :sort_no, :type, :is_mutil_link, :link_type) else - params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no) + params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, + :yaml, :sort_no, :type, :is_mutil_link, :link_type) end end end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 79c54293d..3ce092fd2 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -34,13 +34,16 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true - attr_accessor :cust_name, :run_values, :input_values + attr_accessor :cust_name, :run_values, :input_values, :next_step_nodes validates :name, presence: { message: "不能为空" } validates :full_name, length: { maximum: 200, too_long: "不能超过200个字符" } validates :label, length: { maximum: 200, too_long: "不能超过200个字符" } validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} + # type 0: 触发器 1: 任务作业, 2: 步骤 + enum type: {trigger: 0, job: 1, step: 2} + def content_yaml "foo".to_yaml diff --git a/db/migrate/202412030203041_add_action_nodes_type.rb b/db/migrate/202412030203041_add_action_nodes_type.rb new file mode 100644 index 000000000..b13aa3ee0 --- /dev/null +++ b/db/migrate/202412030203041_add_action_nodes_type.rb @@ -0,0 +1,7 @@ +class AddActionNodesType < ActiveRecord::Migration[5.2] + def change + add_column :action_nodes, :type, :string + add_column :action_nodes, :is_mutil_link, :boolean + add_column :action_nodes, :link_type, :string + end +end From 18d575512d3da477cef685c36211a08037e52b63 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 3 Dec 2024 11:23:54 +0800 Subject: [PATCH 02/56] =?UTF-8?q?fixed=20action=E8=8A=82=E7=82=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E5=92=8C=E9=93=BE=E6=8E=A5=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/action/node.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 3ce092fd2..072089835 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -42,7 +42,7 @@ class Action::Node < ApplicationRecord validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} # type 0: 触发器 1: 任务作业, 2: 步骤 - enum type: {trigger: 0, job: 1, step: 2} + enum type: {start: 0, job: 1, step: 2} def content_yaml From 1901aca44cabdff71f94e8b4ca9ab9c3f07e073c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 3 Dec 2024 11:27:52 +0800 Subject: [PATCH 03/56] =?UTF-8?q?fixed=20action=E7=B1=BB=E5=9E=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BAnode=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/action/node.rb | 2 +- db/migrate/202412030203041_add_action_nodes_type.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 072089835..ea072bded 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -42,7 +42,7 @@ class Action::Node < ApplicationRecord validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} # type 0: 触发器 1: 任务作业, 2: 步骤 - enum type: {start: 0, job: 1, step: 2} + enum node_type: {start: 0, job: 1, step: 2} def content_yaml diff --git a/db/migrate/202412030203041_add_action_nodes_type.rb b/db/migrate/202412030203041_add_action_nodes_type.rb index b13aa3ee0..bc7d77f4f 100644 --- a/db/migrate/202412030203041_add_action_nodes_type.rb +++ b/db/migrate/202412030203041_add_action_nodes_type.rb @@ -1,6 +1,6 @@ class AddActionNodesType < ActiveRecord::Migration[5.2] def change - add_column :action_nodes, :type, :string + add_column :action_nodes, :node_type, :string add_column :action_nodes, :is_mutil_link, :boolean add_column :action_nodes, :link_type, :string end From 5939e59347812bf6249d53aed3aaa5dc48abfc5e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 3 Dec 2024 11:30:23 +0800 Subject: [PATCH 04/56] =?UTF-8?q?fixed=20action=E7=B1=BB=E5=9E=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=B8=BAnode=5Ftype?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/action/nodes/index.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/action/nodes/index.json.jbuilder b/app/views/action/nodes/index.json.jbuilder index fc8a38505..835c7f145 100644 --- a/app/views/action/nodes/index.json.jbuilder +++ b/app/views/action/nodes/index.json.jbuilder @@ -2,7 +2,7 @@ json.types @node_types.each do |node_type| if node_type.name.to_s == "未分类" json.extract! node_type, :id, :name json.nodes @no_type_nodes do |node| - json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count, :node_type, :is_mutil_link, :link_type json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end @@ -10,7 +10,7 @@ json.types @node_types.each do |node_type| else json.extract! node_type, :id, :name json.nodes node_type.action_nodes do |node| - json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count + json.extract! node, :id, :label, :name, :full_name, :description, :icon, :action_node_types_id, :yaml, :sort_no, :use_count, :node_type, :is_mutil_link, :link_type json.inputs node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: node } end From d9880b66d77e78d231229e7b328da0de85da9cc5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 3 Dec 2024 11:48:47 +0800 Subject: [PATCH 05/56] =?UTF-8?q?fixed=20action=E8=8A=82=E7=82=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/action/node.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/action/node.rb b/app/models/action/node.rb index ea072bded..290d302bd 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -23,7 +23,7 @@ # index_action_nodes_on_action_node_types_id (action_node_types_id) # index_action_nodes_on_user_id (user_id) # - +# node_type 0: 触发器 1: 任务作业, 2: 步骤 class Action::Node < ApplicationRecord self.table_name = 'action_nodes' default_scope { order(sort_no: :asc) } @@ -41,8 +41,6 @@ class Action::Node < ApplicationRecord validates :label, length: { maximum: 200, too_long: "不能超过200个字符" } validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"} - # type 0: 触发器 1: 任务作业, 2: 步骤 - enum node_type: {start: 0, job: 1, step: 2} def content_yaml From 840af7a73cc770b952bde029efb4f62776605a69 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 6 Dec 2024 10:41:15 +0800 Subject: [PATCH 06/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=20issue?= =?UTF-8?q?=E6=89=80=E6=9C=89=E5=AD=90=E5=B7=A5=E4=BD=9C=E9=A1=B9=E5=8F=8A?= =?UTF-8?q?=E5=85=B3=E8=81=94=E5=B7=A5=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 40 ++++++++++++++++++- .../api/pm/issues/link_issues.json.jbuilder | 11 +++++ config/routes/api.rb | 1 + 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 app/views/api/pm/issues/link_issues.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index a10a70bce..281b41ecb 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -237,15 +237,51 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end end + def link_issues + children_issues = Issue.joins(:parent_issue).where(issues: {id: @issue.id}) + linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id)) + belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id)) + + full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) + compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) + i = compare_link_issues_ids.count + while i > 0 do + children_issues = Issue.joins(:parent_issue).where(issues: {id: compare_link_issues_ids}) + linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids)) + belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids)) + + compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) + full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids + i = compare_link_issues_ids.count + end + + @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1) + @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2) + @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3) + end + private + def circle_link_issues(issue_ids) + if issue_ids.present? + children_issues = Issue.joins(:parent_issue).where(issues: {id: issue_ids}) + linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: issue_ids)) + belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: issue_ids)) + + return circle_link_issues(children_issues.pluck(:id)) + else + return [] + end + end + def check_issue_operate_permission return if params[:project_id].to_i.zero? render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user end def load_issue - return render_parameter_missing if params[:pm_project_id].blank? - @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + @issue = Issue.find_by_id params[:id] + # return render_parameter_missing if params[:pm_project_id].blank? + # @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) render_not_found('疑修不存在!') if @issue.blank? end diff --git a/app/views/api/pm/issues/link_issues.json.jbuilder b/app/views/api/pm/issues/link_issues.json.jbuilder new file mode 100644 index 000000000..f20208bf6 --- /dev/null +++ b/app/views/api/pm/issues/link_issues.json.jbuilder @@ -0,0 +1,11 @@ +json.requirement_issues @requirement_issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} +end + +json.task_issues @task_issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} +end + +json.bug_issues @bug_issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 4aaa4beab..3f75a3b22 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -14,6 +14,7 @@ defaults format: :json do member do get :link_index get :parent_issues + get :link_issues end resources :issue_links From 46604c1010bbc822df1c5dbfce29a273aebb7d10 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 6 Dec 2024 10:43:39 +0800 Subject: [PATCH 07/56] load_issues --- app/controllers/api/pm/issues_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 281b41ecb..cf55fa9eb 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -279,9 +279,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def load_issue - @issue = Issue.find_by_id params[:id] - # return render_parameter_missing if params[:pm_project_id].blank? - # @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) + return render_parameter_missing if params[:pm_project_id].blank? + @issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id]) render_not_found('疑修不存在!') if @issue.blank? end From 1681b144d66b8303d6917feaf2f83f905326ed83 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 6 Dec 2024 10:59:10 +0800 Subject: [PATCH 08/56] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index cf55fa9eb..687fa986e 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -238,17 +238,17 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_issues - children_issues = Issue.joins(:parent_issue).where(issues: {id: @issue.id}) - linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id)) - belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id)) + children_issues = Issue.where(root_id: @issue.id) + linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id)) + belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id)) full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) i = compare_link_issues_ids.count while i > 0 do - children_issues = Issue.joins(:parent_issue).where(issues: {id: compare_link_issues_ids}) - linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids)) - belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids)) + children_issues = Issue.where(root_id: compare_link_issues_ids) + linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id)) + belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id)) compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids From 69f801115ce7f728ade58cfe63887de2976cee17 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:11:06 +0800 Subject: [PATCH 09/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 2008 ++++++++++++++--- app/models/action/node.rb | 12 +- .../api/v1/projects/pipelines/_jobs.yaml.erb | 29 + .../v1/projects/pipelines/_test_job.yaml.erb | 51 + .../pipelines/build_pipeline.yaml.erb | 23 +- .../api/v1/projects/pipelines/test.yaml.erb | 33 +- .../v1/projects/pipelines/test_yaml.yaml.erb | 26 + config/routes/api.rb | 1 + 8 files changed, 1854 insertions(+), 329 deletions(-) create mode 100644 app/views/api/v1/projects/pipelines/_jobs.yaml.erb create mode 100644 app/views/api/v1/projects/pipelines/_test_job.yaml.erb create mode 100644 app/views/api/v1/projects/pipelines/test_yaml.yaml.erb diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 888e68960..8e92a74e4 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -6,6 +6,16 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipelines = paginate @pipelines end + def test_yaml + pipeline_yaml = build_pipeline_yaml_new("test", JSON.parse(demo2.to_json)) + respond_to do |format| + format.html { @nodes = Action::Node.all } + # format.yaml { @nodes = Action::Node.all } + format.yaml { render template: "api/v1/projects/pipelines/test_yaml", content_type: "text/html" } + format.json { render_ok({ pipeline_yaml: pipeline_yaml }) } + end + 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 @@ -37,7 +47,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 - render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) end def build_yaml @@ -85,8 +95,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_pipeline_yaml(pipeline_name, pipeline_json) if pipeline_json.present? && pipeline_json.present? @pipeline_name = pipeline_name - params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } - on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } + params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -100,39 +110,23 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController pipeline_yaml end - def build_test_yaml - @pipeline_name = "I like it" - params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } - on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } + def build_pipeline_yaml_new(pipeline_name, pipeline_json) + @pipeline_name = pipeline_name + job_nodes = pipeline_json["nodes"].select { |node| node["data"]["name"].to_s.include?("job") } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["data"]["name"]) } @on_nodes = build_nodes(on_nodes) - @steps_nodes = [] - params_nodes.each do |input_node| - # Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}" - node = Action::Node.find_by(name: input_node["name"]) + @job_nodes = [] + job_nodes.each do |job| + node = Action::Node.find_by(name: job["data"]["name"]) + node.label = job["data"]["label"] if job["data"]["label"].present? next if node.blank? - node.label = input_node["label"] if input_node["label"].present? - run_values = {} - input_values = {} - if input_node["inputs"].present? - Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" - input_node["inputs"].each do |input| - # Rails.logger.info "@inputs.input_name===#{input[:name]}" - # Rails.logger.info "@inputs.input_value===#{input["value"]}" - if input[:name].to_s.gsub("--", "") == "run" - run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) - else - input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) - end - end - node.run_values = run_values - node.input_values = input_values - # Rails.logger.info "@input_values run_values===#{node.run_values.to_json}" - # Rails.logger.info "@input_values input_values===#{node.input_values.to_json}" - end - @steps_nodes.push(node) + next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } + node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } + next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["data"]["id"]) && !node["data"]["name"].to_s.include?("job") }&.first + node.sub_nodes = [] + get_all_child_nodes(node, next_step_node) if next_step_node.present? + @job_nodes.push(node) end - Rails.logger.info "@@on_nodes===#{@on_nodes.to_json}" - Rails.logger.info "@steps_nodes===#{@steps_nodes.to_json}" yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) pipeline_yaml = yaml.gsub(/^\s*\n/, "") Rails.logger.info "=========================" @@ -177,10 +171,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController run_values = {} input_values = {} if input_node["inputs"].present? - Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" input_node["inputs"].each do |input| - # Rails.logger.info "@inputs.input_name===#{input[:name]}" - # Rails.logger.info "@inputs.input_value===#{input["value"]}" if input[:name].to_s.gsub("--", "") == "run" run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) else @@ -195,269 +186,1694 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController steps_nodes end - def demo + def get_all_child_nodes(job_node, target_node) + job_node.sub_nodes.push(get_node_info(target_node)) + target_edge = JSON.parse(demo2.to_json)["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first + # 判断是否有子节点 + if target_edge.present? + next_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first + get_all_child_nodes(job_node, next_node) + end + end + + def get_node_info(input_node) + node = Action::Node.find_by(name: input_node["data"]["name"]) + return nil if node.blank? + node.label = input_node["data"]["label"] if input_node["data"]["label"].present? + run_values = {} + input_values = {} + if input_node["data"]["inputs"].present? + input_node["data"]["inputs"].each do |input| + if input["name"].to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) + else + input_values = input_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) + end + end + node.run_values = run_values + node.input_values = input_values + end + node + end + + def demo2 { - "nodes": [{ - "id": "on-schedule-2fcf505", - "name": "on-schedule", - "full_name": "on-schedule", - "description": " 定时器计划器", - "icon": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", - "action_node_types_id": 3, - "yaml": "", - "sort_no": 0, - "use_count": 0, - "inputs": [{ - "id": 8, - "name": "cron", - "input_type": "input", - "description": "示例:\r\n- cron: '20 8 * * *'", - "is_required": true, - "value": "- corn: '0 10 * * *'" - }], - "x": 586, - "y": 165.328125, - "label": "on-schedule", - "img": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "labelCfg": { - "style": { - "fill": "transparent", - "fontSize": 0, - "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", - "overflow": "hidden", - "x": -20, - "y": 0, - "textAlign": "left", - "textBaseline": "middle" - } - }, - "style": { - "active": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10 - }, - "selected": { - "fill": "rgb(255, 255, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 4, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "fill": "rgb(223, 234, 255)", - "stroke": "#4572d9", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(191, 213, 255)", - "lineWidth": 1 - }, - "disable": { - "fill": "rgb(250, 250, 250)", - "stroke": "rgb(224, 224, 224)", - "lineWidth": 1 - }, - "nodeSelected": { - "fill": "red", - "shadowColor": "red", - "stroke": "red", - "text-shape": { - "fill": "red", - "stroke": "red" - } - }, + "nodes": [ + { + "position": { + "x": 290, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, "fill": "#fff", - "stroke": "transparent", - "cursor": "pointer", - "radius": 10, - "overflow": "hidden", - "lineWidth": 0.5, - "shadowColor": "rgba(75,84,137,0.05)", - "shadowBlur": 12 - }, - "cron": "- corn: '0 10 * * *'", - "depth": 0 - }, { - "id": "actions/setup-node@v3-257f29d", - "name": "node", - "full_name": "actions/setup-node@v3", - "description": "", - "icon": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", - "action_node_types_id": 1, - "yaml": "", - "sort_no": 0, - "use_count": 0, - "inputs": [{ - "id": 2, - "name": "node-version", - "input_type": "select", - "is_required": false, - "value": 55 - }], - "x": 608, - "y": 357.328125, - "label": "node", - "img": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "labelCfg": { - "style": { - "fill": "transparent", - "fontSize": 0, - "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", - "overflow": "hidden", - "x": -20, - "y": 0, - "textAlign": "left", - "textBaseline": "middle" - } - }, - "style": { - "active": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10 - }, - "selected": { - "fill": "rgb(255, 255, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 4, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "fill": "rgb(223, 234, 255)", - "stroke": "#4572d9", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(191, 213, 255)", - "lineWidth": 1 - }, - "disable": { - "fill": "rgb(250, 250, 250)", - "stroke": "rgb(224, 224, 224)", - "lineWidth": 1 - }, - "nodeSelected": { - "fill": "red", - "shadowColor": "red", - "stroke": "red", - "text-shape": { - "fill": "red", - "stroke": "red" - } - }, + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, "fill": "#fff", - "stroke": "transparent", - "cursor": "pointer", - "radius": 10, - "overflow": "hidden", - "lineWidth": 0.5, - "shadowColor": "rgba(75,84,137,0.05)", - "shadowBlur": 12 - }, - "depth": 0, - "node-version": 55 - }], - "edges": [{ - "source": "on-schedule-2fcf505", - "target": "actions/setup-node@v3-257f29d", - "style": { - "active": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 1 - }, - "selected": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "stroke": "rgb(234, 234, 234)", - "lineWidth": 1 - }, - "disable": { - "stroke": "rgb(245, 245, 245)", - "lineWidth": 1 - }, - "endArrow": { - "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", - "d": 4.5, - "fill": "#CDD0DC" - }, - "cursor": "pointer", - "lineWidth": 1, - "opacity": 1, - "stroke": "#CDD0DC", - "radius": 1 - }, - "nodeStateStyle": { - "hover": { - "opacity": 1, - "stroke": "#8fe8ff" - } - }, - "labelCfg": { - "autoRotate": true, - "style": { - "fontSize": 10, - "fill": "#FFF" - } - }, - "id": "edge-0.96904321945951241716516719464", - "startPoint": { - "x": 586, - "y": 183.578125, - "anchorIndex": 1 - }, - "endPoint": { - "x": 608, - "y": 339.078125, - "anchorIndex": 0 - }, - "sourceAnchor": 1, - "targetAnchor": 0, - "type": "cubic-vertical", - "curveOffset": [0, 0], - "curvePosition": [0.5, 0.5], - "minCurveOffset": [0, 0] - }], - "combos": [] + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "on-push-b2c871f-left", + "group": "left" + }, + { + "id": "on-push-b2c871f-right", + "group": "right" + }, + { + "id": "on-push-b2c871f-top", + "group": "top" + }, + { + "id": "on-push-b2c871f-bottom", + "group": "bottom" + } + ] + }, + "id": "on-push-b2c871f", + "data": { + "id": 11, + "label": "代码push事件启动", + "name": "on-push", + "full_name": "on-push", + "description": "GitLink仓库push事件", + "icon": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c", + "action_node_types_id": 3, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "start", + "is_mutil_link": true, + "link_type": "job", + "inputs": [ + { + "id": 6, + "name": "branches", + "input_type": "input", + "description": "分支名称,多个分支英文逗号隔开,如'master,dev'", + "is_required": true + }, + { + "id": 7, + "name": "paths-ignore", + "input_type": "input", + "description": "忽略文件,多个文件英文逗号隔开,如'**.md,**.yaml'", + "is_required": false + } + ], + "x": 673, + "y": 495, + "img": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c" + }, + "zIndex": 1, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-ed9ed25-left", + "group": "left" + }, + { + "id": "job-ed9ed25-right", + "group": "right" + }, + { + "id": "job-ed9ed25-top", + "group": "top" + }, + { + "id": "job-ed9ed25-bottom", + "group": "bottom" + } + ] + }, + "id": "job-ed9ed25", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1093, + "y": 513, + "img": "" + }, + "zIndex": 2, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-3359fd2c-left", + "group": "left" + }, + { + "id": "job-3359fd2c-right", + "group": "right" + }, + { + "id": "job-3359fd2c-top", + "group": "top" + }, + { + "id": "job-3359fd2c-bottom", + "group": "bottom" + } + ] + }, + "id": "job-3359fd2c", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1493, + "y": 540, + "img": "" + }, + "zIndex": 3, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 380 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-79d5ba5d-left", + "group": "left" + }, + { + "id": "shell-79d5ba5d-right", + "group": "right" + }, + { + "id": "shell-79d5ba5d-top", + "group": "top" + }, + { + "id": "shell-79d5ba5d-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-79d5ba5d", + "data": { + "id": "shell-79d5ba5d", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 111" + } + ], + "x": 1190, + "y": 662, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 111" + }, + "zIndex": 5, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1470, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-7760b89e-left", + "group": "left" + }, + { + "id": "job-7760b89e-right", + "group": "right" + }, + { + "id": "job-7760b89e-top", + "group": "top" + }, + { + "id": "job-7760b89e-bottom", + "group": "bottom" + } + ] + }, + "id": "job-7760b89e", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1909, + "y": 552, + "img": "" + }, + "zIndex": 4, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 370 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-dd97c50-left", + "group": "left" + }, + { + "id": "shell-dd97c50-right", + "group": "right" + }, + { + "id": "shell-dd97c50-top", + "group": "top" + }, + { + "id": "shell-dd97c50-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-dd97c50", + "data": { + "id": "shell-dd97c50", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 444" + } + ], + "x": 1572, + "y": 725, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 444" + }, + "zIndex": 7, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 560 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-799aadee-left", + "group": "left" + }, + { + "id": "shell-799aadee-right", + "group": "right" + }, + { + "id": "shell-799aadee-top", + "group": "top" + }, + { + "id": "shell-799aadee-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-799aadee", + "data": { + "id": "shell-799aadee", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 222" + } + ], + "x": 1190, + "y": 922, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 222" + }, + "zIndex": 6, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1470, + "y": 370 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-1766a765-left", + "group": "left" + }, + { + "id": "shell-1766a765-right", + "group": "right" + }, + { + "id": "shell-1766a765-top", + "group": "top" + }, + { + "id": "shell-1766a765-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-1766a765", + "data": { + "id": "shell-1766a765", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 666" + } + ], + "x": 1986, + "y": 702, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 666" + }, + "zIndex": 9, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 550 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-4e09400-left", + "group": "left" + }, + { + "id": "shell-4e09400-right", + "group": "right" + }, + { + "id": "shell-4e09400-top", + "group": "top" + }, + { + "id": "shell-4e09400-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-4e09400", + "data": { + "id": "shell-4e09400", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 555" + } + ], + "x": 1577, + "y": 904, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 555" + }, + "zIndex": 8, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 760 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-5cec9ec-left", + "group": "left" + }, + { + "id": "shell-5cec9ec-right", + "group": "right" + }, + { + "id": "shell-5cec9ec-top", + "group": "top" + }, + { + "id": "shell-5cec9ec-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-5cec9ec", + "data": { + "id": "shell-5cec9ec", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 333" + } + ], + "x": 1189, + "y": 1082, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 333" + }, + "zIndex": 10, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + } + ], + "edges": [ + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "9cd9fab0-875a-4ddc-9d32-06fb5abcd986", + "zIndex": -1, + "source": { + "cell": "on-push-b2c871f", + "port": "on-push-b2c871f-right" + }, + "target": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "32fee66b-377e-49a6-9f5c-b6a7cb78b4f0", + "zIndex": -1, + "source": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-right" + }, + "target": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "84b37c54-b347-4ecb-8e7d-f338bb83c503", + "zIndex": -1, + "source": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-right" + }, + "target": { + "cell": "job-7760b89e", + "port": "job-7760b89e-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "1703563e-2233-4d23-89ec-ed61f4243791", + "zIndex": -1, + "source": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-bottom" + }, + "target": { + "cell": "shell-79d5ba5d", + "port": "shell-79d5ba5d-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "0be52bf9-8be4-43a9-aaca-1632eaf450ce", + "zIndex": -1, + "source": { + "cell": "shell-79d5ba5d", + "port": "shell-79d5ba5d-bottom" + }, + "target": { + "cell": "shell-799aadee", + "port": "shell-799aadee-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "5b9800bd-5486-4b30-9142-49e6c5a2f78b", + "zIndex": -1, + "source": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-bottom" + }, + "target": { + "cell": "shell-dd97c50", + "port": "shell-dd97c50-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "0b01ccf2-0ac9-48d5-a5d1-34a4ccc3f1f7", + "zIndex": -1, + "source": { + "cell": "shell-dd97c50", + "port": "shell-dd97c50-bottom" + }, + "target": { + "cell": "shell-4e09400", + "port": "shell-4e09400-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "c10ada7b-ada5-4970-b05d-ea31b97c1408", + "zIndex": -1, + "source": { + "cell": "job-7760b89e", + "port": "job-7760b89e-bottom" + }, + "target": { + "cell": "shell-1766a765", + "port": "shell-1766a765-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "78909862-8e2a-4750-8b5c-c621a7c327ba", + "zIndex": -1, + "source": { + "cell": "shell-799aadee", + "port": "shell-799aadee-bottom" + }, + "target": { + "cell": "shell-5cec9ec", + "port": "shell-5cec9ec-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + } + ] } end + end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 290d302bd..8d2620d06 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -17,13 +17,17 @@ # created_at :datetime not null # updated_at :datetime not null # label :string(255) +# node_type :string(255) +# is_mutil_link :boolean +# link_type :string(255) # # Indexes # -# index_action_nodes_on_action_node_types_id (action_node_types_id) -# index_action_nodes_on_user_id (user_id) +# by_name (name) +# index_action_nodes_on_action_types_id (action_node_types_id) +# index_action_nodes_on_user_id (user_id) # -# node_type 0: 触发器 1: 任务作业, 2: 步骤 + class Action::Node < ApplicationRecord self.table_name = 'action_nodes' default_scope { order(sort_no: :asc) } @@ -34,7 +38,7 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true - attr_accessor :cust_name, :run_values, :input_values, :next_step_nodes + attr_accessor :cust_name, :run_values, :input_values, :sub_nodes validates :name, presence: { message: "不能为空" } validates :full_name, length: { maximum: 200, too_long: "不能超过200个字符" } diff --git a/app/views/api/v1/projects/pipelines/_jobs.yaml.erb b/app/views/api/v1/projects/pipelines/_jobs.yaml.erb new file mode 100644 index 000000000..4f54cdc0a --- /dev/null +++ b/app/views/api/v1/projects/pipelines/_jobs.yaml.erb @@ -0,0 +1,29 @@ +jobs: +<%@job_nodes.each_with_index do |job,index| %> + job<%=index + 1 %>: + name: "<%=job.label || job.name %>" + # 运行环境,这里就是上面定义的多个 os + runs-on: 'ubuntu-latest' + <% if index >0 %> + needs: job<%=index %> + <% end %> + steps: + <%job.sub_nodes.each do |node| %> + - name: <%=node.label || node.name %> + <% if node.name !="shell" %> + uses: <%=node.full_name %> + <% end %> + <%if node.input_values.present? %> + with: + <% node.input_values.each_key do |key| %> + <%=key %>: '<%=node.input_values[key] %>' + <%end %> + <%end %> + <%if node.run_values.present? %> + <% node.run_values.each_key do |key| %> + <%=key %>: | + <%=node.run_values[key] %> + <%end %> + <%end %> + <% end %> +<%end %> \ No newline at end of file diff --git a/app/views/api/v1/projects/pipelines/_test_job.yaml.erb b/app/views/api/v1/projects/pipelines/_test_job.yaml.erb new file mode 100644 index 000000000..f9b905e9e --- /dev/null +++ b/app/views/api/v1/projects/pipelines/_test_job.yaml.erb @@ -0,0 +1,51 @@ +# steps: + # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用 + - name: Checkout codes + uses: actions/checkout@v3 + - name: Install Java and Maven + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + # 设置jdk环境 + - name: download latest temurin JDK + id: download_latest_jdk + env: + HTTPS_PROXY: http://172.20.32.253:3128 + HTTP_PROXY: http://172.20.32.253:3128 + #run: curl -o https://testgitea2.trustie.net/xxq250/licensee-identify-api-sss/raw/branch/master/openlogic-openjdk-11.0.22+7-linux-x64.tar.gz + run: wget -O $RUNNER_TEMP/java_package.tar.gz "http://172.20.32.202:10082/xxq250/licensee-identify-api-sss/raw/branch/master/OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz" + - uses: actions/setup-java@v4 + with: + distribution: 'jdkfile' + jdkFile: ${{ runner.temp }}/java_package.tar.gz + java-version: '11.0.0' + architecture: x64 + mvn-toolchain-vendor: 'Oracle' + # 设置maven 仓库缓存 避免每次构建时都重新下载依赖 + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Test java version + run: java -version + - name: Set up Maven + uses: stCarolas/setup-maven@v5 + with: + maven-version: 3.8.2 + - name: Setup Maven mirrors + uses: s4u/maven-settings-action@v3.0.0 + with: + mirrors: '[{"id": "alimaven", "name": "aliyun maven", "mirrorOf": "central", "url": "http://172.20.32.181:30005/repository/aliyun-maven/"}]' + - name: env show + run: env + - name: cat maven-settings.xml + run: cat /root/.m2/settings.xml + - name: Test with Maven + run: mvn clean test -B -U + env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 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 cbe7a8333..aa170b071 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -1,7 +1,4 @@ -# action name -name: <%=@pipeline_name %> - -# 什么时候触发这个workflow +name: "<%=@pipeline_name %>" on: <%@on_nodes.each do |node| %> <%if node.name.to_s.include?("on-push") %> @@ -39,16 +36,18 @@ on: <% end %> jobs: - job1: - # 运行环境 +<%@job_nodes.each_with_index do |job,index| %> + job<%=index %>: + name: "<%=job.label || job.name %>" + # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' steps: - <%@steps_nodes.each do |node| %> + <%job.sub_nodes.each do |node| %> - name: <%=node.label || node.name %> - <% if node.name !="shell" %> + <% if node.name !="shell" %> uses: <%=node.full_name %> - <% end %> - <%if node.input_values.present? %> + <% end %> + <%if node.input_values.present? %> with: <% node.input_values.each_key do |key| %> <%=key %>: '<%=node.input_values[key] %>' @@ -56,7 +55,9 @@ jobs: <%end %> <%if node.run_values.present? %> <% node.run_values.each_key do |key| %> - <%=key %>: '<%=node.run_values[key] %>' + <%=key %>: | + <%=node.run_values[key] %> <%end %> <%end %> <% end %> +<%end %> diff --git a/app/views/api/v1/projects/pipelines/test.yaml.erb b/app/views/api/v1/projects/pipelines/test.yaml.erb index 3ec890230..0411ba6cd 100644 --- a/app/views/api/v1/projects/pipelines/test.yaml.erb +++ b/app/views/api/v1/projects/pipelines/test.yaml.erb @@ -1,22 +1,20 @@ -name: Check dist<%= @name %> - # action name name: Test with Junit # 什么时候触发这个workflow on: # push 到master分之的时候 这里可以指定多个 - #push: - # branches: - # - master -# paths-ignore: -# - '**.md' + push: + branches: + - master + paths-ignore: + - '**.md' # pull request 到master分之的时候, 这里可以指定多个 - #pull_request: - # branches: - # - master -# paths-ignore: -# - '**.md' + pull_request: + branches: + - master + paths-ignore: + - '**.md' # 定时调度执行 schedule: - cron: '26 10,11 * * *' @@ -35,16 +33,15 @@ jobs: os: [ 'ubuntu-latest' ] # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' - steps: # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用 - name: Checkout codes uses: actions/checkout@v3 - #- name: Install Java and Maven - # uses: actions/setup-java@v3 - # with: - # java-version: '11' - # distribution: 'temurin' + - name: Install Java and Maven + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' # 设置jdk环境 - name: download latest temurin JDK id: download_latest_jdk diff --git a/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb b/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb new file mode 100644 index 000000000..14ac79a4d --- /dev/null +++ b/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb @@ -0,0 +1,26 @@ +# action name +name: Test with Junit + +# 什么时候触发这个workflow +on: + # push 到master分之的时候 这里可以指定多个 + push: + branches: + - master + paths-ignore: + - '**.md' + # pull request 到master分之的时候, 这里可以指定多个 + pull_request: + branches: + - master + paths-ignore: + - '**.md' + # 定时调度执行 + schedule: + - cron: '26 10,11 * * *' +env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 + +# 一个workflow可以由多个job组成,多个job可以并行运行 +<%= render(partial: 'api/v1/projects/pipelines/jobs') %> diff --git a/config/routes/api.rb b/config/routes/api.rb index 4aaa4beab..a1596d485 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -165,6 +165,7 @@ defaults format: :json do resources :pipelines do post :build_yaml, on: :collection post :save_yaml, on: :collection + get :test_yaml, on: :collection end resources :pulls, module: 'pulls' do member do From 6142f483ca70a9a87676f226af87f4c6df4c66f6 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:14:04 +0800 Subject: [PATCH 10/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E6=96=B0?= 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 8e92a74e4..8d8f7695b 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -39,7 +39,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.json = params[:pipeline_json].to_json - pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + 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 a6a05b69d123475007fa261c3495d49737f0b83e Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 6 Dec 2024 11:20:53 +0800 Subject: [PATCH 11/56] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 687fa986e..600cf089e 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -243,14 +243,14 @@ class Api::Pm::IssuesController < Api::Pm::BaseController belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id)) full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) - compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) + compare_link_issues_ids = (children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)) - full_link_issues_ids i = compare_link_issues_ids.count while i > 0 do children_issues = Issue.where(root_id: compare_link_issues_ids) linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id)) belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id)) - compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) + compare_link_issues_ids = (children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)) - full_link_issues_ids full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids i = compare_link_issues_ids.count end From b8de8a1d3b28d03366276cb3d424b85c7217dfd9 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:25:01 +0800 Subject: [PATCH 12/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E5=90=AF=E5=8A=A8=E8=8A=82=E7=82=B9?= 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 8d8f7695b..f73626e1e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -165,9 +165,9 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_nodes(params_nodes) steps_nodes = [] params_nodes.each do |input_node| - node = Action::Node.find_by(name: input_node["name"]) + node = Action::Node.find_by(name: input_node["data"]["name"]) next if node.blank? - node.label = input_node["label"] if input_node["label"].present? + node.label = input_node["data"]["label"] if input_node["data"]["label"].present? run_values = {} input_values = {} if input_node["inputs"].present? From 3ba6259d9f016be71cb6047841edefec194ebacd Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:28:05 +0800 Subject: [PATCH 13/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E6=8F=90=E4=BA=A4=E4=BF=A1=E6=81=AF?= 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 f73626e1e..493fb6e84 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -153,7 +153,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController branch: @pipeline.branch, new_branch: @pipeline.branch, content: opt == "create" ? Base64.encode64(@pipeline.yaml).gsub(/\n/, '') : @pipeline.yaml, - message: "#{opt} pipeline", + message: opt == "create" ? "创建流水线:#{@pipeline.pipeline_name}" : "修改流水线:#{@pipeline.pipeline_name}", committer: { email: current_user.mail, name: current_user.login From c038979732d16accc8eaf28cd25d8754247bad72 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 6 Dec 2024 11:31:58 +0800 Subject: [PATCH 14/56] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=85=B3=E8=81=94=E6=9F=A5=E8=AF=A2=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 600cf089e..7ec79b5e5 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -243,7 +243,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id)) full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) - compare_link_issues_ids = (children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)) - full_link_issues_ids + compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) i = compare_link_issues_ids.count while i > 0 do children_issues = Issue.where(root_id: compare_link_issues_ids) From 6a0bec2d3abdd51e45c067f1a732caa651bd4bc8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:33:35 +0800 Subject: [PATCH 15/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E5=90=AF=E5=8A=A8=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 493fb6e84..e080fdcdc 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -115,6 +115,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController job_nodes = pipeline_json["nodes"].select { |node| node["data"]["name"].to_s.include?("job") } on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["data"]["name"]) } @on_nodes = build_nodes(on_nodes) + Rails.logger.info "111=========================#{@on_nodes}" @job_nodes = [] job_nodes.each do |job| node = Action::Node.find_by(name: job["data"]["name"]) @@ -127,6 +128,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController get_all_child_nodes(node, next_step_node) if next_step_node.present? @job_nodes.push(node) end + Rails.logger.info "222=========================#{@job_nodes}" yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) pipeline_yaml = yaml.gsub(/^\s*\n/, "") Rails.logger.info "=========================" @@ -172,10 +174,10 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController input_values = {} if input_node["inputs"].present? input_node["inputs"].each do |input| - if input[:name].to_s.gsub("--", "") == "run" - run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) + if input["name"].to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) else - input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) + input_values = input_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) end end node.run_values = run_values From a5e6594a37fa658f3d6bb911d57a6d793f32ed0b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:36:29 +0800 Subject: [PATCH 16/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E5=90=AF=E5=8A=A8=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=A9=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 2 -- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index e080fdcdc..66830d13c 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -115,7 +115,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController job_nodes = pipeline_json["nodes"].select { |node| node["data"]["name"].to_s.include?("job") } on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["data"]["name"]) } @on_nodes = build_nodes(on_nodes) - Rails.logger.info "111=========================#{@on_nodes}" @job_nodes = [] job_nodes.each do |job| node = Action::Node.find_by(name: job["data"]["name"]) @@ -128,7 +127,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController get_all_child_nodes(node, next_step_node) if next_step_node.present? @job_nodes.push(node) end - Rails.logger.info "222=========================#{@job_nodes}" yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) pipeline_yaml = yaml.gsub(/^\s*\n/, "") Rails.logger.info "=========================" 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 aa170b071..ffd8ddf00 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -1,7 +1,7 @@ name: "<%=@pipeline_name %>" on: <%@on_nodes.each do |node| %> - <%if node.name.to_s.include?("on-push") %> + <%if node.name.to_s.include?("on-push") && node.input_values.present? %> push: <% node.input_values.each_key do |key| %> <%=key %>: @@ -14,7 +14,7 @@ on: <% end %> <% end %> <% end %> - <%if node.name.to_s.include?("on-pull_request") %> + <%if node.name.to_s.include?("on-pull_request") && node.input_values.present? %> pull_request: <% node.input_values.each_key do |key| %> <%=key %>: @@ -27,7 +27,7 @@ on: <% end %> <% end %> <% end %> - <%if node.name.to_s.include?("on-schedule") %> + <%if node.name.to_s.include?("on-schedule") && node.input_values.present? %> schedule: <% node.input_values.each_key do |key| %> - <%=key %>: "<%=node.input_values[key] %>" From d87fe501c4ca8a63342771f77b004cb4901e0173 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 6 Dec 2024 11:47:37 +0800 Subject: [PATCH 17/56] =?UTF-8?q?fixed=20=E5=9B=BE=E5=BD=A2=E5=8C=96?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=A2=9E=E5=8A=A0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E6=B5=81=E7=A8=8B-=E5=90=AF=E5=8A=A8=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 25 +++---------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 66830d13c..68f15d152 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -92,24 +92,6 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank? end - def build_pipeline_yaml(pipeline_name, pipeline_json) - if pipeline_json.present? && pipeline_json.present? - @pipeline_name = pipeline_name - params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } - on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } - @on_nodes = build_nodes(on_nodes) - @steps_nodes = build_nodes(params_nodes) - yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) - # 删除空行内容 - pipeline_yaml = yaml.gsub(/^\s*\n/, "") - else - pipeline_yaml = params[:pipeline_yaml] - end - Rails.logger.info "pipeline_yaml=========================" - Rails.logger.info pipeline_yaml - pipeline_yaml - end - def build_pipeline_yaml_new(pipeline_name, pipeline_json) @pipeline_name = pipeline_name job_nodes = pipeline_json["nodes"].select { |node| node["data"]["name"].to_s.include?("job") } @@ -170,8 +152,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node.label = input_node["data"]["label"] if input_node["data"]["label"].present? run_values = {} input_values = {} - if input_node["inputs"].present? - input_node["inputs"].each do |input| + if input_node["data"]["inputs"].present? + input_node["data"]["inputs"].each do |input| if input["name"].to_s.gsub("--", "") == "run" run_values = run_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) else @@ -331,7 +313,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "name": "branches", "input_type": "input", "description": "分支名称,多个分支英文逗号隔开,如'master,dev'", - "is_required": true + "is_required": true, + "value": "master" }, { "id": 7, From 35c0ac4eec7b7ee0aed05e5c3e0991a82633a003 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 9 Dec 2024 11:24:52 +0800 Subject: [PATCH 18/56] =?UTF-8?q?fixed=20=E5=8F=AF=E7=94=A8=E6=B5=81?= =?UTF-8?q?=E6=B0=B4=E7=BA=BF=E4=BB=93=E5=BA=93actived=E5=B1=8F=E8=94=BD?= =?UTF-8?q?=E9=95=9C=E5=83=8F=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/organizations/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/organizations/projects_controller.rb b/app/controllers/organizations/projects_controller.rb index e0525eaff..380f32e48 100644 --- a/app/controllers/organizations/projects_controller.rb +++ b/app/controllers/organizations/projects_controller.rb @@ -12,7 +12,7 @@ class Organizations::ProjectsController < Organizations::BaseController keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('') @projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present? @projects = @projects.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present? - @projects = @projects.where("gpid is not null") if params[:actived].present? + @projects = @projects.where(project_type: ['mirror', 'common']).where("gpid is not null") if params[:actived].present? @projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present? @projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}") @projects = paginate(@projects) From 28f3395b0566f2669271f85d098896b139271e17 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 09:36:49 +0800 Subject: [PATCH 19/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B1=9E=E6=80=A7=EF=BC=8C=E8=8A=82=E7=82=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=B8=A6=E4=B8=8Aid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 14 +++++++++++--- .../api/v1/projects/pipelines_controller.rb | 3 +++ app/models/action/node.rb | 2 +- app/views/action/nodes/_form.html.erb | 18 +++++++++++++++++- app/views/action/nodes/show.json.jbuilder | 2 +- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index ebccf8efe..2664ff95a 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -13,6 +13,9 @@ class Action::NodesController < ApplicationController def create @node = Action::Node.new(node_params) + if params.require(:node).present? && params.require(:node)[:link_type_array].present? + @node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",") + end respond_to do |format| if @node.save format.html { redirect_to action_nodes_path, notice: '创建成功.' } @@ -33,10 +36,15 @@ class Action::NodesController < ApplicationController end def edit - + if @node.link_type.present? + @node.link_type_array = @node.link_type.to_s.split(",") + end end def update + if params.require(:node).present? && params.require(:node)[:link_type_array].present? + @node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",") + end @node.update(node_params) respond_to do |format| format.html { redirect_to action_nodes_path, notice: '更新成功.' } @@ -62,10 +70,10 @@ class Action::NodesController < ApplicationController def node_params if params.require(:action_node) params.require(:action_node).permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, - :is_local, :local_url, :yaml, :sort_no, :type, :is_mutil_link, :link_type) + :is_local, :local_url, :yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array) else params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, - :yaml, :sort_no, :type, :is_mutil_link, :link_type) + :yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array) end end end diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 68f15d152..532b33d7e 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -101,6 +101,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController job_nodes.each do |job| node = Action::Node.find_by(name: job["data"]["name"]) node.label = job["data"]["label"] if job["data"]["label"].present? + node.node_id = job["data"]["id"] if job["data"]["id"].present? next if node.blank? next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } @@ -150,6 +151,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node = Action::Node.find_by(name: input_node["data"]["name"]) next if node.blank? node.label = input_node["data"]["label"] if input_node["data"]["label"].present? + node.node_id = input_node["data"]["id"] if input_node["data"]["id"].present? run_values = {} input_values = {} if input_node["data"]["inputs"].present? @@ -182,6 +184,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node = Action::Node.find_by(name: input_node["data"]["name"]) return nil if node.blank? node.label = input_node["data"]["label"] if input_node["data"]["label"].present? + node.node_id = input_node["data"]["id"] if input_node["data"]["id"].present? run_values = {} input_values = {} if input_node["data"]["inputs"].present? diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 8d2620d06..b92837b7b 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 + attr_accessor :cust_name, :run_values, :input_values, :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/action/nodes/_form.html.erb b/app/views/action/nodes/_form.html.erb index 0ecee56ed..7b21bb20f 100644 --- a/app/views/action/nodes/_form.html.erb +++ b/app/views/action/nodes/_form.html.erb @@ -11,7 +11,7 @@ <%# end %>
- + <%= form.select :action_node_types_id, options_for_select(Action::NodeType.all.map { |key| [key.name, key.id]}, node.action_node_types_id), {}, class: "form-control" %>
@@ -26,6 +26,22 @@ <%= form.label :full_name, "节点全名" %> <%= form.text_field :full_name %>
+
+ + <% node_type_options = [['action节点', 'step' ], ['启动', 'start' ], ['任务', 'job']] %> + <%= form.select :node_type, options_for_select(node_type_options, node.node_type), {}, class: "form-control" %> +
+
+ + <% is_mutil_link_options = [['否', false ], ['是', true]] %> + <%= form.select :is_mutil_link, options_for_select(is_mutil_link_options, node.is_mutil_link), {}, class: "form-control" %> +
+
+ + <% link_type_options = [Action::Node.new(name: "job", label: "任务"), Action::Node.new(name: "step", label: "action节点")] %> + <%= collection_check_boxes(:node, :link_type_array, link_type_options, :name, :label) %> +
+
<%= form.label :description, "描述" %> diff --git a/app/views/action/nodes/show.json.jbuilder b/app/views/action/nodes/show.json.jbuilder index 64548544d..4bf73bef3 100644 --- a/app/views/action/nodes/show.json.jbuilder +++ b/app/views/action/nodes/show.json.jbuilder @@ -1,7 +1,7 @@ json.status 0 json.message "success" -json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count +json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count, :node_type, :is_mutil_link, :link_type json.inputs @node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: @node } end \ No newline at end of file From 848afa3ec4008afab35bb7aaceae22ee1b742c0c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 09:36:58 +0800 Subject: [PATCH 20/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B1=9E=E6=80=A7=EF=BC=8C=E8=8A=82=E7=82=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=B8=A6=E4=B8=8Aid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 ffd8ddf00..48fe976af 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -38,12 +38,12 @@ on: jobs: <%@job_nodes.each_with_index do |job,index| %> job<%=index %>: - name: "<%=job.label || job.name %>" + name: "<%=job.label || job.name %>[<%=job.node_id %>]" # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' steps: <%job.sub_nodes.each do |node| %> - - name: <%=node.label || node.name %> + - name: "<%=node.label || node.name %>[<%=job.node_id %>]" <% if node.name !="shell" %> uses: <%=node.full_name %> <% end %> From 944a85dbbbbafb1654854eb0ad6175f946cb08b7 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 09:40:42 +0800 Subject: [PATCH 21/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=B8=A6=E4=B8=8Aid,=E6=96=B9=E4=BE=BF=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E7=8A=B6=E6=80=81=E8=AF=BB=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 48fe976af..809daa0c6 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -43,7 +43,7 @@ jobs: runs-on: 'ubuntu-latest' steps: <%job.sub_nodes.each do |node| %> - - name: "<%=node.label || node.name %>[<%=job.node_id %>]" + - name: "<%=node.label || node.name %>[<%=node.node_id %>]" <% if node.name !="shell" %> uses: <%=node.full_name %> <% end %> From 46796095cf5dfcdd2d40de394cfa386042ffe048 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 10:04:37 +0800 Subject: [PATCH 22/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=B8=A6=E4=B8=8Aid,=E6=96=B9=E4=BE=BF=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E7=8A=B6=E6=80=81=E8=AF=BB=E5=8F=96=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 201 ++++++++++++++++-- 1 file changed, 189 insertions(+), 12 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 532b33d7e..e4bf9dfc6 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -100,14 +100,15 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @job_nodes = [] job_nodes.each do |job| node = Action::Node.find_by(name: job["data"]["name"]) + next if node.blank? node.label = job["data"]["label"] if job["data"]["label"].present? node.node_id = job["data"]["id"] if job["data"]["id"].present? - next if node.blank? next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["data"]["id"]) && !node["data"]["name"].to_s.include?("job") }&.first node.sub_nodes = [] get_all_child_nodes(node, next_step_node) if next_step_node.present? + Rails.logger.info "node.sub_nodes=========================#{node.sub_nodes}" @job_nodes.push(node) end yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -297,7 +298,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController }, "id": "on-push-b2c871f", "data": { - "id": 11, + "id": "on-push-b2c871f", "label": "代码push事件启动", "name": "on-push", "full_name": "on-push", @@ -324,14 +325,18 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "name": "paths-ignore", "input_type": "input", "description": "忽略文件,多个文件英文逗号隔开,如'**.md,**.yaml'", - "is_required": false + "is_required": false, + "value": "'*.md'" } ], "x": 673, "y": 495, - "img": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c" + "img": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c", + "branches": "master", + "paths-ignore": "'*.md'" }, "zIndex": 1, + "isDelete": true, "tools": { "items": [ { @@ -437,8 +442,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController }, "id": "job-ed9ed25", "data": { - "id": 29, - "label": "任务", + "id": "job-ed9ed25", + "label": "单元测试", "name": "job", "full_name": "", "description": "允许并行多个任务", @@ -456,6 +461,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "img": "" }, "zIndex": 2, + "isDelete": true, "tools": { "items": [ { @@ -561,8 +567,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController }, "id": "job-3359fd2c", "data": { - "id": 29, - "label": "任务", + "id": "job-3359fd2c", + "label": "压力测试", "name": "job", "full_name": "", "description": "允许并行多个任务", @@ -580,6 +586,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "img": "" }, "zIndex": 3, + "isDelete": true, "tools": { "items": [ { @@ -713,6 +720,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 111" }, "zIndex": 5, + "isDelete": true, "tools": { "items": [ { @@ -818,8 +826,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController }, "id": "job-7760b89e", "data": { - "id": 29, - "label": "任务", + "id": "job-7760b89e", + "label": "功能测试", "name": "job", "full_name": "", "description": "允许并行多个任务", @@ -837,6 +845,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "img": "" }, "zIndex": 4, + "isDelete": true, "tools": { "items": [ { @@ -970,6 +979,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 444" }, "zIndex": 7, + "isDelete": true, "tools": { "items": [ { @@ -1076,7 +1086,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "id": "shell-799aadee", "data": { "id": "shell-799aadee", - "label": "运行Shell脚本", + "label": "唱首歌", "name": "shell", "full_name": "shell", "description": "", @@ -1103,6 +1113,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 222" }, "zIndex": 6, + "isDelete": true, "tools": { "items": [ { @@ -1236,6 +1247,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 666" }, "zIndex": 9, + "isDelete": true, "tools": { "items": [ { @@ -1342,7 +1354,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "id": "shell-4e09400", "data": { "id": "shell-4e09400", - "label": "运行Shell脚本", + "label": "测试报告浏览", "name": "shell", "full_name": "shell", "description": "", @@ -1369,6 +1381,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 555" }, "zIndex": 8, + "isDelete": true, "tools": { "items": [ { @@ -1502,6 +1515,132 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController "run": "echo 333" }, "zIndex": 10, + "isDelete": true, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1470, + "y": 560 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "checkout-gitlink-f6e67fe-left", + "group": "left" + }, + { + "id": "checkout-gitlink-f6e67fe-right", + "group": "right" + }, + { + "id": "checkout-gitlink-f6e67fe-top", + "group": "top" + }, + { + "id": "checkout-gitlink-f6e67fe-bottom", + "group": "bottom" + } + ] + }, + "id": "checkout-gitlink-f6e67fe", + "data": { + "id": "checkout-gitlink-f6e67fe", + "label": "加速版-克隆代码", + "name": "checkout-gitlink", + "full_name": "https://gitlink.org.cn/actions/checkout@v4", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c", + "action_node_types_id": 6, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [], + "x": 2017, + "y": 887, + "img": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c" + }, + "zIndex": 11, + "isDelete": true, "tools": { "items": [ { @@ -1857,6 +1996,44 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController } ] } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "cf60eaaf-3503-4c6e-96d8-ca8d273b107b", + "zIndex": -1, + "source": { + "cell": "shell-1766a765", + "port": "shell-1766a765-bottom" + }, + "target": { + "cell": "checkout-gitlink-f6e67fe", + "port": "checkout-gitlink-f6e67fe-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } } ] } From 2792c172d57e1fd2ad3fac5361dc049ac3ccb33f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 10:20:50 +0800 Subject: [PATCH 23/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=B8=A6=E4=B8=8Aid,=E6=96=B9=E4=BE=BF=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E4=B8=AD=E7=8A=B6=E6=80=81=E8=AF=BB=E5=8F=96=EF=BC=8C?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E8=AF=BB=E5=8F=96=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/pipelines_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index e4bf9dfc6..83926aed1 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -102,13 +102,12 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node = Action::Node.find_by(name: job["data"]["name"]) next if node.blank? node.label = job["data"]["label"] if job["data"]["label"].present? - node.node_id = job["data"]["id"] if job["data"]["id"].present? + node.node_id = job["id"] if job["id"].present? next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } - next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["data"]["id"]) && !node["data"]["name"].to_s.include?("job") }&.first + next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first node.sub_nodes = [] get_all_child_nodes(node, next_step_node) if next_step_node.present? - Rails.logger.info "node.sub_nodes=========================#{node.sub_nodes}" @job_nodes.push(node) end yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -152,7 +151,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node = Action::Node.find_by(name: input_node["data"]["name"]) next if node.blank? node.label = input_node["data"]["label"] if input_node["data"]["label"].present? - node.node_id = input_node["data"]["id"] if input_node["data"]["id"].present? + node.node_id = input_node["id"] if input_node["id"].present? run_values = {} input_values = {} if input_node["data"]["inputs"].present? @@ -185,7 +184,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController node = Action::Node.find_by(name: input_node["data"]["name"]) return nil if node.blank? node.label = input_node["data"]["label"] if input_node["data"]["label"].present? - node.node_id = input_node["data"]["id"] if input_node["data"]["id"].present? + node.node_id = input_node["id"] if input_node["id"].present? run_values = {} input_values = {} if input_node["data"]["inputs"].present? From e5c030270b4f934228736ff5219c880b6cfd9de5 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 10:31:12 +0800 Subject: [PATCH 24/56] =?UTF-8?q?fixed=20job=E9=A1=BA=E5=BA=8F=E6=89=A7?= =?UTF-8?q?=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 809daa0c6..75459273d 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -37,10 +37,13 @@ on: jobs: <%@job_nodes.each_with_index do |job,index| %> - job<%=index %>: + job<%=index + 1 %>: name: "<%=job.label || job.name %>[<%=job.node_id %>]" # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' + <% if index >0 %> + needs: job<%=index %> + <% end %> steps: <%job.sub_nodes.each do |node| %> - name: "<%=node.label || node.name %>[<%=node.node_id %>]" From f9cf1e3a136c2f4224e36e318b1d8b43c2743d46 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Dec 2024 11:08:37 +0800 Subject: [PATCH 25/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8F=90=E5=8F=96=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/pipelines_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 83926aed1..71d588491 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -103,11 +103,11 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController next if node.blank? node.label = job["data"]["label"] if job["data"]["label"].present? node.node_id = job["id"] if job["id"].present? - next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } + 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 = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first + next_step_node = pipeline_json["nodes"].select { |node| node_ids.include?(node["id"]) && !node["data"]["name"].to_s.include?("job") }&.first node.sub_nodes = [] - get_all_child_nodes(node, next_step_node) if next_step_node.present? + get_all_child_nodes(pipeline_json, node, next_step_node) if next_step_node.present? @job_nodes.push(node) end yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -170,13 +170,13 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController steps_nodes end - def get_all_child_nodes(job_node, target_node) + def get_all_child_nodes(pipeline_json, job_node, target_node) job_node.sub_nodes.push(get_node_info(target_node)) - target_edge = JSON.parse(demo2.to_json)["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first + target_edge = pipeline_json["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first # 判断是否有子节点 if target_edge.present? - next_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first - get_all_child_nodes(job_node, next_node) + next_node = pipeline_json["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first + get_all_child_nodes(pipeline_json, job_node, next_node) end end From 9cdc593763b702c0bd24114e142767c6ee5b94eb Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 10 Dec 2024 17:20:08 +0800 Subject: [PATCH 26/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E5=8F=B0=E9=83=A8=E5=88=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E5=85=B3=E8=81=94=E5=B7=A5=E4=BD=9C=E9=A1=B9?= =?UTF-8?q?=E5=8F=98=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/dashboards_controller.rb | 123 ++++++++++++++++++ app/controllers/api/pm/issues_controller.rb | 10 +- app/models/issue.rb | 1 + .../api/pm/dashboards/my_issues.json.jbuilder | 8 ++ .../api/pm/dashboards/todo.json.jbuilder | 5 + config/routes/api.rb | 12 ++ 6 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 app/controllers/api/pm/dashboards_controller.rb create mode 100644 app/views/api/pm/dashboards/my_issues.json.jbuilder create mode 100644 app/views/api/pm/dashboards/todo.json.jbuilder diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb new file mode 100644 index 000000000..25ebcc6d1 --- /dev/null +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -0,0 +1,123 @@ +class Api::Pm::DashboardsController < Api::Pm::BaseController + before_action :require_login + def index + end + + def todo + return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? + pm_project_ids = params[:pm_project_ids].split(",") rescue [] + date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today + @issues = Issue.where("start_date < ? and due_date > ?", date, date) + @issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}) + @issues = kaminari_paginate(@issues.distinct.pm_includes) + end + + def my_issues + return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? + pm_project_ids = params[:pm_project_ids].split(",") rescue [] + @all_issues = Issue.where(pm_project_id: pm_project_ids) + @issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id}) + @issues = @issues.where(pm_issue_type: params[:pm_issue_type].to_i) if params[:pm_issue_type].present? + + @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 + @my_assign_tasks_count = @all_issues.where(pm_issue_type: 2).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size + @my_assign_bugs_count = @all_issues.where(pm_issue_type: 3).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size + end + + def my_pm_projects + return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank? + @all_issues = Issue.where(pm_project_id: params[:pm_project_id]) + time_now = Time.now + @last_week_create_issues_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 7.days, time_now).size + @before_last_week_create_issue_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 14.days, time_now - 7.days).size + @compare_last_week_create_issues = @before_last_week_create_issue_count.zero? ? 0 :(@last_week_create_issues_count - @before_last_week_create_issue_count).to_f / @before_last_week_create_issue_count rescue 0 + @last_week_close_issues_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size + @before_last_week_close_issue_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 14.days, time_now - 7.days).size + @compare_last_week_close_issues = @before_last_week_close_issue_count.zero? ? 0 :(@last_week_close_issues_count - @before_last_week_close_issue_count).to_f / @before_last_week_close_issue_count rescue 0 + @all_requirement_issues_count = @all_issues.where(pm_issue_type: 1).size + @last_week_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size + @last_month_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size + @all_task_issues_count = @all_issues.where(pm_issue_type: 2).size + @last_week_close_tast_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size + @last_month_close_task_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size + @all_bug_issues_count = @all_issues.where(pm_issue_type: 3).size + @last_week_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size + @last_month_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size + + + @requirement_close_trend = [[],[]] + @task_close_trend = [[],[]] + @bug_close_trend = [[],[]] + ((time_now-29.days).to_date..time_now.to_date).to_a.each do |i| + @requirement_close_trend[0] << i.strftime("%Y.%m.%d") + @task_close_trend[0] << i.strftime("%Y.%m.%d") + @bug_close_trend[0] << i.strftime("%Y.%m.%d") + @requirement_close_trend[1] << @all_issues.where(pm_issue_type: 1, status_id: 5).where("DATE(updated_on) = ?", i).size + @task_close_trend[1] << @all_issues.where(pm_issue_type: 2, status_id: 5).where("DATE(updated_on) = ?", i).size + @bug_close_trend[1] << @all_issues.where(pm_issue_type: 3, status_id: 5).where("DATE(updated_on) = ?", i).size + end + @close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend} + + + render :json => { + last_week_close_issues_count: @last_week_close_issues_count, + before_last_week_close_issue_count: @before_last_week_close_issue_count, + compare_last_week_close_issues: @compare_last_week_close_issues, + last_week_create_issues_count: @last_week_create_issues_count, + before_last_week_create_issue_count: @before_last_week_create_issue_count, + compare_last_week_create_issues: @compare_last_week_create_issues, + all_requirement_issues_count: @all_requirement_issues_count, + last_week_close_requirement_issues_count: @last_week_close_requirement_issues_count, + last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count, + all_task_issues_count: @all_task_issues_count, + last_week_close_tast_issues_count: @last_week_close_tast_issues_count, + last_month_close_task_issues_count: @last_month_close_task_issues_count, + all_bug_issues_count: @all_bug_issues_count, + last_week_close_bug_issues_count: @last_week_close_bug_issues_count, + last_month_close_bug_issues_count: @last_month_close_bug_issues_count, + close_trend: @close_trend + } + end + + def my_projects + return render_error('请输入正确的project_id.') if params[:project_id].blank? + + @project = Project.find_by_id params[:project_id] + return render_error('请输入正确的project_id.') unless @project.present? + time_now = Time.now + + branch_tag_result = $gitea_hat_client.get_repos_branch_tag_count_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {} + languages_result = $gitea_client.get_repos_languages_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {} + + @open_pull_requests_count = @project.pull_requests.opening.size + @last_week_close_pull_requests_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 7.days, time_now).size + @last_month_close_pull_requets_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 30.days, time_now).size + + @commits_count = @project.commit_logs.size + @last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size + @last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size + + render :json => { + branch_count: branch_tag_result["branch_count"].to_i, + tag_count: branch_tag_result["tag_count"].to_i, + license_name: @project.license&.name, + open_pull_requests_count: @open_pull_requests_count, + last_week_close_pull_requests_count: @last_week_close_pull_requests_count, + last_month_close_pull_requets_count: @last_month_close_pull_requets_count, + commits_count: @commits_count, + last_week_commits_count: @last_week_commits_count, + last_month_commits_count: @last_month_commits_count, + language: hash_transform_precentagable(languages_result), + } + end + + private + def hash_transform_precentagable(hash) + total_byte_size = hash.values.sum + hash.transform_values { |v| + ActionController::Base.helpers + .number_to_percentage((v * 100.0 / total_byte_size), precision: 1) + }.select{|k,v| v != "0.0%"} + end +end \ No newline at end of file diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 7ec79b5e5..ce0981a89 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -238,7 +238,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end def link_issues - children_issues = Issue.where(root_id: @issue.id) + children_issues = @issue.pm_issue_type == 1 ? @issue.child_count > 0 ? Issue.where(id: @issue.id) : Issue.none : Issue.where(root_id: @issue.id) linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id)) belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id)) @@ -246,7 +246,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) i = compare_link_issues_ids.count while i > 0 do - children_issues = Issue.where(root_id: compare_link_issues_ids) + children_issues = Issue.where(root_id: compare_link_issues_ids).where.not(pm_issue_type: 1) linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id)) belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id)) @@ -255,9 +255,9 @@ class Api::Pm::IssuesController < Api::Pm::BaseController i = compare_link_issues_ids.count end - @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1) - @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2) - @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3) + @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1).pm_includes + @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes + @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes end private diff --git a/app/models/issue.rb b/app/models/issue.rb index 955f903e9..c28c49bb1 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -102,6 +102,7 @@ class Issue < ApplicationRecord scope :issue_issue, ->{where(issue_classify: [nil, 'issue'])} scope :issue_pull_request, ->{where(issue_classify: 'pull_request')} scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)} + scope :pm_includes, -> {includes(:project, :show_issue_tags, :issue_status, :priority, :version, :user, :show_assigners, :comment_journals, :operate_journals)} scope :closed, ->{where(status_id: 5)} scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic diff --git a/app/views/api/pm/dashboards/my_issues.json.jbuilder b/app/views/api/pm/dashboards/my_issues.json.jbuilder new file mode 100644 index 000000000..fd4193e1c --- /dev/null +++ b/app/views/api/pm/dashboards/my_issues.json.jbuilder @@ -0,0 +1,8 @@ +json.total_count @issues.total_count +json.my_assign_requirements_count @my_assign_requirements_count +json.my_assign_tasks_count @my_assign_tasks_count +json.my_assign_bugs_count @my_assign_bugs_count +json.issues @issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} +end + diff --git a/app/views/api/pm/dashboards/todo.json.jbuilder b/app/views/api/pm/dashboards/todo.json.jbuilder new file mode 100644 index 000000000..852a36390 --- /dev/null +++ b/app/views/api/pm/dashboards/todo.json.jbuilder @@ -0,0 +1,5 @@ +json.total_count @issues.total_count + +json.issues @issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} +end diff --git a/config/routes/api.rb b/config/routes/api.rb index a6fe42d86..6d652f31e 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -1,6 +1,18 @@ defaults format: :json do namespace :api do namespace :pm do + resources :dashboards,only: [:index] do + collection do + get :todo + get :my_issues + get :my_pm_projects + get :my_projects + end + end + namespace :projects do + resources :dashboards, only: [:index] do + end + end resources :issues do collection do patch :batch_update From 3b55009473a9e757a87972915ed644355af7fc12 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Dec 2024 14:43:21 +0800 Subject: [PATCH 27/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/dashboards_controller.rb | 27 ++++++++++++++----- app/controllers/api/pm/projects_controller.rb | 15 ++++++++--- app/models/journal.rb | 16 +++++++++++ .../api/pm/dashboards/my_issues.json.jbuilder | 2 ++ .../my_operate_journals.json.jbuilder | 21 +++++++++++++++ .../api/pm/dashboards/todo.json.jbuilder | 2 ++ config/routes/api.rb | 5 +--- 7 files changed, 74 insertions(+), 14 deletions(-) create mode 100644 app/views/api/pm/dashboards/my_operate_journals.json.jbuilder diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 25ebcc6d1..8acff2fe8 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -14,10 +14,11 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController def my_issues return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? + return render_error('请输入正确的pm_issue_types.') if params[:pm_issue_types].blank? pm_project_ids = params[:pm_project_ids].split(",") rescue [] - @all_issues = Issue.where(pm_project_id: pm_project_ids) + 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(pm_issue_type: params[:pm_issue_type].to_i) if params[:pm_issue_type].present? @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 @@ -36,12 +37,15 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController @before_last_week_close_issue_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 14.days, time_now - 7.days).size @compare_last_week_close_issues = @before_last_week_close_issue_count.zero? ? 0 :(@last_week_close_issues_count - @before_last_week_close_issue_count).to_f / @before_last_week_close_issue_count rescue 0 @all_requirement_issues_count = @all_issues.where(pm_issue_type: 1).size + @open_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where.not(status_id: 5).size @last_week_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size @last_month_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size @all_task_issues_count = @all_issues.where(pm_issue_type: 2).size + @open_task_issues_count = @all_issues.where(pm_issue_type: 2).where.not(status_id: 5).size @last_week_close_tast_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size @last_month_close_task_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size @all_bug_issues_count = @all_issues.where(pm_issue_type: 3).size + @open_bug_issues_count = @all_issues.where(pm_issue_type: 3).where.not(status_id: 5).size @last_week_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size @last_month_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size @@ -59,8 +63,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController end @close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend} - - render :json => { + render_ok(data={ last_week_close_issues_count: @last_week_close_issues_count, before_last_week_close_issue_count: @before_last_week_close_issue_count, compare_last_week_close_issues: @compare_last_week_close_issues, @@ -68,16 +71,19 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController before_last_week_create_issue_count: @before_last_week_create_issue_count, compare_last_week_create_issues: @compare_last_week_create_issues, all_requirement_issues_count: @all_requirement_issues_count, + open_requirement_issues_count: @open_requirement_issues_count, last_week_close_requirement_issues_count: @last_week_close_requirement_issues_count, last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count, all_task_issues_count: @all_task_issues_count, + open_task_issues_count: @open_task_issues_count, last_week_close_tast_issues_count: @last_week_close_tast_issues_count, last_month_close_task_issues_count: @last_month_close_task_issues_count, all_bug_issues_count: @all_bug_issues_count, + open_bug_issues_count: @open_bug_issues_count, last_week_close_bug_issues_count: @last_week_close_bug_issues_count, last_month_close_bug_issues_count: @last_month_close_bug_issues_count, close_trend: @close_trend - } + }) end def my_projects @@ -98,7 +104,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController @last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size @last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size - render :json => { + render_ok(data={ branch_count: branch_tag_result["branch_count"].to_i, tag_count: branch_tag_result["tag_count"].to_i, license_name: @project.license&.name, @@ -109,7 +115,14 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController last_week_commits_count: @last_week_commits_count, last_month_commits_count: @last_month_commits_count, language: hash_transform_precentagable(languages_result), - } + }) + end + + def my_operate_journals + return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank? + @journals = Journal.operate_journals.joins(:issue).where(issues: {pm_project_id: params[:pm_project_id], pm_issue_type: [1,2,3]}) + + @journals = kaminari_paginate(@journals.order(updated_on: :desc)) end private diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 8d808bf99..82b931f05 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -56,6 +56,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def statistics return tip_exception '参数错误' if params[:pm_project_id].blank? @issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type:[1, 2, 3]) + @last_week_close_issues = @issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", Time.now - 7.days, Time.now) + last_week_close_type_count_data = @last_week_close_issues.group(:pm_issue_type).count type_count_data = @issues.group(:pm_issue_type).count type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} @@ -81,17 +83,24 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController type_count_data[e] = 0 } end + if last_week_close_type_count_data.keys.size < 3 + nedd_add = [1,2,3] - last_week_close_type_count_data.keys + nedd_add.map{ |e| + last_week_close_type_count_data[e] = 0 + } + end data = { pie_chart: type_count_data, bar_chart: type_status_data, - open_data: open_data + open_data: open_data, + last_week_close_data: last_week_close_type_count_data, } render_ok(data: data) end def polyline return tip_exception '参数错误' if params[:pm_project_id].blank? - time_line = (Time.current.beginning_of_day - 6.day) .. Time.current + time_line = (Time.current.beginning_of_day - 29.day) .. Time.current @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) @due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @@ -100,7 +109,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController create_issues: {}, due_issues: {} } - 7.times do |time| + 30.times do |time| current_time = Date.current - time.day if @create_issues_count.present? data[:create_issues][current_time] = { diff --git a/app/models/journal.rb b/app/models/journal.rb index 77c806ca8..fe077ae66 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -52,6 +52,7 @@ class Journal < ApplicationRecord scope :journal_includes, ->{includes(:user, :journal_details, :attachments)} scope :parent_journals, ->{where(parent_id: nil)} scope :children_journals, lambda{|journal_id| where(parent_id: journal_id)} + scope :operate_journals, ->{where(notes: nil)} enum state: {opened: 0, resolved: 1, disabled: 2} @@ -103,6 +104,21 @@ class Journal < ApplicationRecord end end + def pm_dashboard_operate_content + content = self.pm_operate_content + if content.start_with?('创建了') + content += "#{self.issue.subject}" + else + prefix = '将' + prefix += "计划" if self.issue.pm_issue_type == 1 + prefix += "任务" if self.issue.pm_issue_type == 2 + prefix += "缺陷" if self.issue.pm_issue_type == 3 + prefix += "#{self.issue.subject}" + content = prefix + content + end + content + end + def pm_operate_content content = "#{operate_by_content}" detail = self.journal_details.take diff --git a/app/views/api/pm/dashboards/my_issues.json.jbuilder b/app/views/api/pm/dashboards/my_issues.json.jbuilder index fd4193e1c..d9ebf754a 100644 --- a/app/views/api/pm/dashboards/my_issues.json.jbuilder +++ b/app/views/api/pm/dashboards/my_issues.json.jbuilder @@ -1,3 +1,5 @@ +json.status 0 +json.message "success" json.total_count @issues.total_count json.my_assign_requirements_count @my_assign_requirements_count json.my_assign_tasks_count @my_assign_tasks_count diff --git a/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder new file mode 100644 index 000000000..76ec90f97 --- /dev/null +++ b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder @@ -0,0 +1,21 @@ +json.status 0 +json.message "success" +json.total_count @journals.total_count +json.journals @journals do |journal| + journal.associate_attachment_container + json.id journal.id + json.is_journal_detail journal.is_journal_detail? + json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") + json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") + json.user do + if journal.user.present? + json.partial! "api/v1/users/simple_user", user: journal.user + else + json.nil! + end + end + detail = journal.journal_details.take + json.operate_category journal.pm_operate_category + json.operate_content journal.is_journal_detail? ? journal.pm_dashboard_operate_content : nil + +end \ No newline at end of file diff --git a/app/views/api/pm/dashboards/todo.json.jbuilder b/app/views/api/pm/dashboards/todo.json.jbuilder index 852a36390..bea1ec07f 100644 --- a/app/views/api/pm/dashboards/todo.json.jbuilder +++ b/app/views/api/pm/dashboards/todo.json.jbuilder @@ -1,3 +1,5 @@ +json.status 0 +json.message "success" json.total_count @issues.total_count json.issues @issues.each do |issue| diff --git a/config/routes/api.rb b/config/routes/api.rb index 6d652f31e..242037e09 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -7,10 +7,7 @@ defaults format: :json do get :my_issues get :my_pm_projects get :my_projects - end - end - namespace :projects do - resources :dashboards, only: [:index] do + get :my_operate_journals end end resources :issues do From 406ceb094283a2cd0641218dd4d52cf4134f8dc0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Dec 2024 15:04:51 +0800 Subject: [PATCH 28/56] =?UTF-8?q?fix:=20=E6=9B=B4=E6=94=B9json=E7=BB=93?= =?UTF-8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/dashboards_controller.rb | 4 +-- .../api/pm/dashboards/my_issues.json.jbuilder | 17 ++++----- .../my_operate_journals.json.jbuilder | 36 ++++++++++--------- .../api/pm/dashboards/todo.json.jbuilder | 11 +++--- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 8acff2fe8..6b05c3b48 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -63,7 +63,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController end @close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend} - render_ok(data={ + render_ok(data: { last_week_close_issues_count: @last_week_close_issues_count, before_last_week_close_issue_count: @before_last_week_close_issue_count, compare_last_week_close_issues: @compare_last_week_close_issues, @@ -104,7 +104,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController @last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size @last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size - render_ok(data={ + render_ok(data: { branch_count: branch_tag_result["branch_count"].to_i, tag_count: branch_tag_result["tag_count"].to_i, license_name: @project.license&.name, diff --git a/app/views/api/pm/dashboards/my_issues.json.jbuilder b/app/views/api/pm/dashboards/my_issues.json.jbuilder index d9ebf754a..dfce9c664 100644 --- a/app/views/api/pm/dashboards/my_issues.json.jbuilder +++ b/app/views/api/pm/dashboards/my_issues.json.jbuilder @@ -1,10 +1,11 @@ json.status 0 json.message "success" -json.total_count @issues.total_count -json.my_assign_requirements_count @my_assign_requirements_count -json.my_assign_tasks_count @my_assign_tasks_count -json.my_assign_bugs_count @my_assign_bugs_count -json.issues @issues.each do |issue| - json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} -end - +json.data do + json.total_count @issues.total_count + json.my_assign_requirements_count @my_assign_requirements_count + json.my_assign_tasks_count @my_assign_tasks_count + json.my_assign_bugs_count @my_assign_bugs_count + json.issues @issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} + end +end \ No newline at end of file diff --git a/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder index 76ec90f97..dc9613183 100644 --- a/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder +++ b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder @@ -1,21 +1,23 @@ json.status 0 json.message "success" -json.total_count @journals.total_count -json.journals @journals do |journal| - journal.associate_attachment_container - json.id journal.id - json.is_journal_detail journal.is_journal_detail? - json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") - json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") - json.user do - if journal.user.present? - json.partial! "api/v1/users/simple_user", user: journal.user - else - json.nil! +json.data do + json.total_count @journals.total_count + json.journals @journals do |journal| + journal.associate_attachment_container + json.id journal.id + json.is_journal_detail journal.is_journal_detail? + json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") + json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") + json.user do + if journal.user.present? + json.partial! "api/v1/users/simple_user", user: journal.user + else + json.nil! + end end + detail = journal.journal_details.take + json.operate_category journal.pm_operate_category + json.operate_content journal.is_journal_detail? ? journal.pm_dashboard_operate_content : nil + end - detail = journal.journal_details.take - json.operate_category journal.pm_operate_category - json.operate_content journal.is_journal_detail? ? journal.pm_dashboard_operate_content : nil - -end \ No newline at end of file +end diff --git a/app/views/api/pm/dashboards/todo.json.jbuilder b/app/views/api/pm/dashboards/todo.json.jbuilder index bea1ec07f..59f331531 100644 --- a/app/views/api/pm/dashboards/todo.json.jbuilder +++ b/app/views/api/pm/dashboards/todo.json.jbuilder @@ -1,7 +1,10 @@ json.status 0 json.message "success" -json.total_count @issues.total_count +json.data do + json.total_count @issues.total_count -json.issues @issues.each do |issue| - json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} -end + json.issues @issues.each do |issue| + json.partial! "api/v1/issues/simple_detail", locals: {issue: issue} + end + +end \ No newline at end of file From f838ce4a0c82cb59fcb4ced447e979e2ad089d2a Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Dec 2024 17:22:27 +0800 Subject: [PATCH 29/56] =?UTF-8?q?fix:=20=E5=85=B3=E8=81=94issue=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index ce0981a89..19ab28435 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -246,7 +246,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id) i = compare_link_issues_ids.count while i > 0 do - children_issues = Issue.where(root_id: compare_link_issues_ids).where.not(pm_issue_type: 1) + children_issues = Issue.where(root_id: compare_link_issues_ids) linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id)) belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id)) @@ -254,6 +254,10 @@ class Api::Pm::IssuesController < Api::Pm::BaseController full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids i = compare_link_issues_ids.count end + exclude_issues_array = Issue.where(id: full_link_issues_ids).where.not(root_id: nil).pluck(:id, :root_id) + exclude_issues_array.each do |i| + full_link_issues_ids - [i[0]] if full_link_issues_ids.include?(i[1]) + end @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1).pm_includes @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes From 31ff7ba49e8d475e752ef3763d455541c2b525a7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 11 Dec 2024 17:34:48 +0800 Subject: [PATCH 30/56] =?UTF-8?q?fix:=20=E5=85=B3=E8=81=94=E9=9A=90?= =?UTF-8?q?=E8=97=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 19ab28435..3c33ab02d 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -256,7 +256,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end exclude_issues_array = Issue.where(id: full_link_issues_ids).where.not(root_id: nil).pluck(:id, :root_id) exclude_issues_array.each do |i| - full_link_issues_ids - [i[0]] if full_link_issues_ids.include?(i[1]) + full_link_issues_ids = full_link_issues_ids - [i[0]] if full_link_issues_ids.include?(i[1]) end @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1).pm_includes From e822652901545e571390f3176fef086eb59af384 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 12 Dec 2024 09:10:09 +0800 Subject: [PATCH 31/56] =?UTF-8?q?=E6=9B=B4=E6=96=B0:=20=E5=85=B3=E8=81=94?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 3c33ab02d..7c527e6cc 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -254,14 +254,15 @@ class Api::Pm::IssuesController < Api::Pm::BaseController full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids i = compare_link_issues_ids.count end - exclude_issues_array = Issue.where(id: full_link_issues_ids).where.not(root_id: nil).pluck(:id, :root_id) - exclude_issues_array.each do |i| - full_link_issues_ids = full_link_issues_ids - [i[0]] if full_link_issues_ids.include?(i[1]) + exclude_issues_ids = [] + exclude_issues = Issue.where(id: full_link_issues_ids).where.not(root_id: nil) + exclude_issues.each do |i| + exclude_issues_ids << i.id if i.pm_issue_type == 1 && full_link_issues_ids.include?(i.root_id) end - - @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1).pm_includes - @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes - @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes + full_link_issues_ids = full_link_issues_ids - exclude_issues_ids + @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1, root_id: nil).pm_includes + @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2, root_id: nil).pm_includes + @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3, root_id: nil).pm_includes end private From 43f33b1af296f5e3952c5012210bba470c2bf846 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 16 Dec 2024 14:18:35 +0800 Subject: [PATCH 32/56] =?UTF-8?q?fix:=20=E9=A1=B9=E7=9B=AE=E6=A6=82?= =?UTF-8?q?=E8=A7=88=E5=BC=80=E5=90=AF=E4=B8=AD=E5=B7=A5=E4=BD=9C=E9=A1=B9?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 82b931f05..51e68d18f 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -73,9 +73,9 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } end open_data = { - "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i, - "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i, - "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i, + "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i + type_status_data[1][3].to_i, + "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i + type_status_data[2][3].to_i, + "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i + type_status_data[3][3].to_i, } if type_count_data.keys.size < 3 nedd_add = [1,2,3] - type_count_data.keys From 5dc16d11c5077922ef2ed2a28da7f8630c0bf9c1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 16 Dec 2024 16:04:23 +0800 Subject: [PATCH 33/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E6=A6=82=E8=A7=88=E6=95=B0=E9=87=8F=E4=BB=A5=E5=8F=8A=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=8F=98=E6=9B=B4=E9=A1=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 4 ++-- app/controllers/api/pm/projects_controller.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 7c527e6cc..49cb5295c 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -261,8 +261,8 @@ class Api::Pm::IssuesController < Api::Pm::BaseController end full_link_issues_ids = full_link_issues_ids - exclude_issues_ids @requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1, root_id: nil).pm_includes - @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2, root_id: nil).pm_includes - @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3, root_id: nil).pm_includes + @task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes + @bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes end private diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 51e68d18f..bd7c0991d 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -73,9 +73,9 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } end open_data = { - "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i + type_status_data[1][3].to_i, - "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i + type_status_data[2][3].to_i, - "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i + type_status_data[3][3].to_i, + "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i + type_status_data[1][3].to_i + type_status_data[1][6].to_i, + "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i + type_status_data[2][3].to_i + type_status_data[2][6].to_i, + "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i + type_status_data[3][3].to_i + type_status_data[3][6].to_i, } if type_count_data.keys.size < 3 nedd_add = [1,2,3] - type_count_data.keys From 117e2683069cebc69a01604db90278e8a63ab809 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 17 Dec 2024 15:05:51 +0800 Subject: [PATCH 34/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=8F=90=E5=8F=96=E5=90=8E=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AEdb?= 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 From c96bbf5ec79b7ce70535277ff50a016a63c4fb9e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 17 Dec 2024 17:34:17 +0800 Subject: [PATCH 35/56] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=A4=E4=B8=AA=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index bd7c0991d..3cece6400 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -64,6 +64,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController IssueStatus.all.map do |e| # next if e.id == 5 [1,2,3].map{ |type| + next if type == 1 && [1, 6].include?(e.id) type_status_data[type] = {} if type_status_data[type].nil? if type_status[[type,e.id]].nil? type_status_data[type][e.id] = 0 From c4728713555fcc429743a886079c3c8291683ac8 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Dec 2024 10:09:40 +0800 Subject: [PATCH 36/56] =?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| %> From c99dc6647a30ac45eae15bd734ed911d6d1cd048 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 18 Dec 2024 10:22:39 +0800 Subject: [PATCH 37/56] =?UTF-8?q?fix:=20=E5=AD=97=E6=AF=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/dashboards_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 6b05c3b48..0c483df46 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -76,7 +76,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count, all_task_issues_count: @all_task_issues_count, open_task_issues_count: @open_task_issues_count, - last_week_close_tast_issues_count: @last_week_close_tast_issues_count, + last_week_close_task_issues_count: @last_week_close_tast_issues_count, last_month_close_task_issues_count: @last_month_close_task_issues_count, all_bug_issues_count: @all_bug_issues_count, open_bug_issues_count: @open_bug_issues_count, From 96254f0cc46f77834a496973d24657a9fd2dc910 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 18 Dec 2024 11:24:10 +0800 Subject: [PATCH 38/56] fixed run_results --- 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 0f20df969..68305a40b 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -109,7 +109,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @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])) + render_ok(run_results: results.as_json(only: %i[id run_id job_name job_show_type job_result])) end def show From c014857cf52a70a6038289b9174d6183b6330189 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 24 Dec 2024 15:11:55 +0800 Subject: [PATCH 39/56] =?UTF-8?q?fixed=20user=20=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E9=97=B4=E6=94=B9=E4=B8=BA5?= =?UTF-8?q?=E5=88=86=E9=92=9F=E6=9B=B4=E6=96=B0=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1fee098fb..a65775225 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -692,7 +692,11 @@ class User < Owner # Returns the user who matches the given autologin +key+ or nil def self.try_to_autologin(key) user = Token.find_active_user('autologin', key) - user.update(last_login_on: Time.now) if user + if user + Rails.cache.fetch("user::update::last_login_on::#{user.id}",:expires_in => 5.minutes) do + user.update(last_login_on: Time.now) + end + end user end From 3c3ff13ab0f13d339a9e3ea8c142e31ae0c23d5b Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 30 Dec 2024 16:04:20 +0800 Subject: [PATCH 40/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=BA=93?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/node_types_controller.rb | 14 ++++++++++++-- app/controllers/action/nodes_controller.rb | 5 ++++- app/controllers/action/templates_controller.rb | 5 ++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/controllers/action/node_types_controller.rb b/app/controllers/action/node_types_controller.rb index 32508d942..e90bb665c 100644 --- a/app/controllers/action/node_types_controller.rb +++ b/app/controllers/action/node_types_controller.rb @@ -4,6 +4,10 @@ class Action::NodeTypesController < ApplicationController def index @node_types = Action::NodeType.all + respond_to do |format| + format.html + format.json { render_ok(data: @node_types.as_json) } + end end def create @@ -20,7 +24,10 @@ class Action::NodeTypesController < ApplicationController end def show - + respond_to do |format| + format.html + format.json { render_ok(data: @node_type.as_json) } + end end def new @@ -45,7 +52,10 @@ class Action::NodeTypesController < ApplicationController else flash[:danger] = '删除失败' end - redirect_to action_node_types_path + respond_to do |format| + format.html { redirect_to action_node_types_path } + format.json { render_ok } + end end private diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index 2664ff95a..f8219ca8d 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -58,7 +58,10 @@ class Action::NodesController < ApplicationController else flash[:danger] = '删除失败' end - redirect_to action_nodes_path + respond_to do |format| + format.html { redirect_to action_nodes_path } + format.json { render_ok() } + end end private diff --git a/app/controllers/action/templates_controller.rb b/app/controllers/action/templates_controller.rb index 092d38d64..f7f99b7d7 100644 --- a/app/controllers/action/templates_controller.rb +++ b/app/controllers/action/templates_controller.rb @@ -49,7 +49,10 @@ class Action::TemplatesController < ApplicationController else flash[:danger] = '删除失败' end - redirect_to action_templates_path + respond_to do |format| + format.html { redirect_to action_templates_path } + format.json { render_ok } + end end private From 956552e36fad0efa036653290f8781a3749a06ec Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 2 Jan 2025 14:43:11 +0800 Subject: [PATCH 41/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=BA=93?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/node_inputs_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/action/node_inputs_controller.rb b/app/controllers/action/node_inputs_controller.rb index 65227c657..cf108f324 100644 --- a/app/controllers/action/node_inputs_controller.rb +++ b/app/controllers/action/node_inputs_controller.rb @@ -6,7 +6,7 @@ class Action::NodeInputsController < ApplicationController @node_inputs = @node.action_node_inputs respond_to do |format| format.html - format.json + format.json{ render_ok(data: @node_inputs.as_json) } end end From accecb3d0c486633547dd475990a32cb95159295 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 2 Jan 2025 16:36:41 +0800 Subject: [PATCH 42/56] =?UTF-8?q?fixed=20=E8=8A=82=E7=82=B9=E5=BA=93?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/action/nodes/show.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/action/nodes/show.json.jbuilder b/app/views/action/nodes/show.json.jbuilder index 4bf73bef3..e731dbd0b 100644 --- a/app/views/action/nodes/show.json.jbuilder +++ b/app/views/action/nodes/show.json.jbuilder @@ -1,7 +1,7 @@ json.status 0 json.message "success" -json.extract! @node, :id, :name, :full_name, :description, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count, :node_type, :is_mutil_link, :link_type +json.extract! @node, :id, :name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no, :use_count, :label, :node_type, :is_mutil_link, :link_type json.inputs @node.action_node_inputs do |node_input| json.partial! "node_input", locals: { node_input: node_input, node: @node } end \ No newline at end of file From 38d860385dc235e91f68a1d2cfca378c3b603288 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 9 Jan 2025 14:45:43 +0800 Subject: [PATCH 43/56] =?UTF-8?q?fix:=20=E5=8A=A8=E6=80=81=E6=96=87?= =?UTF-8?q?=E6=A1=88=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index fe077ae66..196a76165 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -114,7 +114,7 @@ class Journal < ApplicationRecord prefix += "任务" if self.issue.pm_issue_type == 2 prefix += "缺陷" if self.issue.pm_issue_type == 3 prefix += "#{self.issue.subject}" - content = prefix + content + content = prefix + content.sub('将', '的') end content end From aef492cc4fb1df176c90e07342482e2a47695114 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 10 Jan 2025 09:29:28 +0800 Subject: [PATCH 44/56] =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=BA=93=E5=BC=80?= =?UTF-8?q?=E6=94=BE=E7=AE=A1=E7=90=86=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 7 +++++-- app/views/action/nodes/index.html.erb | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index f8219ca8d..c995513da 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -1,12 +1,13 @@ class Action::NodesController < ApplicationController - before_action :require_admin, except: [:index] + # before_action :require_admin, except: [:index] + before_action :require_login before_action :find_action_node, except: [:index, :create, :new] def index @node_types = Action::NodeType.all @no_type_nodes = Action::Node.where(action_node_types_id: nil) respond_to do |format| - format.html { @nodes = Action::Node.all } + format.html { @nodes = Action::Node.where("name LIKE :search OR full_name LIKE :search", :search => "%#{params[:search]}%") } format.json end end @@ -16,6 +17,7 @@ class Action::NodesController < ApplicationController if params.require(:node).present? && params.require(:node)[:link_type_array].present? @node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",") end + @node.user_id = current_user.id respond_to do |format| if @node.save format.html { redirect_to action_nodes_path, notice: '创建成功.' } @@ -45,6 +47,7 @@ class Action::NodesController < ApplicationController if params.require(:node).present? && params.require(:node)[:link_type_array].present? @node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",") end + @node.user_id = current_user.id if @node.user_id.blank? @node.update(node_params) respond_to do |format| format.html { redirect_to action_nodes_path, notice: '更新成功.' } diff --git a/app/views/action/nodes/index.html.erb b/app/views/action/nodes/index.html.erb index ce603590b..60ad9489a 100644 --- a/app/views/action/nodes/index.html.erb +++ b/app/views/action/nodes/index.html.erb @@ -5,6 +5,15 @@

>>前往模板配置

说明:该界面适用于action 节点配置参数配置

+
+ <%= form_tag(action_nodes_path, method: :get, class: 'form-inline search-form flex-1') do %> + <%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '关键字检索') %> + <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %> + + <% end %> + <%= link_to "新增", new_action_node_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> +
+ From b27dc8393dafa9d93dcfb67966b6c1c318f6ec53 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 10 Jan 2025 14:55:35 +0800 Subject: [PATCH 45/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=8E=92=E8=A1=8C=E6=A6=9C=E7=BB=9F=E8=AE=A1=E8=B4=9F=E6=95=B0?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/cache/v2/user_date_rank_service.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/services/cache/v2/user_date_rank_service.rb b/app/services/cache/v2/user_date_rank_service.rb index b669e4d67..d390d1f5f 100644 --- a/app/services/cache/v2/user_date_rank_service.rb +++ b/app/services/cache/v2/user_date_rank_service.rb @@ -87,14 +87,22 @@ class Cache::V2::UserDateRankService < ApplicationService def set_user_rank set_user_statistic follow_count = $redis_cache.hget(user_date_statistic_key, "follow-count") || 0 + follow_count = follow_count.to_i < 0 ? 0 : follow_count pullrequest_count = $redis_cache.hget(user_date_statistic_key, "pullrequest-count") || 0 + pullrequest_count = pullrequest_count.to_i < 0 ? 0 : pullrequest_count issues_count = $redis_cache.hget(user_date_statistic_key, "issue-count") || 0 + issues_count = issues_count.to_i < 0 ? 0 : issues_count project_count = $redis_cache.hget(user_date_statistic_key, "project-count") || 0 + project_count = project_count.to_i < 0 ? 0 : project_count fork_count = $redis_cache.hget(user_date_statistic_key, "fork-count") || 0 + fork_count = fork_count.to_i < 0 ? 0 : fork_count project_watchers_count = $redis_cache.hget(user_date_statistic_key, "project-watcher-count") || 0 + project_watchers_count = project_watchers_count.to_i < 0 ? 0 : project_watchers_count project_praises_count = $redis_cache.hget(user_date_statistic_key, "project-praise-count") || 0 + project_praises_count = project_praises_count.to_i < 0 ? 0 : project_praises_count project_language = $redis_cache.hget(user_date_statistic_key, "project-language") project_languages_count = project_language.nil? || project_language == "{}" ? 0 : JSON.parse(project_language).length + project_languages_count = project_languages_count.to_i < 0 ? 0 : project_languages_count # 影响力 influence = (60.0 + follow_count.to_i / (follow_count.to_i + 20.0) * 40.0).to_i From 84d6626c5c59445686c3e982d1788d6bb09e8f25 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Jan 2025 16:26:17 +0800 Subject: [PATCH 46/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Astar=5Fdate?= =?UTF-8?q?=E5=92=8Cdue=5Fdate=E5=88=B0=E5=B7=A5=E4=BD=9C=E5=8F=B0?= =?UTF-8?q?=E6=88=91=E7=9A=84=E5=B7=A5=E4=BD=9C=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/issues/_simple_detail.json.jbuilder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/api/v1/issues/_simple_detail.json.jbuilder b/app/views/api/v1/issues/_simple_detail.json.jbuilder index f3a4a12fd..2c05acf7f 100644 --- a/app/views/api/v1/issues/_simple_detail.json.jbuilder +++ b/app/views/api/v1/issues/_simple_detail.json.jbuilder @@ -38,4 +38,6 @@ end json.assigners issue.show_assigners.each do |assigner| json.partial! "api/v1/users/simple_user", locals: {user: assigner} end -json.comment_journals_count issue.comment_journals.size \ No newline at end of file +json.comment_journals_count issue.comment_journals.size +json.start_date issue.start_date +json.due_date issue.due_date \ No newline at end of file From 2a77ac99d94ad7abc3bbdfb5887b3e765a936bac Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 16 Jan 2025 15:17:48 +0800 Subject: [PATCH 47/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E5=B7=A5=E4=BD=9C?= =?UTF-8?q?=E5=8F=B0=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=B2=BE=E7=A1=AE=E5=88=B0=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/pm/dashboards/my_operate_journals.json.jbuilder | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder index dc9613183..0d0aeb18f 100644 --- a/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder +++ b/app/views/api/pm/dashboards/my_operate_journals.json.jbuilder @@ -8,6 +8,8 @@ json.data do json.is_journal_detail journal.is_journal_detail? json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M") json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M") + json.created_time journal.created_on.to_i + json.updated_time journal.updated_on.to_i json.user do if journal.user.present? json.partial! "api/v1/users/simple_user", user: journal.user From 4be2d817c9c28e3af8649dd63b62ac805c71d301 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Jan 2025 15:22:08 +0800 Subject: [PATCH 48/56] =?UTF-8?q?fixed:=20fork=EF=BC=8Cpr=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=AF=AD=E6=B3=95=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 cda797b1a..4d3bf7738 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -6,7 +6,7 @@ on: <% node.input_values.each_key do |key| %> <%=key %>: <% if node.input_values[key].blank? %> - - * + - '*' <% else %> <% node.input_values[key].to_s.split(",").each do |val| %> - <%=val %> @@ -19,10 +19,10 @@ on: <% node.input_values.each_key do |key| %> <%=key %>: <% if node.input_values[key].blank? %> - - * + - '*' <% else %> <% node.input_values[key].to_s.split(",").each do |val| %> - - <%=val %> + - <%=val %> <% end %> <% end %> <% end %> From 71a8d67515cb4176aaa9af3e099e8b6fdf215729 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 17 Jan 2025 10:43:31 +0800 Subject: [PATCH 49/56] =?UTF-8?q?fixed:=20=E6=9C=AA=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index c995513da..a891b2a29 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -5,7 +5,9 @@ class Action::NodesController < ApplicationController def index @node_types = Action::NodeType.all + no_node_type = Action::NodeType.find_by(name: "未分类") @no_type_nodes = Action::Node.where(action_node_types_id: nil) + @no_type_nodes = Action::Node.where(action_node_types_id: nil).or(where(action_node_types_id: no_node_type.id)) if no_node_type.present? respond_to do |format| format.html { @nodes = Action::Node.where("name LIKE :search OR full_name LIKE :search", :search => "%#{params[:search]}%") } format.json From e3d21199f57930e2555c74a99b4407624f4a7e2f Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 17 Jan 2025 10:45:37 +0800 Subject: [PATCH 50/56] =?UTF-8?q?fixed:=20=E6=9C=AA=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/action/nodes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/action/nodes_controller.rb b/app/controllers/action/nodes_controller.rb index a891b2a29..67eb70c2f 100644 --- a/app/controllers/action/nodes_controller.rb +++ b/app/controllers/action/nodes_controller.rb @@ -7,7 +7,7 @@ class Action::NodesController < ApplicationController @node_types = Action::NodeType.all no_node_type = Action::NodeType.find_by(name: "未分类") @no_type_nodes = Action::Node.where(action_node_types_id: nil) - @no_type_nodes = Action::Node.where(action_node_types_id: nil).or(where(action_node_types_id: no_node_type.id)) if no_node_type.present? + @no_type_nodes = Action::Node.where(action_node_types_id: nil).or(Action::Node.where(action_node_types_id: no_node_type.id)) if no_node_type.present? respond_to do |format| format.html { @nodes = Action::Node.where("name LIKE :search OR full_name LIKE :search", :search => "%#{params[:search]}%") } format.json From c94078831cb3520ab830161cd2655f25b48220f0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Jan 2025 14:01:09 +0800 Subject: [PATCH 51/56] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=E4=BB=8A=E6=97=A5?= =?UTF-8?q?=E5=BE=85=E5=8A=9E=E6=97=B6=E9=97=B4=E8=8C=83=E5=9B=B4=E5=8C=85?= =?UTF-8?q?=E6=8B=AC=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/dashboards_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/dashboards_controller.rb b/app/controllers/api/pm/dashboards_controller.rb index 0c483df46..8fd1f0b9e 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -7,7 +7,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank? pm_project_ids = params[:pm_project_ids].split(",") rescue [] date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today - @issues = Issue.where("start_date < ? and due_date > ?", date, date) + @issues = Issue.where("start_date <= ? and due_date >= ?", date, date) @issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}) @issues = kaminari_paginate(@issues.distinct.pm_includes) end From 0fb6069ed64ea5948d46f83a5f6573cacf81a5a1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 17 Jan 2025 14:49:12 +0800 Subject: [PATCH 52/56] =?UTF-8?q?=E6=9B=B4=E6=94=B9:=E4=BB=8A=E6=97=A5?= =?UTF-8?q?=E5=BE=85=E5=8A=9E=E7=AD=9B=E9=80=89=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 8fd1f0b9e..2798c3c52 100644 --- a/app/controllers/api/pm/dashboards_controller.rb +++ b/app/controllers/api/pm/dashboards_controller.rb @@ -9,6 +9,7 @@ class Api::Pm::DashboardsController < Api::Pm::BaseController date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today @issues = Issue.where("start_date <= ? and due_date >= ?", date, date) @issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}) + @issues = @issues.where.not(status_id: 5) @issues = kaminari_paginate(@issues.distinct.pm_includes) end From e82e63938b910b02d1e3d26bbb305728cfa360ae Mon Sep 17 00:00:00 2001 From: feng <281221230@qq.com> Date: Wed, 22 Jan 2025 15:17:45 +0800 Subject: [PATCH 53/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20nps=20=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/nps/index.html.erb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/views/admins/nps/index.html.erb b/app/views/admins/nps/index.html.erb index 81e11dd2f..61686e831 100644 --- a/app/views/admins/nps/index.html.erb +++ b/app/views/admins/nps/index.html.erb @@ -37,6 +37,21 @@ 提升用户体验:<%= UserNp.where("memo like '%用户体验需进一步提升%'").count %>, 其他:<%= UserNp.where("action_type !='close'").where("LENGTH(memo) >0").where.not(id: UserNp.where("memo like '%期待更加丰富的功能%' or memo like '%希望有新手引导%' or memo like '%用户体验需进一步提升%' ").ids).count %>

+

+ 代码库基本功能:<%= UserNp.where("memo like '%代码库基本功能%'").count %>, + 疑修:<%= UserNp.where("memo like '%疑修%'").count %>, + 合并请求:<%= UserNp.where("memo like '%合并请求%'").count %>, + 流水线引擎:<%= UserNp.where("memo like '%流水线引擎%'").count %>, + 维基Wiki:<%= UserNp.where("memo like '%维基Wiki%'").count %>, + 数据集:<%= UserNp.where("memo like '%数据集%'").count %>, + 特色专区:<%= UserNp.where("memo like '%特色专区%'").count %>, + BOT功能:<%= UserNp.where("memo like '%BOT功能%'").count %>, + 跨平台同步服务:<%= UserNp.where("memo like '%跨平台同步服务%'").count %>, + 代码溯源及扫描服务:<%= UserNp.where("memo like '%代码溯源及扫描服务%'").count %>, + 开源软件健康度量服务:<%= UserNp.where("memo like '%开源软件健康度量服务%'").count %>, + HiAgent:<%= UserNp.where("memo like '%HiAgent%'").count %>, + 非常满意,没有需要吐槽的功能!:<%= UserNp.where("memo like '%非常满意,没有需要吐槽的功能!%'").count %> +

<%= render partial: 'admins/nps/user_np_list', locals: { user_nps: @user_nps } %> From 4331fc3302b9dbe41f4afce7374249b4cdbb4737 Mon Sep 17 00:00:00 2001 From: feng <281221230@qq.com> Date: Wed, 22 Jan 2025 15:27:39 +0800 Subject: [PATCH 54/56] =?UTF-8?q?nps=20=E7=BB=9F=E8=AE=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/admins/nps/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admins/nps/index.html.erb b/app/views/admins/nps/index.html.erb index 61686e831..4a6e95168 100644 --- a/app/views/admins/nps/index.html.erb +++ b/app/views/admins/nps/index.html.erb @@ -50,7 +50,7 @@ 代码溯源及扫描服务:<%= UserNp.where("memo like '%代码溯源及扫描服务%'").count %>, 开源软件健康度量服务:<%= UserNp.where("memo like '%开源软件健康度量服务%'").count %>, HiAgent:<%= UserNp.where("memo like '%HiAgent%'").count %>, - 非常满意,没有需要吐槽的功能!:<%= UserNp.where("memo like '%非常满意,没有需要吐槽的功能!%'").count %> + 非常满意,没有需要吐槽的功能!:<%= UserNp.where("memo like '%非常满意,没有需要吐槽的功能%'").count %>

From c7b399f6247e0c00c11ddd525dcd9f293de18cd2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 Jan 2025 16:50:42 +0800 Subject: [PATCH 55/56] =?UTF-8?q?=E6=96=B0=E5=A2=9E:=20=E6=B5=81=E6=B0=B4?= =?UTF-8?q?=E7=BA=BF=E6=94=B9=E7=89=88=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1/projects/actions/actions_controller.rb | 44 +++++++++++++++++++ app/models/gitea/action_run.rb | 9 ++++ config/routes/api.rb | 1 + 3 files changed, 54 insertions(+) create mode 100644 app/models/gitea/action_run.rb diff --git a/app/controllers/api/v1/projects/actions/actions_controller.rb b/app/controllers/api/v1/projects/actions/actions_controller.rb index 3825b4685..5a34847e2 100644 --- a/app/controllers/api/v1/projects/actions/actions_controller.rb +++ b/app/controllers/api/v1/projects/actions/actions_controller.rb @@ -1,5 +1,49 @@ class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions::BaseController + def new_index + @files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") + puts @files + @action_runs = Gitea::ActionRun.where(repo_id: @project.gpid, status: [1,2]) + group_data = @action_runs.group(:workflow_id, :status).count + @result = [] + @files.map{|i|i['name']}.each do |file| + 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] == 1 + end + + @result << { + name: file, + last_action_run: last_action_run_json, + history: { + total: total, + success: success, + failure: failure, + } + } + end + + render :json => @result + end + def index begin gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier) diff --git a/app/models/gitea/action_run.rb b/app/models/gitea/action_run.rb new file mode 100644 index 000000000..b6c8693fc --- /dev/null +++ b/app/models/gitea/action_run.rb @@ -0,0 +1,9 @@ +class Gitea::ActionRun < Gitea::Base + self.inheritance_column = nil # FIX The single-table inheritance mechanism failed + # establish_connection :gitea_db + + self.table_name = "action_run" + + # belongs_to :user, class_name: '::User', primary_key: :gitea_uid, foreign_key: :owner_id, optional: true + +end diff --git a/config/routes/api.rb b/config/routes/api.rb index 3d6078b13..ec8031fd8 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -162,6 +162,7 @@ defaults format: :json do resource :dataset, only: [:create, :update, :show] resources :actions, module: 'actions' do collection do + get :new_index post :disable post :enable resources :runs, only: [:index, :create] do From 4d0ed530b71ce9b872ac69c381288d3cb2e3d7cd Mon Sep 17 00:00:00 2001 From: feng <281221230@qq.com> Date: Thu, 23 Jan 2025 10:08:06 +0800 Subject: [PATCH 56/56] =?UTF-8?q?nps=20=E7=BB=9F=E8=AE=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/nps_controller.rb | 2 +- app/views/admins/nps/_user_np_list.html.erb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/admins/nps_controller.rb b/app/controllers/admins/nps_controller.rb index bfb72f730..2817cd0c6 100644 --- a/app/controllers/admins/nps_controller.rb +++ b/app/controllers/admins/nps_controller.rb @@ -2,7 +2,7 @@ class Admins::NpsController < Admins::BaseController before_action :require_business def index @on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true' - @user_nps = UserNp.joins(:user).order(created_at: :desc) + @user_nps = UserNp.order(created_at: :desc) keyword = params[:keyword].to_s.strip.presence if keyword sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword' diff --git a/app/views/admins/nps/_user_np_list.html.erb b/app/views/admins/nps/_user_np_list.html.erb index f2d5196e9..474fe8b86 100644 --- a/app/views/admins/nps/_user_np_list.html.erb +++ b/app/views/admins/nps/_user_np_list.html.erb @@ -12,15 +12,15 @@
<% if user_nps.present? %> <% user_nps.each_with_index do |nps, index| %> - + "> - +
<%= list_index_no((params[:page] || 1).to_i, index) %> - <%= link_to "/#{nps.user.login}", target: '_blank' do %> - <%= overflow_hidden_span nps.user.real_name, width: 100 %> + <%= link_to "/#{nps.user.nil? ? "用户已注销" : nps.user.login}", target: '_blank' do %> + <%= overflow_hidden_span (nps.user.nil? ? "用户已注销" : nps.user.real_name), width: 100 %> <% end %> <%= display_text(nps.created_at&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(nps.user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %><%= display_text(nps.user.nil? ? "用户已注销" : nps.user.last_login_on&.strftime('%Y-%m-%d %H:%M')) %> <%= nps.action_type == 'close' ? '--' : nps.score %> <%= nps.memo %>