Class: Danger::CISource::LocalGitRepo

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

Instance Attribute Summary collapse

Attributes inherited from CI

#pull_request_id, #repo_slug

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLocalGitRepo

Returns a new instance of LocalGitRepo.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/danger/ci_source/local_git_repo.rb', line 15

def initialize(*)
  git = Git.open(".")
  if git.remote("origin")
    url = git.remote("origin").url
    # deal with https://
    if url.start_with? "https://github.com/"
      self.repo_slug = url.gsub("https://github.com/", "").gsub(".git", '')

    # deal with SSH origin
    elsif url.start_with? "[email protected]:"
      self.repo_slug = url.gsub("[email protected]:", "").gsub(".git", '')
    end
  end

  logs = git.log.since('2 weeks ago')
  # Look for something like
  # "Merge pull request #38 from KrauseFx/funky_circles\n\nAdd support for GitHub compare URLs that don't conform
  pr_merge = logs.detect { |log| (/Merge pull request #[0-9]* from/ =~ log.message) == 0 }
  if pr_merge
    # then pull out the 38, to_i
    self.pull_request_id = pr_merge.message.gsub("Merge pull request #", "").to_i
    self.base_commit = pr_merge.parents[0].sha
    self.head_commit = pr_merge.parents[1].sha
  end
end

Instance Attribute Details

#base_commitObject

Returns the value of attribute base_commit.



9
10
11
# File 'lib/danger/ci_source/local_git_repo.rb', line 9

def base_commit
  @base_commit
end

#head_commitObject

Returns the value of attribute head_commit.



9
10
11
# File 'lib/danger/ci_source/local_git_repo.rb', line 9

def head_commit
  @head_commit
end

Class Method Details

.validates?(env) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/danger/ci_source/local_git_repo.rb', line 11

def self.validates?(env)
  return !env["DANGER_USE_LOCAL_GIT"].nil?
end