From 2ece4432bca46f9a4e3cac3efac0590b735efbd0 Mon Sep 17 00:00:00 2001 From: Gabriel Mazetto <gabriel@gitlab.com> Date: Mon, 8 Jul 2024 17:14:06 +0200 Subject: [PATCH] Use `GITLAB_PATH` instead of `APP_PATH` and expose it into context --- bin/gitlab-backup-cli | 2 +- gems/gitlab-backup-cli/bin/console | 2 ++ gems/gitlab-backup-cli/lib/gitlab/backup/cli.rb | 2 +- .../lib/gitlab/backup/cli/source_context.rb | 8 ++++++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/gitlab-backup-cli b/bin/gitlab-backup-cli index 4037684be07d6..6ddfd5d49d025 100755 --- a/bin/gitlab-backup-cli +++ b/bin/gitlab-backup-cli @@ -5,7 +5,7 @@ $:.unshift File.expand_path("../../lib", __FILE__) # We require APP_PATH when the rails environment is required only, # this allows for faster CLI execution when rails is not needed -APP_PATH = File.expand_path('../config/application', __dir__) +GITLAB_PATH = File.expand_path('../', __dir__) require_relative '../config/boot' diff --git a/gems/gitlab-backup-cli/bin/console b/gems/gitlab-backup-cli/bin/console index 3aa2eb40f2184..0cd1d6c57f511 100755 --- a/gems/gitlab-backup-cli/bin/console +++ b/gems/gitlab-backup-cli/bin/console @@ -7,5 +7,7 @@ require "gitlab/backup/cli" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. +GITLAB_PATH = File.expand_path(File.join(__dir__, '../../../')) + require "irb" IRB.start(__FILE__) diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli.rb index 4679c5da7aae9..de526fd33af08 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli.rb @@ -27,7 +27,7 @@ module Cli Error = Class.new(StandardError) def self.rails_environment! - require APP_PATH + require File.join(GITLAB_PATH, 'config/application') Rails.application.require_environment! Rails.application.autoloaders diff --git a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb index 4299f2eb2dd3c..67ad708189992 100644 --- a/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb +++ b/gems/gitlab-backup-cli/lib/gitlab/backup/cli/source_context.rb @@ -76,6 +76,14 @@ def env @env ||= ActiveSupport::EnvironmentInquirer.new( ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development") end + + private + + def gitlab_basedir + return GITLAB_PATH if GITLAB_PATH + + raise ::Gitlab::Backup::Cli::Error, 'GITLAB_PATH is missing' + end end end end -- GitLab