Skip to content

Commit eb222e4

Browse files
committed
Improve Danger workflow configuration
- Add explicit PR event types (opened, synchronize, reopened) - Set artifact retention to 1 day - Fix regex patterns with word boundaries to avoid false positives
1 parent 7d8ff3e commit eb222e4

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

.github/workflows/danger-comment.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ on:
66
types: [completed]
77

88
permissions:
9-
contents: read
10-
pull-requests: write
9+
actions: read # Required to download the artifact
10+
contents: read # Standard safe default
11+
issues: write # Required to post comments (PRs are Issues in the API)
12+
1113

1214
jobs:
1315
comment:

.github/workflows/danger.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
name: danger
3-
on: pull_request
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
46

57
jobs:
68
danger:
@@ -26,3 +28,4 @@ jobs:
2628
with:
2729
name: danger-report
2830
path: danger_report.json
31+
retention-days: 1

Dangerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
# Inline checks from ruby-grape-danger (avoids plugins requiring GitHub API token)
44

5-
has_app_changes = !git.modified_files.grep(/lib/).empty?
6-
has_spec_changes = !git.modified_files.grep(/spec/).empty?
5+
has_app_changes = !git.modified_files.grep(%r{^lib/}).empty?
6+
has_spec_changes = !git.modified_files.grep(%r{^spec/}).empty?
77

88
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
99

@@ -20,8 +20,8 @@ warn('Please update CHANGELOG.md with a description of your changes.', sticky: f
2020
contents = File.read(file)
2121
# rubocop:disable Style/SignalException -- `fail` is Danger's DSL method, not Kernel#fail
2222
if file.start_with?('spec')
23-
fail("`xit` or `fit` left in tests (#{file})") if /^\w*[xf]it/.match?(contents)
24-
fail("`fdescribe` left in tests (#{file})") if /^\w*fdescribe/.match?(contents)
23+
fail("`xit` or `fit` left in tests (#{file})") if /^\s*[xf]it\b/.match?(contents)
24+
fail("`fdescribe` left in tests (#{file})") if /^\s*fdescribe\b/.match?(contents)
2525
end
2626
# rubocop:enable Style/SignalException
2727
end

0 commit comments

Comments
 (0)