Skip to content
代码片段 群组 项目
未验证 提交 ca99f083 编辑于 作者: Thong Kuah's avatar Thong Kuah 提交者: GitLab
浏览文件

Merge branch 'jtucker/dump-nav-rake-task' into 'master'

[#442753] Add rake task to dump nav structure as YAML

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/148204



Merged-by: default avatarThong Kuah <tkuah@gitlab.com>
Approved-by: default avatarThong Kuah <tkuah@gitlab.com>
Co-authored-by: default avatarJeff Tucker <jtucker@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -566,3 +566,16 @@ This task clones the remote repository, recursively walks the file system lookin ...@@ -566,3 +566,16 @@ This task clones the remote repository, recursively walks the file system lookin
ending in `.pub`, parses those files as SSH public keys, and then adds the public key fingerprints ending in `.pub`, parses those files as SSH public keys, and then adds the public key fingerprints
to `output_file`. The contents of `config/security/banned_ssh_keys.yml` is read by GitLab and kept to `output_file`. The contents of `config/security/banned_ssh_keys.yml` is read by GitLab and kept
in memory. It is not recommended to increase the size of this file beyond 1 megabyte in size. in memory. It is not recommended to increase the size of this file beyond 1 megabyte in size.
## Output current navigation structure to YAML
_This task relies on your current environment setup (licensing, feature flags, projects/groups), so output may vary from run-to-run or environment-to-environment. We may look to standardize output in a future iteration._
Product, UX, and tech writing need a way to audit the entire GitLab navigation,
yet may not be comfortable directly reviewing the code in `lib/sidebars`. You
can dump the entire nav structure to YAML via the `gitlab:nav:dump_structure`
Rake task:
```shell
bundle exec rake gitlab:nav:dump_structure
```
# frozen_string_literal: true
return if Rails.env.production?
namespace :gitlab do
namespace :nav do
desc "GitLab | Nav | Dump the complete navigation structure for all navigation contexts"
task :dump_structure, [] => :gitlab_environment do
dumper = Tasks::Gitlab::Nav::DumpStructure.new
puts dumper.dump
end
end
end
# frozen_string_literal: true
module Tasks
module Gitlab
module Nav
class DumpStructure
attr_accessor :context_defaults
def initialize
@context_defaults = {
current_user: User.first,
is_super_sidebar: true,
# Turn features on that impact the list of items rendered
can_view_pipeline_editor: true,
learn_gitlab_enabled: true,
show_discover_group_security: true,
show_discover_project_security: true,
show_security_dashboard: true,
# Turn features off that do not add/remove items
show_cluster_hint: false,
show_promotions: false,
current_ref: 'master'
}
end
def panels
panels = []
panels << Sidebars::UserProfile::Panel.new(Sidebars::Context.new(
container: User.first,
**@context_defaults
))
panels << Sidebars::UserSettings::Panel.new(Sidebars::Context.new(
container: User.first,
**@context_defaults
))
panels << Sidebars::YourWork::Panel.new(Sidebars::Context.new(
container: User.first,
**@context_defaults
))
panels << Sidebars::Projects::SuperSidebarPanel.new(Sidebars::Projects::Context.new(
container: Project.first,
**@context_defaults
))
panels << Sidebars::Groups::SuperSidebarPanel.new(Sidebars::Groups::Context.new(
container: Group.first,
**@context_defaults
))
panels << Sidebars::Organizations::Panel.new(Sidebars::Context.new(
container: Organizations::Organization.first,
**@context_defaults
))
panels << Sidebars::Admin::Panel.new(Sidebars::Context.new(
container: nil,
**@context_defaults
))
panels << Sidebars::Explore::Panel.new(Sidebars::Context.new(
container: nil,
**@context_defaults
))
panels
end
def current_time
Time.now.utc.iso8601
end
def current_sha
`git rev-parse --short HEAD`.strip
end
def dump
contexts = panels.map do |panel|
{
title: panel.aria_label,
items: panel.super_sidebar_menu_items
}
end
# Recurse through structure to drop info we don't need
clean_keys!(contexts)
YAML.dump({
generated_at: current_time,
commit_sha: current_sha,
contexts: contexts
}.deep_stringify_keys)
end
private
def clean_keys!(entries)
entries.each do |entry|
clean_keys!(entry[:items]) if entry[:items]
entry[:id] = entry[:id].to_s if entry[:id]
entry.slice!(:id, :title, :icon, :link, :items)
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'gitlab:nav:dump_structure', :silence_stdout, feature_category: :navigation do
let!(:user) { create(:user) }
before do
# Build out scaffold records required for rake task
create(:project)
create(:group)
create(:organization)
Rake.application.rake_require 'tasks/gitlab/nav/dump_structure'
end
it 'outputs YAML describing the current nav structure' do
# Sample items that _hopefully_ won't change very often.
expected = {
"generated_at" => an_instance_of(String),
"commit_sha" => an_instance_of(String),
"contexts" => a_collection_including(a_hash_including({
"title" => "User profile navigation",
"items" => a_collection_including(a_hash_including({
"id" => "activity_menu",
"title" => "Activity",
"icon" => "history",
"link" => "/users/#{user.username}/activity"
}))
}))
}
expect(YAML).to receive(:dump).with(expected)
run_rake_task('gitlab:nav:dump_structure')
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册