Commit fe145c6f authored by Zhu Shuang's avatar Zhu Shuang Committed by Thong Kuah

Move COM_URL related variables to a module

parent 2eb9b6eb
......@@ -19,7 +19,7 @@ module VersionCheckHelper
end
def source_host_url
Gitlab::COM_URL
Gitlab::Saas.com_url
end
def source_code_group
......
......@@ -25,7 +25,7 @@ module BulkImports
delegate :query, :parse, :execute, to: :client
def initialize(url: Gitlab::COM_URL, token: nil)
def initialize(url: Gitlab::Saas.com_url, token: nil)
@url = Gitlab::Utils.append_path(url, '/api/graphql')
@token = token
@client = Graphlient::Client.new(
......
......@@ -39,17 +39,14 @@ module Gitlab
end
end
COM_URL = 'https://gitlab.com'
STAGING_COM_URL = 'https://staging.gitlab.com'
APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}.freeze
SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}.freeze
VERSION = File.read(root.join("VERSION")).strip.freeze
INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
HTTP_PROXY_ENV_VARS = %w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY).freeze
def self.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
Gitlab.config.gitlab.url == Gitlab::Saas.com_url || gl_subdomain?
end
def self.com
......@@ -57,7 +54,7 @@ module Gitlab
end
def self.staging?
Gitlab.config.gitlab.url == STAGING_COM_URL
Gitlab.config.gitlab.url == Gitlab::Saas.staging_com_url
end
def self.canary?
......@@ -73,11 +70,11 @@ module Gitlab
end
def self.org?
Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
Gitlab.config.gitlab.url == Gitlab::Saas.dev_url
end
def self.gl_subdomain?
SUBDOMAIN_REGEX === Gitlab.config.gitlab.url
Gitlab::Saas.subdomain_regex === Gitlab.config.gitlab.url
end
def self.dev_env_org_or_com?
......
......@@ -43,7 +43,7 @@ module Gitlab
survey_id: EASE_SCORE_SURVEY_ID
}
"#{Gitlab::COM_URL}/-/survey_responses?#{params.to_query}"
"#{Gitlab::Saas.com_url}/-/survey_responses?#{params.to_query}"
end
def feedback_ratings(rating)
......
# frozen_string_literal: true
# This module is used to return various SaaS related configurations
# which may be overridden in other variants of GitLab
module Gitlab
module Saas
def self.com_url
'https://gitlab.com'
end
def self.staging_com_url
'https://staging.gitlab.com'
end
def self.subdomain_regex
%r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}.freeze
end
def self.dev_url
'https://dev.gitlab.org'
end
end
end
Gitlab::Saas.prepend_mod
......@@ -22,7 +22,7 @@ RSpec.describe Gitlab::Tracking::StandardContext do
context 'staging' do
before do
stub_config_setting(url: 'https://staging.gitlab.com')
stub_config_setting(url: Gitlab::Saas.staging_com_url)
end
include_examples 'contains environment', 'staging'
......@@ -30,7 +30,7 @@ RSpec.describe Gitlab::Tracking::StandardContext do
context 'production' do
before do
stub_config_setting(url: 'https://gitlab.com')
stub_config_setting(url: Gitlab::Saas.com_url)
end
include_examples 'contains environment', 'production'
......@@ -38,7 +38,7 @@ RSpec.describe Gitlab::Tracking::StandardContext do
context 'org' do
before do
stub_config_setting(url: 'https://dev.gitlab.org')
stub_config_setting(url: Gitlab::Saas.dev_url)
end
include_examples 'contains environment', 'org'
......
......@@ -70,20 +70,21 @@ RSpec.describe Gitlab do
end
describe '.com?' do
it 'is true when on GitLab.com' do
stub_config_setting(url: 'https://gitlab.com')
it "is true when on #{Gitlab::Saas.com_url}" do
stub_config_setting(url: Gitlab::Saas.com_url)
expect(described_class.com?).to eq true
end
it 'is true when on staging' do
stub_config_setting(url: 'https://staging.gitlab.com')
it "is true when on #{Gitlab::Saas.staging_com_url}" do
stub_config_setting(url: Gitlab::Saas.staging_com_url)
expect(described_class.com?).to eq true
end
it 'is true when on other gitlab subdomain' do
stub_config_setting(url: 'https://example.gitlab.com')
url_with_subdomain = Gitlab::Saas.com_url.gsub('https://', 'https://example.')
stub_config_setting(url: url_with_subdomain)
expect(described_class.com?).to eq true
end
......@@ -118,14 +119,14 @@ RSpec.describe Gitlab do
describe '.staging?' do
subject { described_class.staging? }
it 'is false when on GitLab.com' do
stub_config_setting(url: 'https://gitlab.com')
it "is false when on #{Gitlab::Saas.com_url}" do
stub_config_setting(url: Gitlab::Saas.com_url)
expect(subject).to eq false
end
it 'is true when on staging' do
stub_config_setting(url: 'https://staging.gitlab.com')
it "is true when on #{Gitlab::Saas.staging_com_url}" do
stub_config_setting(url: Gitlab::Saas.staging_com_url)
expect(subject).to eq true
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