Class: Danger::LocalOnlyGitRepo

Inherits:
CI
  • Object
show all
Defined in:
lib/danger/ci_source/local_only_git_repo.rb

Overview

### CI Setup

For setting up LocalOnlyGitRepo there is not much needed. Either ‘–base` and `–head` need to be specified or origin/master is expected for base and HEAD for head

Constant Summary collapse

HEAD_VAR =
"DANGER_LOCAL_HEAD"
BASE_VAR =
"DANGER_LOCAL_BASE"

Instance Attribute Summary collapse

Attributes inherited from CI

#pull_request_id, #repo_slug, #repo_url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CI

available_ci_sources, inherited, #supports?

Constructor Details

#initialize(env = {}) ⇒ LocalOnlyGitRepo

Returns a new instance of LocalOnlyGitRepo.



38
39
40
41
42
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 38

def initialize(env = {})
  # expects --base/--head specified OR origin/master to be base and HEAD head
  self.base_commit = env[BASE_VAR] || run_git("rev-parse --abbrev-ref origin/master")
  self.head_commit = env[HEAD_VAR] || run_git("rev-parse --abbrev-ref HEAD")
end

Instance Attribute Details

#base_commitObject

Returns the value of attribute base_commit.



13
14
15
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 13

def base_commit
  @base_commit
end

#head_commitObject

Returns the value of attribute head_commit.



13
14
15
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 13

def head_commit
  @head_commit
end

Class Method Details

.validates_as_ci?(env) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 18

def self.validates_as_ci?(env)
  env.key? "DANGER_USE_LOCAL_ONLY_GIT"
end

.validates_as_pr?(_env) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 22

def self.validates_as_pr?(_env)
  false
end

Instance Method Details

#gitObject



26
27
28
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 26

def git
  @git ||= GitRepo.new
end

#run_git(command) ⇒ Object



30
31
32
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 30

def run_git(command)
  git.exec(command).encode("UTF-8", "binary", invalid: :replace, undef: :replace, replace: "")
end

#supported_request_sourcesObject



34
35
36
# File 'lib/danger/ci_source/local_only_git_repo.rb', line 34

def supported_request_sources
  @supported_request_sources ||= [Danger::RequestSources::LocalOnly]
end