Class: Danger::DangerfileGitPlugin
- Defined in:
- lib/danger/danger_core/plugins/dangerfile_git_plugin.rb
Overview
Handles interacting with git inside a Dangerfile. Providing access to files that have changed, and useful statistics. Also provides access to the commits in the form of [Git::Log](github.com/schacon/ruby-git/blob/master/lib/git/log.rb) objects.
Git Files collapse
-
#added_files ⇒ FileList<String>
Paths for files that were added during the diff.
-
#deleted_files ⇒ FileList<String>
Paths for files that were removed during the diff.
-
#modified_files ⇒ FileList<String>
Paths for files that changed during the diff.
Git Metadata collapse
-
#commits ⇒ Git::Log
The log of commits inside the diff.
-
#deletions ⇒ Fixnum
The overall lines of code removed in the diff.
-
#diff_for_file(file) ⇒ Git::Diff::DiffFile
Details for a specific file in this diff.
-
#insertions ⇒ Fixnum
The overall lines of code added in the diff.
-
#lines_of_code ⇒ Fixnum
The overall lines of code added/removed in the diff.
Class Method Summary collapse
-
.instance_name ⇒ String
The instance name used in the Dangerfile.
Instance Method Summary collapse
-
#initialize(dangerfile) ⇒ DangerfileGitPlugin
constructor
A new instance of DangerfileGitPlugin.
Methods inherited from Plugin
all_plugins, clear_external_plugins, inherited, #method_missing
Constructor Details
#initialize(dangerfile) ⇒ DangerfileGitPlugin
Returns a new instance of DangerfileGitPlugin.
47 48 49 50 51 52 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 47 def initialize(dangerfile) super(dangerfile) raise unless dangerfile.env.scm.class == Danger::GitRepo @git = dangerfile.env.scm end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Danger::Plugin
Class Method Details
.instance_name ⇒ String
The instance name used in the Dangerfile
43 44 45 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 43 def self.instance_name "git" end |
Instance Method Details
#added_files ⇒ FileList<String>
Paths for files that were added during the diff
58 59 60 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 58 def added_files Danger::FileList.new(@git.diff.select { |diff| diff.type == "new" }.map(&:path)) end |
#commits ⇒ Git::Log
The log of commits inside the diff
106 107 108 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 106 def commits @git.log.to_a end |
#deleted_files ⇒ FileList<String>
Paths for files that were removed during the diff
66 67 68 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 66 def deleted_files Danger::FileList.new(@git.diff.select { |diff| diff.type == "deleted" }.map(&:path)) end |
#deletions ⇒ Fixnum
The overall lines of code removed in the diff
90 91 92 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 90 def deletions @git.diff.deletions end |
#diff_for_file(file) ⇒ Git::Diff::DiffFile
Details for a specific file in this diff
114 115 116 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 114 def diff_for_file(file) modified_files.include?(file) ? @git.diff[file] : nil end |
#insertions ⇒ Fixnum
The overall lines of code added in the diff
98 99 100 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 98 def insertions @git.diff.insertions end |
#lines_of_code ⇒ Fixnum
The overall lines of code added/removed in the diff
82 83 84 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 82 def lines_of_code @git.diff.lines end |