This repository was archived by the owner on Dec 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDangerfile
More file actions
65 lines (53 loc) · 3.42 KB
/
Dangerfile
File metadata and controls
65 lines (53 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
require 'ruby-grape-danger'
require 'English'
# This Dangerfile provides automatic danger report export and standard checks for Grape projects.
# Other projects can import this via: danger.import_dangerfile(gem: 'ruby-grape-danger')
# to get automatic reporting with their own custom checks.
# Register at_exit hook to export report when Dangerfile finishes
dangerfile_instance = self if defined?(Danger::Dangerfile) && is_a?(Danger::Dangerfile)
at_exit do
# Only skip if there's an actual exception (not SystemExit from danger calling exit)
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
next unless dangerfile_instance
reporter = RubyGrapeDanger::Reporter.new(dangerfile_instance.status_report)
reporter.export_json(
ENV.fetch('DANGER_REPORT_PATH', nil),
ENV.fetch('GITHUB_EVENT_PATH', nil)
)
end
# --------------------------------------------------------------------------------------------------------------------
# Has any changes happened inside the actual library code?
# --------------------------------------------------------------------------------------------------------------------
has_app_changes = !git.modified_files.grep(/lib/).empty?
has_spec_changes = !git.modified_files.grep(/spec/).empty?
# --------------------------------------------------------------------------------------------------------------------
# You've made changes to lib, but didn't write any tests?
# --------------------------------------------------------------------------------------------------------------------
warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false) if has_app_changes && !has_spec_changes
# --------------------------------------------------------------------------------------------------------------------
# You've made changes to specs, but no library code has changed?
# --------------------------------------------------------------------------------------------------------------------
if !has_app_changes && has_spec_changes
message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false)
end
# --------------------------------------------------------------------------------------------------------------------
# Have you updated CHANGELOG.md?
# --------------------------------------------------------------------------------------------------------------------
changelog.check!
# --------------------------------------------------------------------------------------------------------------------
# Do you have a TOC?
# --------------------------------------------------------------------------------------------------------------------
toc.check!
# --------------------------------------------------------------------------------------------------------------------
# Don't let testing shortcuts get into master by accident,
# ensuring that we don't get green builds based on a subset of tests.
# --------------------------------------------------------------------------------------------------------------------
(git.modified_files + git.added_files - %w[Dangerfile]).each do |file|
next unless File.file?(file)
contents = File.read(file)
if file.start_with?('spec')
fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/
fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/
end
end