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 ⇒ Git::Diff
Whole diff.
-
#diff_for_file(file) ⇒ Git::Diff::DiffFile
Details for a specific file in this diff.
-
#info_for_file(file) ⇒ Hash
Statistics 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.
-
#renamed_files ⇒ Array<Hash>
List of renamed files.
-
#tags ⇒ String
List of remote tags.
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 # rubocop:disable Style/ClassEqualityComparison @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
122 123 124 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 122 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
106 107 108 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 106 def deletions @git.diff.deletions end |
#diff ⇒ Git::Diff
Whole diff
90 91 92 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 90 def diff @git.diff end |
#diff_for_file(file) ⇒ Git::Diff::DiffFile
Details for a specific file in this diff
130 131 132 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 130 def diff_for_file(file) (added_files + modified_files + deleted_files).include?(file) ? @git.diff[file] : nil end |
#info_for_file(file) ⇒ Hash
Statistics for a specific file in this diff
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 138 def info_for_file(file) return nil unless modified_files.include?(file) || added_files.include?(file) || deleted_files.include?(file) stats = @git.diff.stats[:files][file] diff = @git.diff[file] { insertions: stats[:insertions], deletions: stats[:deletions], before: added_files.include?(file) || deleted_files.include?(file) ? nil : diff.blob(:src).contents, after: added_files.include?(file) || deleted_files.include?(file) ? nil : diff.blob(:dst).contents } end |
#insertions ⇒ Fixnum
The overall lines of code added in the diff
114 115 116 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 114 def insertions @git.diff.insertions end |
#lines_of_code ⇒ Fixnum
The overall lines of code added/removed in the diff
98 99 100 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 98 def lines_of_code @git.diff.lines end |
#modified_files ⇒ FileList<String>
Paths for files that changed during the diff
74 75 76 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 74 def modified_files Danger::FileList.new(@git.diff.select { |diff| diff.type == "modified" }.map(&:path)) end |
#renamed_files ⇒ Array<Hash>
List of renamed files
82 83 84 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 82 def renamed_files @git.renamed_files end |
#tags ⇒ String
List of remote tags
155 156 157 |
# File 'lib/danger/danger_core/plugins/dangerfile_git_plugin.rb', line 155 def @git..each_line end |