Sha256: b6e3745c83fc56eb7a9fd24afbdd7d86d0d0b4023e0f19624fe2ab68be52824f

Contents?: true

Size: 1.99 KB

Versions: 42

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

module AppMap
  module Metadata
    class << self
      def detect
        {
          app: AppMap.configuration.name,
          language: {
            name: 'ruby',
            engine: RUBY_ENGINE,
            version: RUBY_VERSION
          },
          client: {
            name: 'appmap',
            url: AppMap::URL,
            version: AppMap::VERSION
          }
        }.tap do |m|
          if defined?(::Rails) && defined?(::Rails.version)
            m[:frameworks] ||= []
            m[:frameworks] << {
              name: 'rails',
              version: ::Rails.version
            }
          end
          m[:git] = git_metadata if git_available
        end
      end

      protected

      def git_available
        @git_available = system('git status 2>&1 > /dev/null') if @git_available.nil?
      end

      def git_metadata
        git_repo = `git config --get remote.origin.url`.strip
        git_branch = `git rev-parse --abbrev-ref HEAD`.strip
        git_sha = `git rev-parse HEAD`.strip
        git_status = `git status -s`.split("\n").map(&:strip)
        git_last_annotated_tag = `git describe --abbrev=0 2>/dev/null`.strip
        git_last_annotated_tag = nil if git_last_annotated_tag.blank?
        git_last_tag = `git describe --abbrev=0 --tags 2>/dev/null`.strip
        git_last_tag = nil if git_last_tag.blank?
        git_commits_since_last_annotated_tag = `git describe`.strip =~ /-(\d+)-(\w+)$/[1] rescue 0 if git_last_annotated_tag
        git_commits_since_last_tag = `git describe --tags`.strip =~ /-(\d+)-(\w+)$/[1] rescue 0 if git_last_tag

        {
          repository: git_repo,
          branch: git_branch,
          commit: git_sha,
          status: git_status,
          git_last_annotated_tag: git_last_annotated_tag,
          git_last_tag: git_last_tag,
          git_commits_since_last_annotated_tag: git_commits_since_last_annotated_tag,
          git_commits_since_last_tag: git_commits_since_last_tag
        }
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
appmap-0.53.0 lib/appmap/metadata.rb
appmap-0.52.1 lib/appmap/metadata.rb
appmap-0.52.0 lib/appmap/metadata.rb
appmap-0.51.3 lib/appmap/metadata.rb
appmap-0.51.2 lib/appmap/metadata.rb
appmap-0.51.1 lib/appmap/metadata.rb
appmap-0.51.0 lib/appmap/metadata.rb
appmap-0.50.0 lib/appmap/metadata.rb
appmap-0.49.0 lib/appmap/metadata.rb
appmap-0.48.2 lib/appmap/metadata.rb
appmap-0.48.1 lib/appmap/metadata.rb
appmap-0.48.0 lib/appmap/metadata.rb
appmap-0.47.1 lib/appmap/metadata.rb
appmap-0.47.0 lib/appmap/metadata.rb
appmap-0.46.0 lib/appmap/metadata.rb
appmap-0.45.1 lib/appmap/metadata.rb
appmap-0.45.0 lib/appmap/metadata.rb
appmap-0.44.0 lib/appmap/metadata.rb
appmap-0.43.0 lib/appmap/metadata.rb
appmap-0.42.1 lib/appmap/metadata.rb