Class: Danger::ViewChangesChecker
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::ViewChangesChecker
- Defined in:
- lib/dangermattic/plugins/view_changes_checker.rb
Overview
Plugin to make sure View file changes in a Pull Request will have accompanying screenshots in the PR description.
Constant Summary collapse
- VIEW_EXTENSIONS_IOS =
/(View|Button)\.(swift|m)$|\.xib$|\.storyboard$/- VIEW_EXTENSIONS_ANDROID =
/(?i)(View|Button)\.(java|kt|xml)$/- MEDIA_IN_PR_BODY_PATTERNS =
[ %r{https?://\S*\.(gif|jpg|jpeg|png|svg)}, %r{https?://\S*\.(mp4|avi|mov|mkv)}, %r{https?://\S*github\S+/\S+/assets/}, %r{https?://\S*github\S+/storage/user/}, /!\[(.*?)\]\((.*?)\)/, /<img\s+[^>]*src\s*=\s*[^>]*>/, /<video\s+[^>]*src\s*=\s*[^>]*>/ ].freeze
- MESSAGE =
'View files have been modified, but no screenshot or video is included in the pull request. ' \ 'Consider adding some for clarity.'
Instance Method Summary collapse
-
#check(report_type: :warning) ⇒ void
Checks if view files have been modified and if a screenshot or video is included in the pull request body, displaying a warning if view files have been modified but no screenshot or video is included.
Instance Method Details
#check(report_type: :warning) ⇒ void
This method returns an undefined value.
Checks if view files have been modified and if a screenshot or video is included in the pull request body, displaying a warning if view files have been modified but no screenshot or video is included.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/dangermattic/plugins/view_changes_checker.rb', line 35 def check(report_type: :warning) view_files_modified = git.modified_files.any? do |file| VIEW_EXTENSIONS_IOS =~ file || VIEW_EXTENSIONS_ANDROID =~ file end pr_has_media = MEDIA_IN_PR_BODY_PATTERNS.any? do |pattern| github.pr_body =~ pattern end reporter.report(message: MESSAGE, type: report_type) if view_files_modified && !pr_has_media end |