Commit 664719f1 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'mf-group-coverage-data-download-frontend' into 'master'

Add group code coverage download button

See merge request gitlab-org/gitlab!37853
parents aeb754af a32b8a88
......@@ -740,6 +740,12 @@ and issues) performed by your group members.
With [GitLab Issue Analytics](issues_analytics/index.md), you can see a bar chart of the number of issues created each month in your groups.
## Repositories analytics **(PREMIUM)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/215104) in [GitLab Premium](https://about.gitlab.com/pricing/) 13.4.
With [GitLab Repositories Analytics](repositories_analytics/index.md), you can download a CSV of the latest coverage data for all the projects in your group.
## Dependency Proxy **(PREMIUM)**
Use GitLab as a [dependency proxy](../packages/dependency_proxy/index.md) for upstream Docker images.
......
---
type: reference
stage: Verify
group: Analytics
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
---
# Repositories Analytics **(PREMIUM)**
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/215104) in [GitLab Premium](https://about.gitlab.com/pricing/) 13.4.
> - It's [deployed behind a feature flag](../../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-repositories-analytics). **(CORE ONLY)**
CAUTION: **Warning:**
This feature might not be available to you. Check the **version history** note above for details.
To get a CSV of the code coverage data for all of the projects in your group, go to your group's **Analytics > CI/CD** page, and click **Download historic test coverage data (.csv)**.
For each day that a coverage report was generated by a job in a project's pipeline, there will be a row in the CSV which includes:
- The date when the coverage job ran
- The name of the job that generated the coverage report
- The name of the project
- The coverage value
If the project's code coverage was calculated more than once in a day, we will take the last value from that day.
## Enable or disable Repositories Analytics **(CORE ONLY)**
Repositories Analytics 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 opt to disable it.
To enable it:
```ruby
Feature.enable(:group_coverage_reports)
```
To disable it:
```ruby
Feature.disable(:group_coverage_reports)
```
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X`.
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->
# frozen_string_literal: true
class Groups::Analytics::RepositoryAnalyticsController < Groups::Analytics::ApplicationController
check_feature_flag Gitlab::Analytics::GROUP_COVERAGE_REPORTS_FEATURE_FLAG
layout 'group'
before_action :load_group
before_action -> { check_feature_availability!(:group_repository_analytics) }
before_action -> { authorize_view_by_action!(:read_group_repository_analytics) }
def show
end
end
......@@ -18,6 +18,7 @@ module EE
override :group_analytics_navbar_links
def group_analytics_navbar_links(group, current_user)
super + [
group_repository_analytics_navbar_link(group, current_user),
contribution_analytics_navbar_link(group, current_user),
group_insights_navbar_link(group, current_user),
issues_analytics_navbar_link(group, current_user),
......@@ -114,6 +115,17 @@ module EE
)
end
def group_repository_analytics_navbar_link(group, current_user)
return unless ::Gitlab::Analytics.group_coverage_reports_enabled?
return unless group_sidebar_link?(:repository_analytics)
navbar_sub_item(
title: _('Repositories'),
path: 'groups/analytics/repository_analytics#show',
link: group_analytics_repository_analytics_path(group)
)
end
def insights_navbar_link(project, current_user)
return unless project_nav_tab?(:project_insights)
......
......@@ -118,12 +118,10 @@ module EE
def get_group_sidebar_links
links = super
if can?(current_user, :read_group_cycle_analytics, @group)
links << :cycle_analytics
end
resources = [:cycle_analytics, :merge_request_analytics, :repository_analytics]
if can?(current_user, :read_group_merge_request_analytics, @group)
links << :merge_request_analytics
links += resources.select do |resource|
can?(current_user, "read_group_#{resource}".to_sym, @group)
end
if can?(current_user, :read_group_contribution_analytics, @group) || show_promotions?
......
......@@ -83,6 +83,7 @@ class License < ApplicationRecord
group_ip_restriction
group_merge_request_analytics
group_project_templates
group_repository_analytics
group_saml
issues_analytics
jira_issues_integration
......
......@@ -25,6 +25,10 @@ module EE
@subject.feature_available?(:group_merge_request_analytics)
end
condition(:group_repository_analytics_available) do
@subject.feature_available?(:group_repository_analytics)
end
condition(:group_activity_analytics_available) do
@subject.feature_available?(:group_activity_analytics) && ::Feature.enabled?(:group_activity_analytics, @subject, default_enabled: true)
end
......@@ -131,6 +135,9 @@ module EE
rule { has_access & group_activity_analytics_available }
.enable :read_group_activity_analytics
rule { has_access & group_repository_analytics_available }
.enable :read_group_repository_analytics
rule { reporter & group_merge_request_analytics_available }
.enable :read_group_merge_request_analytics
......
- page_title _("Repositories Analytics")
.mb-3.border-bottom
%h3
= _("Repositories Analytics")
.gl-display-flex.gl-justify-content-space-between.gl-align-items-center
%h4.sub-header
= _("RepositoriesAnalytics|Test Code Coverage")
= link_to _("RepositoriesAnalytics|Download historic test coverage data (.csv)"), group_analytics_coverage_reports_path(@group, format: :csv, ref_path: "refs/heads/master", start_date: Date.today - 1.year, end_date: Date.today),
rel: 'nofollow', download: '', method: :get, class: 'gl-button btn-sm'
---
title: Add group code coverage download button
merge_request: 37853
author:
type: added
......@@ -26,6 +26,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
resource :productivity_analytics, only: :show, constraints: -> (req) { Gitlab::Analytics.productivity_analytics_enabled? }
resources :coverage_reports, only: :index, constraints: -> (req) { Gitlab::Analytics.group_coverage_reports_enabled? }
resource :merge_request_analytics, only: :show, constraints: -> (req) { Gitlab::Analytics.group_merge_request_analytics_enabled? }
resource :repository_analytics, only: :show, constraints: -> (req) { Gitlab::Analytics.group_coverage_reports_enabled? }
feature_default_enabled = Gitlab::Analytics.feature_enabled_by_default?(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG)
constrainer = ::Constraints::FeatureConstrainer.new(Gitlab::Analytics::CYCLE_ANALYTICS_FEATURE_FLAG, default_enabled: feature_default_enabled)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::Analytics::RepositoryAnalyticsController do
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:feature_flag_name) { Gitlab::Analytics::GROUP_COVERAGE_REPORTS_FEATURE_FLAG }
let_it_be(:feature_name) { :group_repository_analytics }
before do
sign_in(current_user)
stub_feature_flags(feature_flag_name => true)
stub_licensed_features(feature_name => true)
end
describe 'GET show' do
subject { get :show, params: { group_id: group } }
before do
group.add_guest(current_user)
end
specify { is_expected.to have_gitlab_http_status(:success) }
context 'when license is missing' do
before do
stub_licensed_features(feature_name => false)
end
it { is_expected.to have_gitlab_http_status(:forbidden) }
end
context 'when feature flag is off' do
before do
stub_feature_flags(feature_flag_name => false)
end
it { is_expected.to have_gitlab_http_status(:not_found) }
end
context 'when the user has no access to the group' do
before do
current_user.group_members.delete_all
end
it { is_expected.to have_gitlab_http_status(:forbidden) }
end
end
end
......@@ -194,6 +194,26 @@ RSpec.describe GroupPolicy do
it { is_expected.not_to be_allowed(:read_group_activity_analytics) }
end
context 'when group repository analytics is available' do
let(:current_user) { guest }
before do
stub_licensed_features(group_repository_analytics: true)
end
it { is_expected.to be_allowed(:read_group_repository_analytics) }
end
context 'when group repository analytics is not available' do
let(:current_user) { guest }
before do
stub_licensed_features(group_repository_analytics: false)
end
it { is_expected.not_to be_allowed(:read_group_repository_analytics) }
end
context 'when timelogs report feature is enabled' do
before do
stub_licensed_features(group_timelogs: true)
......
......@@ -21201,6 +21201,15 @@ msgstr ""
msgid "Repositories"
msgstr ""
msgid "Repositories Analytics"
msgstr ""
msgid "RepositoriesAnalytics|Download historic test coverage data (.csv)"
msgstr ""
msgid "RepositoriesAnalytics|Test Code Coverage"
msgstr ""
msgid "Repository"
msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment