class Git::Cop::Branches::Environments::TravisCI

Provides feature branch information for Travis CI build environment.

Attributes

shell[R]

Public Class Methods

ci_branch() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 11
def self.ci_branch
  ENV["TRAVIS_BRANCH"]
end
new(shell: Open3) click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 23
def initialize shell: Open3
  @shell = shell
end
pull_request_branch() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 15
def self.pull_request_branch
  ENV["TRAVIS_PULL_REQUEST_BRANCH"]
end
pull_request_slug() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 19
def self.pull_request_slug
  ENV["TRAVIS_PULL_REQUEST_SLUG"]
end

Public Instance Methods

name() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 27
def name
  klass = self.class
  pull_request_branch = klass.pull_request_branch

  pull_request_branch.empty? ? klass.ci_branch : pull_request_branch
end
shas() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 34
def shas
  prepare_project

  result, _status = shell.capture2e %(git log --pretty=format:"%H" origin/master..#{name})
  result.split("\n")
end

Private Instance Methods

prepare_project() click to toggle source
# File lib/git/cop/branches/environments/travis_ci.rb, line 45
def prepare_project
  slug = self.class.pull_request_slug

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

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