Class: Danger::LocalGitRepo
- Inherits:
-
CI
- Object
- CI
- Danger::LocalGitRepo
show all
- Defined in:
- lib/danger/ci_source/local_git_repo.rb
Overview
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
Returns a new instance of LocalGitRepo.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 42
def initialize(env = {})
repo_slug = RemoteFinder.new(
env["DANGER_GITHUB_HOST"] || "github.com".freeze,
run_git("remote show origin -n".freeze)
).call
pull_request_id, sha = MergedPullRequestFinder.new(
env.fetch("LOCAL_GIT_PR_ID") { "" },
run_git("log --oneline -1000000".freeze)
).call
self.repo_slug = repo_slug ? repo_slug : print_repo_slug_warning
self.pull_request_id = pull_request_id
self.base_commit = parents(sha)[0]
self.head_commit = parents(sha)[1]
end
|
Instance Attribute Details
#base_commit ⇒ Object
Returns the value of attribute base_commit.
12
13
14
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 12
def base_commit
@base_commit
end
|
#head_commit ⇒ Object
Returns the value of attribute head_commit.
12
13
14
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 12
def head_commit
@head_commit
end
|
Class Method Details
.validates_as_ci?(env) ⇒ Boolean
14
15
16
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 14
def self.validates_as_ci?(env)
env.key? "DANGER_USE_LOCAL_GIT"
end
|
.validates_as_pr?(_env) ⇒ Boolean
18
19
20
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 18
def self.validates_as_pr?(_env)
false
end
|
Instance Method Details
#git ⇒ Object
22
23
24
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 22
def git
@git ||= GitRepo.new
end
|
#parents(sha) ⇒ Object
38
39
40
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 38
def parents(sha)
@parents ||= run_git("rev-list --parents -n 1 #{sha}").strip.split(" ".freeze)
end
|
#print_repo_slug_warning ⇒ Object
34
35
36
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 34
def print_repo_slug_warning
puts "Danger local requires a repository hosted on GitHub.com or GitHub Enterprise.".freeze
end
|
#run_git(command) ⇒ Object
26
27
28
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 26
def run_git(command)
git.exec command
end
|
#supported_request_sources ⇒ Object
30
31
32
|
# File 'lib/danger/ci_source/local_git_repo.rb', line 30
def supported_request_sources
@supported_request_sources ||= [Danger::RequestSources::GitHub]
end
|