From 2045a93fb3b4e5f726280c5186c198696309e5de Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 2 Nov 2023 11:34:10 +1100 Subject: [PATCH 1/5] Add migration submodule --- .gitmodules | 3 +++ vendor/migration | 1 + 2 files changed, 4 insertions(+) create mode 160000 vendor/migration diff --git a/.gitmodules b/.gitmodules index 20e0b98686..a3c5d9a4dd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/emojis"] path = vendor/emojis url = https://github.com/buildkite/emojis.git +[submodule "vendor/migration"] + path = vendor/migration + url = https://github.com/buildkite/migration diff --git a/vendor/migration b/vendor/migration new file mode 160000 index 0000000000..c9c42116eb --- /dev/null +++ b/vendor/migration @@ -0,0 +1 @@ +Subproject commit c9c42116eb9253b2a6d8d4e3674805c07b095205 From fe3f8a1f9fcd09c7a36ff544e67e742c0ed2459d Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 2 Nov 2023 12:06:51 +1100 Subject: [PATCH 2/5] Add parslet gem (migration dependency) --- Gemfile | 2 ++ Gemfile.lock | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index 9f6ac4c776..d8605732c6 100644 --- a/Gemfile +++ b/Gemfile @@ -79,3 +79,5 @@ end group :test do gem "buildkite-test_collector" end + +gem "parslet" diff --git a/Gemfile.lock b/Gemfile.lock index c5a439b522..ed88c47af4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,7 @@ GEM nokogiri (1.15.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) + parslet (2.0.0) pry (0.14.1) coderay (~> 1.1) method_source (~> 1.0) @@ -175,6 +176,7 @@ DEPENDENCIES graphql-client lograge matrix + parslet pry puma railties (~> 6.0) From 3a4c465ef2d52ed61189d378cbf310456445fe31 Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 2 Nov 2023 12:08:11 +1100 Subject: [PATCH 3/5] Mount migration tool under /docs/migrate --- app/controllers/migration_controller.rb | 20 +++ app/views/migrate.html.erb | 181 ++++++++++++++++++++++++ config/initializers/migration.rb | 2 + config/routes.rb | 4 + 4 files changed, 207 insertions(+) create mode 100644 app/controllers/migration_controller.rb create mode 100644 app/views/migrate.html.erb create mode 100644 config/initializers/migration.rb diff --git a/app/controllers/migration_controller.rb b/app/controllers/migration_controller.rb new file mode 100644 index 0000000000..9c966b5c22 --- /dev/null +++ b/app/controllers/migration_controller.rb @@ -0,0 +1,20 @@ +class MigrationController < ApplicationController + skip_forgery_protection + + def show + @nav = default_nav + + render template: "migrate", layout: "homepage" + end + + def migrate + # Some request path rewriting for the compat server to slot in. + request.env["REQUEST_PATH"] = "/" + request.env["REQUEST_URI"] = "/" + request.env["PATH_INFO"] = "/" + + res = BK::Compat::Server.new.call(request.env) + + render body: res[2].string, status: res[0], content_type: res[1]["content-type"] + end +end diff --git a/app/views/migrate.html.erb b/app/views/migrate.html.erb new file mode 100644 index 0000000000..f6e2eb90c8 --- /dev/null +++ b/app/views/migrate.html.erb @@ -0,0 +1,181 @@ + + + + Buildkite-ification! + + + +
+
+
+ + +
+
+ +
+
+
+ + + + diff --git a/config/initializers/migration.rb b/config/initializers/migration.rb new file mode 100644 index 0000000000..0756a728e5 --- /dev/null +++ b/config/initializers/migration.rb @@ -0,0 +1,2 @@ +require Rails.root.join('vendor/migration/app/lib/bk/compat').to_s +require Rails.root.join('vendor/migration/app/lib/bk/compat/server').to_s diff --git a/config/routes.rb b/config/routes.rb index 95b36f42df..020374fbcd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -143,6 +143,10 @@ # Homepage get "/docs" => "pages#index", as: :home_page + # Hosted migration/transform tool + get "/docs/migrate" => "migration#show" + post "/docs/migrate" => "migration#migrate", as: :migrate + # All other standard docs pages get "/docs/*path" => "pages#show", as: :docs_page From 3626e460c1fb0e45dc09459cbab49c80606f725b Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 2 Nov 2023 12:20:10 +1100 Subject: [PATCH 4/5] Remove html/body tags --- app/views/migrate.html.erb | 354 ++++++++++++++++++------------------- 1 file changed, 174 insertions(+), 180 deletions(-) diff --git a/app/views/migrate.html.erb b/app/views/migrate.html.erb index f6e2eb90c8..ab2369446c 100644 --- a/app/views/migrate.html.erb +++ b/app/views/migrate.html.erb @@ -1,181 +1,175 @@ - - - - Buildkite-ification! - - - -
-
-
- - -
-
- -
-
+ + + +
+
+
+ +
- - - - +
+ +
+
+
+ + From b0385bb8e8f6f93a947e6c15358db04699dd03c0 Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Thu, 2 Nov 2023 12:20:43 +1100 Subject: [PATCH 5/5] Ignore orphaned nav items Returning nil rather than erroring seems totally fine. --- app/models/nav.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/models/nav.rb b/app/models/nav.rb index 7c74adda07..ddcba649b5 100644 --- a/app/models/nav.rb +++ b/app/models/nav.rb @@ -15,12 +15,7 @@ def current_item_root(request) # Returns the current nav item def current_item(request) - return nil if request.path == "/docs" - - item = route_map[request.path.sub("/docs/", "")] - raise ActionController::RoutingError.new("Missing navigation for #{request.path}") unless item - - item + route_map[request.path.sub("/docs/", "")] end # Returns a hash of routes, indexed by path