Commit 24818198 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents b18a2d3c 6ab49d29
......@@ -488,7 +488,7 @@ gem 'flipper', '~> 0.21.0'
gem 'flipper-active_record', '~> 0.21.0'
gem 'flipper-active_support_cache_store', '~> 0.21.0'
gem 'unleash', '~> 3.2.2'
gem 'gitlab-experiment', '~> 0.6.2'
gem 'gitlab-experiment', '~> 0.6.3'
# Structured logging
gem 'lograge', '~> 0.5'
......
......@@ -463,7 +463,7 @@ GEM
gitlab-dangerfiles (2.3.0)
danger (>= 8.3.1)
danger-gitlab (>= 8.0.0)
gitlab-experiment (0.6.2)
gitlab-experiment (0.6.3)
activesupport (>= 3.0)
request_store (>= 1.0)
scientist (~> 1.6, >= 1.6.0)
......@@ -1468,7 +1468,7 @@ DEPENDENCIES
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-dangerfiles (~> 2.3.0)
gitlab-experiment (~> 0.6.2)
gitlab-experiment (~> 0.6.3)
gitlab-fog-azure-rm (~> 1.1.1)
gitlab-labkit (~> 0.21.0)
gitlab-license (~> 2.0)
......
- if group_sidebar_link?(:runners)
= nav_link(path: 'groups/runners#index') do
= link_to group_runners_path(@group), title: _('CI/CD'), class: 'has-sub-items' do
.nav-icon-container
= sprite_icon('rocket')
%span.nav-item-name
= _('CI/CD')
%ul.sidebar-sub-level-items
= nav_link(path: 'groups/runners#index', html_options: { class: "fly-out-top-item" } ) do
= link_to group_runners_path(@group), title: _('CI/CD') do
%strong.fly-out-top-item-name
= _('CI/CD')
%li.divider.fly-out-top-item
= nav_link(path: 'groups/runners#index') do
= link_to group_runners_path(@group), title: s_('Runners|Runners') do
%span= s_('Runners|Runners')
- if group_sidebar_link?(:kubernetes)
= nav_link(controller: [:clusters]) do
= link_to group_clusters_path(@group) do
......
......@@ -859,9 +859,13 @@ Example response:
Get the counts (same as in top right menu) of the currently signed in user.
| Attribute | Type | Description |
| ---------------- | ------ | ------------------------------------------------------------ |
| `merge_requests` | number | Merge requests that are active and assigned to current user. |
| Attribute | Type | Description |
| --------------------------------- | ------ | ---------------------------------------------------------------------------- |
| `assigned_issues` | number | Number of issues that are open and assigned to the current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66909) in GitLab 14.2. |
| `assigned_merge_requests` | number | Number of merge requests that are active and assigned to the current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. |
| `merge_requests` | number | [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. Equivalent to and replaced by `assigned_merge_requests`. |
| `review_requested_merge_requests` | number | Number of merge requests that the current user has been requested to review. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50026) in GitLab 13.8. |
| `todos` | number | Number of pending to-do items for current user. [Added](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66909) in GitLab 14.2. |
```plaintext
GET /user_counts
......@@ -875,7 +879,11 @@ Example response:
```json
{
"merge_requests": 4
"merge_requests": 4,
"assigned_issues": 15,
"assigned_merge_requests": 11,
"review_requested_merge_requests": 0,
"todos": 1
}
```
......
......@@ -6,15 +6,17 @@ module API
resource :user_counts do
desc 'Return the user specific counts' do
detail 'Open MR Count'
detail 'Assigned open issues, assigned MRs and pending todos count'
end
get do
unauthorized! unless current_user
{
merge_requests: current_user.assigned_open_merge_requests_count, # @deprecated
assigned_issues: current_user.assigned_open_issues_count,
assigned_merge_requests: current_user.assigned_open_merge_requests_count,
review_requested_merge_requests: current_user.review_requested_open_merge_requests_count
review_requested_merge_requests: current_user.review_requested_open_merge_requests_count,
todos: current_user.todos_pending_count
}
end
end
......
# frozen_string_literal: true
module Sidebars
module Groups
module Menus
class CiCdMenu < ::Sidebars::Menu
override :configure_menu_items
def configure_menu_items
add_item(runners_menu_item)
true
end
override :link
def link
renderable_items.first.link
end
override :title
def title
_('CI/CD')
end
override :sprite_icon
def sprite_icon
'rocket'
end
private
def runners_menu_item
return ::Sidebars::NilMenuItem.new(item_id: :runners) unless show_runners?
::Sidebars::MenuItem.new(
title: _('Runners'),
link: group_runners_path(context.group),
active_routes: { path: 'groups/runners#index' },
item_id: :runners
)
end
# TODO Proper policies, such as `read_group_runners`, should be implemented per
# See https://gitlab.com/gitlab-org/gitlab/-/issues/334802
def show_runners?
can?(context.current_user, :admin_group, context.group) &&
Feature.enabled?(:runner_list_group_view_vue_ui, context.group, default_enabled: :yaml)
end
end
end
end
end
......@@ -10,6 +10,7 @@ module Sidebars
add_menu(Sidebars::Groups::Menus::GroupInformationMenu.new(context))
add_menu(Sidebars::Groups::Menus::IssuesMenu.new(context))
add_menu(Sidebars::Groups::Menus::MergeRequestsMenu.new(context))
add_menu(Sidebars::Groups::Menus::CiCdMenu.new(context))
end
override :render_raw_menus_partial
......
......@@ -236,6 +236,11 @@ RSpec.describe ApplicationExperiment, :experiment do
expect(subject.process_redirect_url(url)).to be_nil
end
end
it "generates the correct urls based on where the engine was mounted" do
url = Rails.application.routes.url_helpers.experiment_redirect_url(subject, url: 'https://docs.gitlab.com')
expect(url).to include("/-/experiment/namespaced%2Fstub:#{subject.context.key}?https://docs.gitlab.com")
end
end
context "when resolving variants" do
......
......@@ -30,9 +30,9 @@ RSpec.describe NewProjectReadmeContentExperiment, :experiment do
end
it "renders redirect URLs" do
expect(markdown).to include(
Rails.application.routes.url_helpers.experiment_redirect_url(subject, url: initial_url)
)
url = Rails.application.routes.url_helpers.experiment_redirect_url(subject, url: initial_url)
expect(url).to include("/-/experiment/#{subject.to_param}?")
expect(markdown).to include(url)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Sidebars::Groups::Menus::CiCdMenu do
let_it_be(:owner) { create(:user) }
let_it_be(:root_group) do
build(:group, :private).tap do |g|
g.add_owner(owner)
end
end
let(:group) { root_group }
let(:user) { owner }
let(:context) { Sidebars::Groups::Context.new(current_user: user, container: group) }
describe 'Menu Items' do
subject { described_class.new(context).renderable_items.index { |e| e.item_id == item_id } }
describe 'Runners' do
let(:item_id) { :runners }
specify { is_expected.not_to be_nil }
describe 'when feature flag :runner_list_group_view_vue_ui is disabled' do
before do
stub_feature_flags(runner_list_group_view_vue_ui: false)
end
specify { is_expected.to be_nil }
end
describe 'when the user does not have access' do
let(:user) { nil }
specify { is_expected.to be_nil }
end
end
end
end
......@@ -3,8 +3,10 @@
require 'spec_helper'
RSpec.describe API::UserCounts do
let(:user) { create(:user) }
let(:project) { create(:project, :public) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project, author: user, assignees: [user]) }
let_it_be(:todo) { create(:todo, :pending, user: user, project: project) }
let!(:merge_request) { create(:merge_request, :simple, author: user, assignees: [user], source_project: project, title: "Test") }
......@@ -18,22 +20,36 @@ RSpec.describe API::UserCounts do
end
context 'when authenticated' do
it 'returns open counts for current user' do
it 'returns assigned issue counts for current_user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(1)
expect(json_response['assigned_issues']).to eq(1)
end
it 'updates the mr count when a new mr is assigned' do
create(:merge_request, source_project: project, author: user, assignees: [user])
context 'merge requests' do
it 'returns assigned MR counts for current user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(1)
end
it 'updates the mr count when a new mr is assigned' do
create(:merge_request, source_project: project, author: user, assignees: [user])
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(2)
end
end
it 'returns pending todo counts for current_user' do
get api('/user_counts', user)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a Hash
expect(json_response['merge_requests']).to eq(2)
expect(json_response['todos']).to eq(1)
end
end
end
......
......@@ -3,10 +3,17 @@
require 'spec_helper'
RSpec.describe 'layouts/nav/sidebar/_group' do
let_it_be(:group) { create(:group) }
let_it_be(:owner) { create(:user) }
let_it_be(:group) do
create(:group).tap do |g|
g.add_owner(owner)
end
end
before do
assign(:group, group)
allow(view).to receive(:current_user).and_return(owner)
end
it_behaves_like 'has nav sidebar'
......@@ -79,4 +86,18 @@ RSpec.describe 'layouts/nav/sidebar/_group' do
expect(rendered).to have_css('span.badge.badge-pill.merge_counter.js-merge-counter')
end
end
describe 'CI/CD' do
it 'has a default link to the runners list path' do
render
expect(rendered).to have_link('CI/CD', href: group_runners_path(group))
end
it 'has a link to the runners list page' do
render
expect(rendered).to have_link('Runners', href: group_runners_path(group))
end
end
end
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