From 9da2bb742f0a3f54670fa38aa4e70dc04ea6d850 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 19 Feb 2021 06:10:35 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/helpers/application_helper.rb | 2 +- ...nable-ci_trigger_payload_into_pipeline.yml | 5 ++ changelogs/unreleased/psi-board-scroll.yml | 5 ++ .../ci_trigger_payload_into_pipeline.yml | 2 +- doc/ci/triggers/README.md | 26 ++++---- .../analytics/cycle_analytics/average.rb | 48 ++++++++++++++ .../cycle_analytics/data_collector.rb | 6 ++ .../create_project_with_auto_devops_spec.rb | 2 - .../analytics/cycle_analytics/average_spec.rb | 66 +++++++++++++++++++ 9 files changed, 145 insertions(+), 17 deletions(-) create mode 100644 changelogs/unreleased/321027-enable-ci_trigger_payload_into_pipeline.yml create mode 100644 changelogs/unreleased/psi-board-scroll.yml create mode 100644 lib/gitlab/analytics/cycle_analytics/average.rb create mode 100644 spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8268ab1ad56..9af45daaca4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -280,7 +280,7 @@ module ApplicationHelper def page_class class_names = [] - class_names << 'issue-boards-page gl-overflow-hidden' if current_controller?(:boards) + class_names << 'issue-boards-page gl-overflow-auto' if current_controller?(:boards) class_names << 'environment-logs-page' if current_controller?(:logs) class_names << 'with-performance-bar' if performance_bar_enabled? class_names << system_message_class diff --git a/changelogs/unreleased/321027-enable-ci_trigger_payload_into_pipeline.yml b/changelogs/unreleased/321027-enable-ci_trigger_payload_into_pipeline.yml new file mode 100644 index 00000000000..b42836a2011 --- /dev/null +++ b/changelogs/unreleased/321027-enable-ci_trigger_payload_into_pipeline.yml @@ -0,0 +1,5 @@ +--- +title: Implement passing trigger payload into pipeline variable +merge_request: 54544 +author: +type: added diff --git a/changelogs/unreleased/psi-board-scroll.yml b/changelogs/unreleased/psi-board-scroll.yml new file mode 100644 index 00000000000..3d68933b6f8 --- /dev/null +++ b/changelogs/unreleased/psi-board-scroll.yml @@ -0,0 +1,5 @@ +--- +title: Restore missing horizontal scrollbar on issue boards +merge_request: 54634 +author: +type: fixed diff --git a/config/feature_flags/development/ci_trigger_payload_into_pipeline.yml b/config/feature_flags/development/ci_trigger_payload_into_pipeline.yml index 93dd7113f2a..2130c6151e8 100644 --- a/config/feature_flags/development/ci_trigger_payload_into_pipeline.yml +++ b/config/feature_flags/development/ci_trigger_payload_into_pipeline.yml @@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/321027 milestone: '13.9' type: development group: group::pipeline authoring -default_enabled: false +default_enabled: true diff --git a/doc/ci/triggers/README.md b/doc/ci/triggers/README.md index b4cea48a362..fa97cbdfcec 100644 --- a/doc/ci/triggers/README.md +++ b/doc/ci/triggers/README.md @@ -188,10 +188,10 @@ source repository. Be sure to URL-encode `ref` if it contains slashes. ### Using webhook payload in the triggered pipeline > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/31197) in GitLab 13.9. -> - It's [deployed behind a feature flag](../../user/feature_flags.md), disabled by default. -> - It's disabled on GitLab.com. -> - It's not recommended for production use. -> - To use it in GitLab self-managed instances, ask a GitLab administrator to [enable it](#enable-or-disable-the-trigger_payload-variable). **(FREE SELF)** +> - It's [deployed behind a feature flag](../../user/feature_flags.md), enabled by default. +> - It's enabled on GitLab.com. +> - It's recommended for production use. +> - For GitLab self-managed instances, GitLab administrators can opt to [disable it](#enable-or-disable-the-trigger_payload-variable). **(FREE SELF)** WARNING: This feature might not be available to you. Check the **version history** note above for details. @@ -203,16 +203,10 @@ so you can access the data with `cat $TRIGGER_PAYLOAD` or a similar command. #### Enable or disable the `TRIGGER_PAYLOAD` variable -The `TRIGGER_PAYLOAD` CI/CD variable is under development and not ready for production use. It is -deployed behind a feature flag that is **disabled by default**. +The `TRIGGER_PAYLOAD` CI/CD variable is under development but ready for production use. +It is deployed behind a feature flag that is **enabled by default**. [GitLab administrators with access to the GitLab Rails console](../../administration/feature_flags.md) -can enable it. - -To enable it: - -```ruby -Feature.enable(:ci_trigger_payload_into_pipeline) -``` +can opt to disable it. To disable it: @@ -220,6 +214,12 @@ To disable it: Feature.disable(:ci_trigger_payload_into_pipeline) ``` +To enable it: + +```ruby +Feature.enable(:ci_trigger_payload_into_pipeline) +``` + ## Making use of trigger variables You can pass any number of arbitrary variables in the trigger API call and they diff --git a/lib/gitlab/analytics/cycle_analytics/average.rb b/lib/gitlab/analytics/cycle_analytics/average.rb new file mode 100644 index 00000000000..a449b71b165 --- /dev/null +++ b/lib/gitlab/analytics/cycle_analytics/average.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +module Gitlab + module Analytics + module CycleAnalytics + class Average + include Gitlab::Utils::StrongMemoize + include StageQueryHelpers + + def initialize(stage:, query:) + @stage = stage + @query = query + end + + def seconds + select_average ? select_average['average'] : nil + end + + def days + seconds ? seconds.fdiv(1.day) : nil + end + + private + + attr_reader :stage + + # rubocop: disable CodeReuse/ActiveRecord + def select_average + strong_memoize(:select_average) do + execute_query(@query.select(average_in_seconds.as('average')).reorder(nil)).first + end + end + # rubocop: enable CodeReuse/ActiveRecord + + def average + Arel::Nodes::NamedFunction.new( + 'AVG', + [duration] + ) + end + + def average_in_seconds + Arel::Nodes::Extract.new(average, :epoch) + end + end + end + end +end diff --git a/lib/gitlab/analytics/cycle_analytics/data_collector.rb b/lib/gitlab/analytics/cycle_analytics/data_collector.rb index 5eca364a697..10a008a76d5 100644 --- a/lib/gitlab/analytics/cycle_analytics/data_collector.rb +++ b/lib/gitlab/analytics/cycle_analytics/data_collector.rb @@ -31,6 +31,12 @@ module Gitlab end end + def average + strong_memoize(:average) do + Average.new(stage: stage, query: query) + end + end + private attr_reader :stage, :params diff --git a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb index 171a4776eaf..6bbc3c8c479 100644 --- a/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb +++ b/qa/qa/specs/features/browser_ui/7_configure/auto_devops/create_project_with_auto_devops_spec.rb @@ -24,8 +24,6 @@ module QA end it 'runs auto devops', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/702' do - skip('Test requires tunnel: see https://gitlab.com/gitlab-org/gitlab/-/issues/251090') - Flow::Login.sign_in # Set an application secret CI variable (prefixed with K8S_SECRET_) diff --git a/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb new file mode 100644 index 00000000000..e2fdd4918d5 --- /dev/null +++ b/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb @@ -0,0 +1,66 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Analytics::CycleAnalytics::Average do + let_it_be(:project) { create(:project) } + + let_it_be(:issue_1) do + # Duration: 10 days + create(:issue, project: project, created_at: 20.days.ago).tap do |issue| + issue.metrics.update!(first_mentioned_in_commit_at: 10.days.ago) + end + end + + let_it_be(:issue_2) do + # Duration: 5 days + create(:issue, project: project, created_at: 20.days.ago).tap do |issue| + issue.metrics.update!(first_mentioned_in_commit_at: 15.days.ago) + end + end + + let(:stage) do + build( + :cycle_analytics_project_stage, + start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::IssueCreated.identifier, + end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::IssueFirstMentionedInCommit.identifier, + project: project + ) + end + + let(:query) { Issue.joins(:metrics).in_projects(project.id) } + + around do |example| + freeze_time { example.run } + end + + subject(:average) { described_class.new(stage: stage, query: query) } + + describe '#seconds' do + subject(:average_duration_in_seconds) { average.seconds } + + context 'when no results' do + let(:query) { Issue.none } + + it { is_expected.to eq(nil) } + end + + context 'returns the average duration in seconds' do + it { is_expected.to be_within(0.5).of(7.5.days.to_f) } + end + end + + describe '#days' do + subject(:average_duration_in_days) { average.days } + + context 'when no results' do + let(:query) { Issue.none } + + it { is_expected.to eq(nil) } + end + + context 'returns the average duration in days' do + it { is_expected.to be_within(0.01).of(7.5) } + end + end +end