Sha256: 75e63b8842ea326ab630e94252309d11906c4b4a30ea53b4cfe7e40ee54688d8

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Sentry
  # @api private
  class ReleaseDetector
    class << self
      def detect_release(project_root:, running_on_heroku:)
        detect_release_from_env ||
        detect_release_from_git ||
        detect_release_from_capistrano(project_root) ||
        detect_release_from_heroku(running_on_heroku)
      end

      def detect_release_from_heroku(running_on_heroku)
        return unless running_on_heroku
        ENV['HEROKU_SLUG_COMMIT']
      end

      def detect_release_from_capistrano(project_root)
        revision_file = File.join(project_root, 'REVISION')
        revision_log = File.join(project_root, '..', 'revisions.log')

        if File.exist?(revision_file)
          File.read(revision_file).strip
        elsif File.exist?(revision_log)
          File.open(revision_log).to_a.last.strip.sub(/.*as release ([0-9]+).*/, '\1')
        end
      end

      def detect_release_from_git
        Sentry.sys_command("git rev-parse --short HEAD") if File.directory?(".git")
      end

      def detect_release_from_env
        ENV['SENTRY_RELEASE']
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
sentry-ruby-5.13.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.13.0 lib/sentry/release_detector.rb
sentry-ruby-5.12.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.12.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.11.0 lib/sentry/release_detector.rb
sentry-ruby-5.11.0 lib/sentry/release_detector.rb
sentry-ruby-5.10.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.10.0 lib/sentry/release_detector.rb
sentry-ruby-5.9.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.9.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.8.0 lib/sentry/release_detector.rb
sentry-ruby-5.8.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.7.0 lib/sentry/release_detector.rb
sentry-ruby-5.7.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.6.0 lib/sentry/release_detector.rb
sentry-ruby-5.6.0 lib/sentry/release_detector.rb
sentry-ruby-core-5.5.0 lib/sentry/release_detector.rb
sentry-ruby-5.5.0 lib/sentry/release_detector.rb
sentry-ruby-5.4.2 lib/sentry/release_detector.rb
sentry-ruby-core-5.4.2 lib/sentry/release_detector.rb