gitlab.rb 1.77 KB
Newer Older
1 2
# frozen_string_literal: true

3
require_dependency 'gitlab/popen'
4 5

module Gitlab
6 7 8 9
  def self.root
    Pathname.new(File.expand_path('..', __dir__))
  end

10 11 12 13 14 15 16 17
  def self.version_info
    Gitlab::VersionInfo.parse(Gitlab::VERSION)
  end

  def self.pre_release?
    VERSION.include?('pre')
  end

18 19 20 21
  def self.config
    Settings
  end

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
  def self.revision
    @_revision ||= begin
      if File.exist?(root.join("REVISION"))
        File.read(root.join("REVISION")).strip.freeze
      else
        result = Gitlab::Popen.popen_with_detail(%W[#{config.git.bin_path} log --pretty=format:%h -n 1])

        if result.status.success?
          result.stdout.chomp.freeze
        else
          "Unknown".freeze
        end
      end
    end
  end

Rémy Coutable's avatar
Rémy Coutable committed
38 39 40 41
  COM_URL = 'https://gitlab.com'.freeze
  APP_DIRS_PATTERN = %r{^/?(app|config|ee|lib|spec|\(\w*\))}
  SUBDOMAIN_REGEX = %r{\Ahttps://[a-z0-9]+\.gitlab\.com\z}
  VERSION = File.read(root.join("VERSION")).strip.freeze
42
  INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
43
  HTTP_PROXY_ENV_VARS = %w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY).freeze
Rémy Coutable's avatar
Rémy Coutable committed
44

45
  def self.com?
46 47
    # Check `gl_subdomain?` as well to keep parity with gitlab.com
    Gitlab.config.gitlab.url == COM_URL || gl_subdomain?
48 49
  end

50 51 52 53
  def self.org?
    Gitlab.config.gitlab.url == 'https://dev.gitlab.org'
  end

54 55
  def self.gl_subdomain?
    SUBDOMAIN_REGEX === Gitlab.config.gitlab.url
56
  end
57

58
  def self.dev_env_or_com?
59
    Rails.env.development? || org? || com?
60
  end
61

62 63 64 65
  def self.ee?
    Object.const_defined?(:License)
  end

66 67 68 69
  def self.http_proxy_env?
    HTTP_PROXY_ENV_VARS.any? { |name| ENV[name] }
  end

70 71 72 73 74 75 76
  def self.process_name
    return 'sidekiq' if Sidekiq.server?
    return 'console' if defined?(Rails::Console)
    return 'test' if Rails.env.test?

    'web'
  end
77
end