lib/dri/commands/fetch/pipelines.rb in dri-0.6.1 vs lib/dri/commands/fetch/pipelines.rb in dri-0.7.0

- old
+ new

@@ -59,11 +59,11 @@ # @return [Gitlab::ObjectifiedHash,nil] nil if downstream (bridge) pipeline does not exist def bridge_pipeline(project_id, pipeline_id) bridges = api_client.pipeline_bridges(project_id, pipeline_id) return if bridges.empty? # If downstream pipeline doesn't exist, which triggers the QA tests, return - bridges.first["downstream_pipeline"] + bridges.find { |it| it.name == "e2e:package-and-test" }&.downstream_pipeline end # Get jobs from a pipeline # @param [Integer] project_id the id of the project # @param [Integer] pipeline_id the pipeline id @@ -134,10 +134,18 @@ false if full_run?(jobs: pipeline_jobs, project_id: pipeline.project_id, pipeline_id: pipeline.id, ops: ops) end + # Master pipeline run + # + # @param [String] pipeline_name + # @return [Boolean] + def master?(pipeline_name) + pipeline_name == "master" + end + # Constructs allure report url for each pipeline # @param [String] pipeline_name # @param [Integer] pipeline_id # @param [Boolean] sanity def allure_report(pipeline_name:, pipeline_id:, sanity:) @@ -149,11 +157,11 @@ # @param [String] pipeline_name # @param [Boolean] sanity def allure_bucket_name(pipeline_name, sanity) case pipeline_name when "master" - "package-and-qa" + "e2e-package-and-test" when "nightly" pipeline_name when "pre_prod" "preprod-#{run_type(sanity)}" else @@ -180,33 +188,40 @@ # @param [String] url def ops_pipeline?(url) url.include?("ops.gitlab.net") end - def notify_slack_job_name(pipeline_name, ops) - return "notify-slack-qa-fail" if ops - - pipeline_name.to_s.include?("master") ? "notify_slack" : "notify-slack-fail" + # Slack notification job name + # + # @param [Boolean] ops + # @return [String] + def notify_job_name(ops) + ops ? "notify-slack-qa-fail" : "notify-slack-fail" end # Returns child pipeline if it is master pipeline + # @param [String] pipeline_name # @param [Gitlab::ObjectifiedHash] pipeline - def pipeline_with_qa_tests(pipeline) - if pipeline.web_url.to_s.include?("gitlab-qa-mirror") + def pipeline_with_qa_tests(pipeline_name, pipeline) + if master?(pipeline_name) bridge_pipeline(pipeline.project_id, pipeline.id) else pipeline end end # Returns query options for pipelines api call # @param [Hash] details # @param [Boolean] ops def options(details, ops) - options = { order_by: "updated_at", scope: "finished", - updated_after: past_timestamp(details[:search_hours_ago]) } - options.merge(username: "gitlab-bot") if ops + options = { + order_by: "updated_at", + scope: "finished", + ref: "master", + updated_after: past_timestamp(details[:search_hours_ago]) + } + options.merge(username: "gitlab-bot") if ops || master?(details[:name]) options end def emoji_for_success_failure(status) return add_color("✓", :green) if status.include?("success") @@ -216,31 +231,28 @@ # @param [String] pipeline_name # @param [Hash] details Pipeline environment details # @return [Array] Array of last executed pipeline details # rubocop:disable Metrics/PerceivedComplexity - def fetch_pipeline(pipeline_name:, details:) # rubocop:disable Metrics/CyclomaticComplexity + def fetch_pipeline(pipeline_name:, details:) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize ops = ops_pipeline?(details[:url]) options = options(details, ops) # instance is ops.gitlab.net or gitlab.com response = api_client(ops: ops).pipelines(project_id: details[:project_id], options: options, auto_paginate: true) return [pipeline_name, NOT_FOUND, NOT_FOUND, NOT_FOUND, NOT_FOUND] if response.empty? # Return empty data to the table if no matching pipelines were found from the query response.each do |pipeline| - pipeline_to_scan = pipeline_with_qa_tests(pipeline) # Fetch child pipeline if it is master + pipeline_to_scan = pipeline_with_qa_tests(pipeline_name, pipeline) # Fetch child pipeline if it is master next if pipeline_to_scan.nil? pipeline_jobs = jobs(project_id: pipeline.project_id, pipeline_id: pipeline_to_scan.id, ops: ops) - next unless contains_job?(pipeline_jobs, job_name: notify_slack_job_name(pipeline_name, ops)) + next unless master?(pipeline_name) || contains_job?(pipeline_jobs, job_name: notify_job_name(ops)) # Need to know if it is a sanity or a full run to construct allure report url - sanity = sanity?(pipeline_jobs: pipeline_jobs, pipeline: pipeline_to_scan, - ops: ops) - + sanity = sanity?(pipeline_jobs: pipeline_jobs, pipeline: pipeline_to_scan, ops: ops) next if sanity.nil? # To filter out some "clean up" pipelines present in live environments - next if sanity && @options[:full_runs_only] # Filter out sanity runs if --full-runs-only option is passed name = ops ? "#{pipeline_name}_#{run_type(sanity)}" : pipeline_name pipeline_last_executed = pipeline_to_scan.updated_at url = pipeline_to_scan.web_url