From 3cccd102ba543e02725d247893729e5c73b38295 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Apr 2022 10:00:54 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-10-stable-ee --- danger/Dangerfile-bundle_size | 41 +++++++++++++++++++++++++++++++++ danger/bundle_size/Dangerfile | 40 -------------------------------- danger/ci_templates/Dangerfile | 2 +- danger/database/Dangerfile | 4 ++-- danger/feature_flag/Dangerfile | 8 +++---- danger/product_intelligence/Dangerfile | 21 +---------------- danger/specialization_labels/Dangerfile | 4 ++-- danger/specs/Dangerfile | 2 +- danger/z_metadata/Dangerfile | 10 ++++---- 9 files changed, 57 insertions(+), 75 deletions(-) create mode 100644 danger/Dangerfile-bundle_size delete mode 100644 danger/bundle_size/Dangerfile (limited to 'danger') diff --git a/danger/Dangerfile-bundle_size b/danger/Dangerfile-bundle_size new file mode 100644 index 00000000000..23ab726096e --- /dev/null +++ b/danger/Dangerfile-bundle_size @@ -0,0 +1,41 @@ +# frozen_string_literal: true +# This file isn't named "Dangerfile" so that it's not imported by default since it's only meant to be run in the `bundle-size-review` job. + +analysis_result = "./bundle-size-review/analysis.json" +markdown_result = "./bundle-size-review/comparison.md" + +# Executing the webpack-entry-point-analyser +# We would like to do that in the CI file directly, +# but unfortunately the head_commit SHA is not available +# as a CI variable due to our merge into master simulation +analyze_cmd = [ + "webpack-entry-point-analyser", + "--from-file ./webpack-report/stats.json", + "--json #{analysis_result}", + " --sha #{gitlab&.head_commit}" +].join(" ") + +# execute analysis +`#{analyze_cmd}` + +# We are executing the comparison by comparing the start_sha +# to the current pipeline result. The start_sha is the commit +# from master that was merged into for the merged pipeline. +comparison_cmd = [ + "webpack-compare-reports", + "--job #{ENV["CI_JOB_ID"]}", + "--to-file #{analysis_result}", + "--html ./bundle-size-review/comparison.html", + "--markdown #{markdown_result}" +].join(" ") + +# execute comparison +`#{comparison_cmd}` + +comment = `cat #{markdown_result}` + +unless comment.strip.empty? + markdown(<<~MARKDOWN) + #{comment} + MARKDOWN +end diff --git a/danger/bundle_size/Dangerfile b/danger/bundle_size/Dangerfile deleted file mode 100644 index b824edb5dab..00000000000 --- a/danger/bundle_size/Dangerfile +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -analysis_result = "./bundle-size-review/analysis.json" -markdown_result = "./bundle-size-review/comparison.md" - -# Executing the webpack-entry-point-analyser -# We would like to do that in the CI file directly, -# but unfortunately the head_commit SHA is not available -# as a CI variable due to our merge into master simulation -analyze_cmd = [ - "webpack-entry-point-analyser", - "--from-file ./webpack-report/stats.json", - "--json #{analysis_result}", - " --sha #{gitlab&.head_commit}" -].join(" ") - -# execute analysis -`#{analyze_cmd}` - -# We are executing the comparison by comparing the start_sha -# to the current pipeline result. The start_sha is the commit -# from master that was merged into for the merged pipeline. -comparison_cmd = [ - "webpack-compare-reports", - "--job #{ENV["CI_JOB_ID"]}", - "--to-file #{analysis_result}", - "--html ./bundle-size-review/comparison.html", - "--markdown #{markdown_result}" -].join(" ") - -# execute comparison -`#{comparison_cmd}` - -comment = `cat #{markdown_result}` - -unless comment.strip.empty? - markdown(<<~MARKDOWN) - #{comment} - MARKDOWN -end diff --git a/danger/ci_templates/Dangerfile b/danger/ci_templates/Dangerfile index 3d57436ef94..ace9905e91d 100644 --- a/danger/ci_templates/Dangerfile +++ b/danger/ci_templates/Dangerfile @@ -19,7 +19,7 @@ return unless helper.ci? template_paths_to_review = helper.changes_by_category[:ci_template] -if gitlab.mr_labels.include?('ci::templates') || template_paths_to_review.any? +if helper.mr_labels.include?('ci::templates') || template_paths_to_review.any? message 'This merge request adds or changes files that require a ' \ 'review from the CI/CD Templates maintainers.' diff --git a/danger/database/Dangerfile b/danger/database/Dangerfile index 0128f0fa195..f94184263ad 100644 --- a/danger/database/Dangerfile +++ b/danger/database/Dangerfile @@ -49,11 +49,11 @@ if geo_migration_created && !geo_db_schema_updated end return unless helper.ci? -return if gitlab.mr_labels.include?(DATABASE_APPROVED_LABEL) +return if helper.mr_labels.include?(DATABASE_APPROVED_LABEL) db_paths_to_review = helper.changes_by_category[:database] -if gitlab.mr_labels.include?('database') || db_paths_to_review.any? +if helper.mr_labels.include?('database') || db_paths_to_review.any? message 'This merge request adds or changes files that require a ' \ 'review from the [Database team](https://gitlab.com/groups/gl-database/-/group_members).' diff --git a/danger/feature_flag/Dangerfile b/danger/feature_flag/Dangerfile index 5fe9d42a7a1..d5b907377aa 100644 --- a/danger/feature_flag/Dangerfile +++ b/danger/feature_flag/Dangerfile @@ -22,21 +22,21 @@ def check_feature_flag_yaml(feature_flag) end rescue Psych::Exception # YAML could not be parsed, fail the build. - fail "#{gitlab.html_link(feature_flag.path)} isn't valid YAML! #{SEE_DOC}" + fail "#{helper.html_link(feature_flag.path)} isn't valid YAML! #{SEE_DOC}" rescue StandardError => e warn "There was a problem trying to check the Feature Flag file. Exception: #{e.class.name} - #{e.message}" end def message_for_feature_flag_missing_group!(feature_flag:, mr_group_label:) if mr_group_label.nil? - warn "Consider setting `group` in #{gitlab.html_link(feature_flag.path)}. #{SEE_DOC}" + warn "Consider setting `group` in #{helper.html_link(feature_flag.path)}. #{SEE_DOC}" else mr_line = feature_flag.raw.lines.find_index("group:\n") if mr_line markdown(format(SUGGEST_MR_COMMENT, group: mr_group_label), file: feature_flag.path, line: mr_line.succ) else - warn %(Consider setting `group: "#{mr_group_label}"` in #{gitlab.html_link(feature_flag.path)}. #{SEE_DOC}) + warn %(Consider setting `group: "#{mr_group_label}"` in #{helper.html_link(feature_flag.path)}. #{SEE_DOC}) end end end @@ -60,7 +60,7 @@ def message_for_feature_flag_with_group!(feature_flag:, mr_group_label:) if mr_group_label.nil? helper.labels_to_add << feature_flag.group else - fail %(`group` is set to ~"#{feature_flag.group}" in #{gitlab.html_link(feature_flag.path)}, which does not match ~"#{mr_group_label}" set on the MR!) + fail %(`group` is set to ~"#{feature_flag.group}" in #{helper.html_link(feature_flag.path)}, which does not match ~"#{mr_group_label}" set on the MR!) end end diff --git a/danger/product_intelligence/Dangerfile b/danger/product_intelligence/Dangerfile index 8f782e3de65..c38d87604cc 100644 --- a/danger/product_intelligence/Dangerfile +++ b/danger/product_intelligence/Dangerfile @@ -1,22 +1,3 @@ # frozen_string_literal: true -# rubocop:disable Style/SignalException -CHANGED_FILES_MESSAGE = <<~MSG -For the following files, a review from the [Data team and Product Intelligence team](https://gitlab.com/groups/gitlab-org/growth/product-intelligence/engineers/-/group_members?with_inherited_permissions=exclude) is recommended -Please check the ~"product intelligence" [guide](https://docs.gitlab.com/ee/development/usage_ping.html). - -For MR review guidelines, see the [Service Ping review guidelines](https://docs.gitlab.com/ee/development/usage_ping/review_guidelines.html) or the [Snowplow review guidelines](https://docs.gitlab.com/ee/development/snowplow/review_guidelines.html). - -%s - -MSG - -# exit if not matching files or if no product intelligence labels -product_intelligence_paths_to_review = helper.changes_by_category[:product_intelligence] -labels_to_add = product_intelligence.missing_labels - -return if product_intelligence_paths_to_review.empty? || product_intelligence.skip_review? - -warn format(CHANGED_FILES_MESSAGE, changed_files: helper.markdown_list(product_intelligence_paths_to_review)) unless product_intelligence.has_approved_label? - -helper.labels_to_add.concat(labels_to_add) unless labels_to_add.empty? +product_intelligence.check! diff --git a/danger/specialization_labels/Dangerfile b/danger/specialization_labels/Dangerfile index f161c470f36..615ceb8625d 100644 --- a/danger/specialization_labels/Dangerfile +++ b/danger/specialization_labels/Dangerfile @@ -16,11 +16,11 @@ SPECIALIZATIONS = { labels_to_add = helper.changes_by_category.each_with_object([]) do |(category, _changes), memo| label = SPECIALIZATIONS[category] next unless label - next if gitlab.mr_labels.include?(label) + next if helper.mr_labels.include?(label) # Don't override already-set scoped labels. label_scope = label.split('::')[0...-1].join('::') - next if !label_scope.empty? && gitlab.mr_labels.any? { |mr_label| mr_label.start_with?(label_scope) } + next if !label_scope.empty? && helper.has_scoped_label_with_scope?(label_scope) memo << label end diff --git a/danger/specs/Dangerfile b/danger/specs/Dangerfile index 8ef046f7bc1..dc9809b20b5 100644 --- a/danger/specs/Dangerfile +++ b/danger/specs/Dangerfile @@ -37,7 +37,7 @@ has_ee_app_changes = all_changed_files.grep(%r{\Aee/(app|lib|db/(geo/)?(post_)?m spec_changes = specs.changed_specs_files(ee: :exclude) has_spec_changes = spec_changes.any? has_ee_spec_changes = specs.changed_specs_files(ee: :only).any? -new_specs_needed = (gitlab.mr_labels & NO_SPECS_LABELS).empty? +new_specs_needed = (helper.mr_labels & NO_SPECS_LABELS).empty? if (has_app_changes || has_ee_app_changes) && !(has_spec_changes || has_ee_spec_changes) && new_specs_needed warn format(NO_NEW_SPEC_MESSAGE, labels: helper.labels_list(NO_SPECS_LABELS)), sticky: false diff --git a/danger/z_metadata/Dangerfile b/danger/z_metadata/Dangerfile index 546fdc8de5f..9140bb7d988 100644 --- a/danger/z_metadata/Dangerfile +++ b/danger/z_metadata/Dangerfile @@ -2,7 +2,7 @@ # rubocop:disable Style/SignalException -DEFAULT_BRANCH = 'master' +default_branch = ENV['CI_DEFAULT_BRANCH'] || 'main' if gitlab.mr_body.size < 5 fail "Please provide a proper merge request description." @@ -14,12 +14,12 @@ end has_milestone = !gitlab.mr_json["milestone"].nil? -unless has_milestone || (helper.security_mr? && gitlab.branch_for_base == DEFAULT_BRANCH) +unless has_milestone || (helper.security_mr? && helper.mr_target_branch == default_branch) warn "This merge request does not refer to an existing milestone.", sticky: false end -has_pick_into_stable_label = gitlab.mr_labels.find { |label| label.start_with?('Pick into') } +has_pick_into_stable_label = helper.mr_labels.find { |label| label.start_with?('Pick into') } -if gitlab.branch_for_base != DEFAULT_BRANCH && !has_pick_into_stable_label && !helper.security_mr? - warn "Most of the time, merge requests should target `#{DEFAULT_BRANCH}`. Otherwise, please set the relevant `Pick into X.Y` label." +if helper.mr_target_branch != default_branch && !has_pick_into_stable_label && !helper.security_mr? + warn "Most of the time, merge requests should target `#{default_branch}`. Otherwise, please set the relevant `Pick into X.Y` label." end -- cgit v1.2.3