Sha256: 2a1b58763014ee4004168fe1f4b57f6649a26237d5323eba690f2d6dec8d68ac

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module CodeClimate
  module TestReporter
    class Git

      class << self
        def info
          {
            head:         `git log -1 --pretty=format:'%H'`,
            committed_at: committed_at,
            branch:       branch_from_git,
          }
        end

        def branch_from_git_or_ci
          clean_service_branch || clean_git_branch || "master"
        end

        def clean_service_branch
          ci_branch = String(Ci.service_data[:branch])
          clean = ci_branch.strip.sub(/^origin\//, "")

          clean.size > 0 ? clean : nil
        end

        def clean_git_branch
          git_branch = String(branch_from_git)
          clean = git_branch.sub(/^origin\//, "") unless git_branch.start_with?("(")

          clean.size > 0 ? clean : nil
        end

        private

        def committed_at
          committed_at = `git log -1 --pretty=format:'%ct'`
          committed_at.to_i.zero? ? nil : committed_at.to_i
        end

        def branch_from_git
          `git rev-parse --abbrev-ref HEAD`.chomp
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
codeclimate-test-reporter-0.4.3 lib/code_climate/test_reporter/git.rb
codeclimate-test-reporter-0.4.2 lib/code_climate/test_reporter/git.rb
codeclimate-test-reporter-0.4.1 lib/code_climate/test_reporter/git.rb