Sha256: e3344ae2102f5b723d1b24801bda3e5aebb0931dce0e27d8e43d7a34f3e339ff

Contents?: true

Size: 1.43 KB

Versions: 2

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require "open3"

module Git
  module Lint
    module Branches
      module Environments
        # Provides Travis CI build environment feature branch information.
        class TravisCI
          def initialize repository: GitPlus::Repository.new, shell: Open3, environment: ENV
            @repository = repository
            @shell = shell
            @environment = environment
          end

          def name
            pull_request_branch.empty? ? ci_branch : pull_request_branch
          end

          def commits
            prepare_project
            repository.commits "origin/master..#{name}"
          end

          private

          attr_reader :environment, :repository, :shell

          def prepare_project
            slug = pull_request_slug

            unless slug.empty?
              shell.capture3 "git remote add -f original_branch https://github.com/#{slug}.git"
              shell.capture3 "git fetch original_branch #{name}:#{name}"
            end

            shell.capture3 "git remote set-branches --add origin master"
            shell.capture3 "git fetch"
          end

          def ci_branch
            environment["TRAVIS_BRANCH"]
          end

          def pull_request_branch
            environment["TRAVIS_PULL_REQUEST_BRANCH"]
          end

          def pull_request_slug
            environment["TRAVIS_PULL_REQUEST_SLUG"]
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git-lint-2.1.0 lib/git/lint/branches/environments/travis_ci.rb
git-lint-2.0.0 lib/git/lint/branches/environments/travis_ci.rb