ruby-grape-danger 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/danger-comment.yml +122 -0
- data/.github/workflows/danger-run.yml +33 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +5 -4
- data/Dangerfile +21 -0
- data/README.md +90 -4
- data/lib/ruby-grape-danger/reporter.rb +38 -0
- data/lib/ruby-grape-danger/version.rb +1 -1
- data/lib/ruby-grape-danger.rb +5 -0
- data/ruby-grape-danger.gemspec +1 -1
- data/spec/ruby-grape-danger/reporter_spec.rb +217 -0
- metadata +11 -6
- data/.github/workflows/danger.yml +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8c6c28f7fdcf4b05bc9d622b75dbe57759a55837143715966441364b7c358044
|
|
4
|
+
data.tar.gz: d963a4a1cc4a97a4043c6a4075fa5b10379a6046f7b08217f2e3da332ce9a155
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b89b6e6d26fe1c53c8c7e14d0e4890bf1daecc43c5fd145245918425ccbaab1a5ece76163e907266cf0d187ef08cc854040e3389d074e0ef510172e15534d6fe
|
|
7
|
+
data.tar.gz: 15661c28f789783af97729bd5b00a72f2e95493e0481f1debe819b6ec1e6a51e37b5704b1e5855a090392613f0171fb6db90e3626b7254d21b49f10fa17ce3fc
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
name: Danger Comment
|
|
2
|
+
on:
|
|
3
|
+
workflow_run:
|
|
4
|
+
workflows: [Danger]
|
|
5
|
+
types: [completed]
|
|
6
|
+
workflow_call:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
actions: read
|
|
10
|
+
contents: read
|
|
11
|
+
issues: write
|
|
12
|
+
pull-requests: write
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
comment:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
if: |
|
|
18
|
+
(github.event_name == 'workflow_run' && github.event.workflow_run.event == 'pull_request')
|
|
19
|
+
|| github.event_name == 'workflow_call'
|
|
20
|
+
steps:
|
|
21
|
+
- name: Checkout
|
|
22
|
+
uses: actions/checkout@v4
|
|
23
|
+
with:
|
|
24
|
+
fetch-depth: 1
|
|
25
|
+
- name: Download Danger Report (workflow_run)
|
|
26
|
+
if: github.event_name == 'workflow_run'
|
|
27
|
+
uses: actions/download-artifact@v4
|
|
28
|
+
continue-on-error: true
|
|
29
|
+
with:
|
|
30
|
+
name: danger-report
|
|
31
|
+
run-id: ${{ github.event.workflow_run.id }}
|
|
32
|
+
repository: ${{ github.event.workflow_run.repository.full_name }}
|
|
33
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
34
|
+
- name: Download Danger Report (reusable call)
|
|
35
|
+
if: github.event_name == 'workflow_call'
|
|
36
|
+
uses: actions/download-artifact@v4
|
|
37
|
+
continue-on-error: true
|
|
38
|
+
with:
|
|
39
|
+
name: danger-report
|
|
40
|
+
- name: Post or Update PR Comment
|
|
41
|
+
uses: actions/github-script@v7
|
|
42
|
+
with:
|
|
43
|
+
script: |
|
|
44
|
+
const fs = require('fs');
|
|
45
|
+
|
|
46
|
+
const hasItems = (arr) => Array.isArray(arr) && arr.length > 0;
|
|
47
|
+
|
|
48
|
+
let report;
|
|
49
|
+
try {
|
|
50
|
+
report = JSON.parse(fs.readFileSync('danger_report.json', 'utf8'));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
console.log('No danger report found, skipping comment');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!report.pr_number) {
|
|
57
|
+
console.log('No PR number found in report, skipping comment');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let body = '## Danger Report\n\n';
|
|
62
|
+
|
|
63
|
+
if (hasItems(report.errors)) {
|
|
64
|
+
body += '### ❌ Errors\n';
|
|
65
|
+
report.errors.forEach(e => body += `- ${e}\n`);
|
|
66
|
+
body += '\n';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (hasItems(report.warnings)) {
|
|
70
|
+
body += '### ⚠️ Warnings\n';
|
|
71
|
+
report.warnings.forEach(w => body += `- ${w}\n`);
|
|
72
|
+
body += '\n';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (hasItems(report.messages)) {
|
|
76
|
+
body += '### ℹ️ Messages\n';
|
|
77
|
+
report.messages.forEach(m => body += `- ${m}\n`);
|
|
78
|
+
body += '\n';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (hasItems(report.markdowns)) {
|
|
82
|
+
report.markdowns.forEach(md => body += `${md}\n\n`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!hasItems(report.errors) &&
|
|
86
|
+
!hasItems(report.warnings) &&
|
|
87
|
+
!hasItems(report.messages) &&
|
|
88
|
+
!hasItems(report.markdowns)) {
|
|
89
|
+
body += '✅ All checks passed!';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const { data: comments } = await github.rest.issues.listComments({
|
|
93
|
+
owner: context.repo.owner,
|
|
94
|
+
repo: context.repo.repo,
|
|
95
|
+
issue_number: report.pr_number
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const botComment = comments.find(c =>
|
|
99
|
+
c.user.login === 'github-actions[bot]' &&
|
|
100
|
+
c.body.includes('## Danger Report')
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (botComment) {
|
|
104
|
+
await github.rest.issues.updateComment({
|
|
105
|
+
owner: context.repo.owner,
|
|
106
|
+
repo: context.repo.repo,
|
|
107
|
+
comment_id: botComment.id,
|
|
108
|
+
body: body
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
await github.rest.issues.createComment({
|
|
112
|
+
owner: context.repo.owner,
|
|
113
|
+
repo: context.repo.repo,
|
|
114
|
+
issue_number: report.pr_number,
|
|
115
|
+
body: body
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Fail if there are errors
|
|
120
|
+
if (hasItems(report.errors)) {
|
|
121
|
+
core.setFailed('Danger found errors');
|
|
122
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
name: Danger
|
|
2
|
+
on:
|
|
3
|
+
pull_request:
|
|
4
|
+
types: [ opened, reopened, edited, synchronize ]
|
|
5
|
+
workflow_call:
|
|
6
|
+
jobs:
|
|
7
|
+
danger:
|
|
8
|
+
name: Danger
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Checkout
|
|
12
|
+
uses: actions/checkout@v3
|
|
13
|
+
with:
|
|
14
|
+
fetch-depth: 0
|
|
15
|
+
- name: Set up Ruby
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 2.7
|
|
19
|
+
bundler-cache: true
|
|
20
|
+
- name: Run Danger
|
|
21
|
+
# Note: We use 'dry_run' mode intentionally as part of a two-workflow pattern.
|
|
22
|
+
# The actual commenting on GitHub is handled by the danger-comment.yml workflow.
|
|
23
|
+
run: bundle exec danger dry_run --verbose
|
|
24
|
+
env:
|
|
25
|
+
DANGER_REPORT_PATH: danger_report.json
|
|
26
|
+
- name: Upload Danger Report
|
|
27
|
+
if: always()
|
|
28
|
+
uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: danger-report
|
|
31
|
+
path: danger_report.json
|
|
32
|
+
retention-days: 1
|
|
33
|
+
if-no-files-found: ignore
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
### Changelog
|
|
2
2
|
|
|
3
|
-
### 0.
|
|
3
|
+
### 0.3.0 (2025/12/18)
|
|
4
4
|
|
|
5
|
-
*
|
|
5
|
+
* [#16](https://github.com/ruby-grape/danger/pull/16): Report workflow postreview fixes - [@numbata](https://github.com/numbata).
|
|
6
|
+
* [#15](https://github.com/ruby-grape/danger/pull/15): Extract danger reporting infrastructure into reusable workflows and gem - [@numbata](https://github.com/numbata).
|
|
6
7
|
|
|
7
|
-
### 0.2.1 (2024/01
|
|
8
|
+
### 0.2.1 (2024/02/01)
|
|
8
9
|
|
|
9
|
-
* [#11](https://github.com/ruby-grape/danger/pull/11): Upgraded Danger to 9.x, danger-changelog 0.7.x & switched from Travis to GHA.
|
|
10
|
+
* [#11](https://github.com/ruby-grape/danger/pull/11): Upgraded Danger to 9.x, danger-changelog 0.7.x & switched from Travis to GHA - [@mscrivo](https://github.com/mscrivo).
|
|
10
11
|
|
|
11
12
|
### 0.2.0 (2020/05/09)
|
|
12
13
|
|
data/Dangerfile
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'ruby-grape-danger'
|
|
4
|
+
require 'English'
|
|
5
|
+
|
|
6
|
+
# This Dangerfile provides automatic danger report export and standard checks for Grape projects.
|
|
7
|
+
# Other projects can import this via: danger.import_dangerfile(gem: 'ruby-grape-danger')
|
|
8
|
+
# to get automatic reporting with their own custom checks.
|
|
9
|
+
|
|
10
|
+
# Register at_exit hook to export report when Dangerfile finishes
|
|
11
|
+
dangerfile_instance = self if defined?(Danger::Dangerfile) && is_a?(Danger::Dangerfile)
|
|
12
|
+
at_exit do
|
|
13
|
+
# Only skip if there's an actual exception (not SystemExit from danger calling exit)
|
|
14
|
+
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
|
|
15
|
+
next unless dangerfile_instance
|
|
16
|
+
|
|
17
|
+
reporter = RubyGrapeDanger::Reporter.new(dangerfile_instance.status_report)
|
|
18
|
+
reporter.export_json(
|
|
19
|
+
ENV.fetch('DANGER_REPORT_PATH', nil),
|
|
20
|
+
ENV.fetch('GITHUB_EVENT_PATH', nil)
|
|
21
|
+
)
|
|
22
|
+
end
|
|
23
|
+
|
|
3
24
|
# --------------------------------------------------------------------------------------------------------------------
|
|
4
25
|
# Has any changes happened inside the actual library code?
|
|
5
26
|
# --------------------------------------------------------------------------------------------------------------------
|
data/README.md
CHANGED
|
@@ -4,14 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://travis-ci.org/ruby-grape/danger)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
# Table of Contents
|
|
8
8
|
|
|
9
9
|
- [Setup](#setup)
|
|
10
|
-
- [Set DANGER_GITHUB_API_TOKEN in Travis-CI](#set-danger_github_api_token-in-travis-ci)
|
|
11
10
|
- [Add Danger](#add-danger)
|
|
12
11
|
- [Add Dangerfile](#add-dangerfile)
|
|
13
|
-
- [Add
|
|
12
|
+
- [Add GitHub Actions Workflows](#add-github-actions-workflows)
|
|
14
13
|
- [Commit via a Pull Request](#commit-via-a-pull-request)
|
|
14
|
+
- [Reusable Workflows](#reusable-workflows)
|
|
15
|
+
- [Architecture](#architecture)
|
|
16
|
+
- [How It Works](#how-it-works)
|
|
17
|
+
- [Examples](#examples)
|
|
15
18
|
- [License](#license)
|
|
16
19
|
|
|
17
20
|
## Setup
|
|
@@ -28,16 +31,99 @@ gem 'ruby-grape-danger', require: false
|
|
|
28
31
|
|
|
29
32
|
### Add Dangerfile
|
|
30
33
|
|
|
31
|
-
|
|
34
|
+
Create a `Dangerfile` in your project's root that imports `ruby-grape-danger` and adds your project-specific checks:
|
|
32
35
|
|
|
33
36
|
```ruby
|
|
34
37
|
danger.import_dangerfile(gem: 'ruby-grape-danger')
|
|
38
|
+
|
|
39
|
+
# Your project-specific danger checks
|
|
40
|
+
changelog.check!
|
|
41
|
+
toc.check!
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The `ruby-grape-danger` Dangerfile automatically handles:
|
|
45
|
+
- Setting up the reporting infrastructure
|
|
46
|
+
- Exporting the danger report via `at_exit` hook when the Dangerfile finishes
|
|
47
|
+
- Consistent output format for the workflow
|
|
48
|
+
|
|
49
|
+
### Add GitHub Actions Workflows
|
|
50
|
+
|
|
51
|
+
Create `.github/workflows/danger.yml`:
|
|
52
|
+
|
|
53
|
+
```yaml
|
|
54
|
+
name: Danger
|
|
55
|
+
on:
|
|
56
|
+
pull_request:
|
|
57
|
+
types: [ opened, reopened, edited, synchronize ]
|
|
58
|
+
workflow_call:
|
|
59
|
+
|
|
60
|
+
jobs:
|
|
61
|
+
danger:
|
|
62
|
+
uses: ruby-grape/danger/.github/workflows/danger-run.yml@main
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Create `.github/workflows/danger-comment.yml`:
|
|
66
|
+
|
|
67
|
+
```yaml
|
|
68
|
+
name: Danger Comment
|
|
69
|
+
on:
|
|
70
|
+
workflow_run:
|
|
71
|
+
workflows: [Danger]
|
|
72
|
+
types: [completed]
|
|
73
|
+
workflow_call:
|
|
74
|
+
|
|
75
|
+
jobs:
|
|
76
|
+
comment:
|
|
77
|
+
uses: ruby-grape/danger/.github/workflows/danger-comment.yml@main
|
|
35
78
|
```
|
|
36
79
|
|
|
37
80
|
### Commit via a Pull Request
|
|
38
81
|
|
|
39
82
|
To test things out, make a dummy entry in `CHANGELOG.md` that doesn't match the standard format and make a pull request. Iterate until green.
|
|
40
83
|
|
|
84
|
+
## Reusable Workflows
|
|
85
|
+
|
|
86
|
+
This gem provides **reusable GitHub Actions workflows** that can be referenced by any Grape project to implement standardized Danger checks with consistent reporting.
|
|
87
|
+
|
|
88
|
+
### Architecture
|
|
89
|
+
|
|
90
|
+
The workflows are separated into two stages:
|
|
91
|
+
|
|
92
|
+
1. **danger-run.yml**: Executes Danger checks and generates a report
|
|
93
|
+
- Runs `bundle exec danger dry_run` with your project's Dangerfile
|
|
94
|
+
- Generates a JSON report of check results
|
|
95
|
+
- Uploads the report as an artifact
|
|
96
|
+
|
|
97
|
+
2. **danger-comment.yml**: Posts/updates PR comments with results
|
|
98
|
+
- Downloads the Danger report artifact
|
|
99
|
+
- Formats and posts results as a PR comment
|
|
100
|
+
- Updates existing comment on subsequent runs
|
|
101
|
+
|
|
102
|
+
### How It Works
|
|
103
|
+
|
|
104
|
+
When you reference the reusable workflows:
|
|
105
|
+
|
|
106
|
+
```yaml
|
|
107
|
+
uses: ruby-grape/danger/.github/workflows/danger-run.yml@main
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
GitHub Actions:
|
|
111
|
+
1. Checks out **your project's repository** (not ruby-grape-danger)
|
|
112
|
+
2. Installs dependencies from **your Gemfile**
|
|
113
|
+
3. Runs danger using **your Dangerfile**
|
|
114
|
+
- Your Dangerfile imports `ruby-grape-danger`'s Dangerfile via `danger.import_dangerfile(gem: 'ruby-grape-danger')`
|
|
115
|
+
- The imported Dangerfile registers an `at_exit` hook for automatic reporting
|
|
116
|
+
- Runs your project-specific checks (added after the import)
|
|
117
|
+
- When Dangerfile finishes, the `at_exit` hook automatically exports the report
|
|
118
|
+
4. The report is uploaded as an artifact for the commenting workflow
|
|
119
|
+
|
|
120
|
+
Each project maintains its own Dangerfile with project-specific checks, while the `ruby-grape-danger` gem provides shared infrastructure for consistent reporting and workflow execution.
|
|
121
|
+
|
|
122
|
+
### Examples
|
|
123
|
+
|
|
124
|
+
- [danger-changelog](https://github.com/ruby-grape/danger-changelog) - Validates CHANGELOG format
|
|
125
|
+
- [grape](https://github.com/ruby-grape/grape) - Multi-check danger implementation
|
|
126
|
+
|
|
41
127
|
## License
|
|
42
128
|
|
|
43
129
|
MIT License. See [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
module RubyGrapeDanger
|
|
4
|
+
class Reporter
|
|
5
|
+
def initialize(status_report)
|
|
6
|
+
@status_report = status_report
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def export_json(report_path, event_path)
|
|
10
|
+
return unless report_path && event_path && File.exist?(event_path)
|
|
11
|
+
|
|
12
|
+
event = JSON.parse(File.read(event_path))
|
|
13
|
+
pr_number = event.dig('pull_request', 'number')
|
|
14
|
+
return unless pr_number
|
|
15
|
+
|
|
16
|
+
report = build_report(pr_number)
|
|
17
|
+
File.write(report_path, JSON.pretty_generate(report))
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def build_report(pr_number)
|
|
23
|
+
{
|
|
24
|
+
pr_number: pr_number,
|
|
25
|
+
errors: to_messages(@status_report[:errors]),
|
|
26
|
+
warnings: to_messages(@status_report[:warnings]),
|
|
27
|
+
messages: to_messages(@status_report[:messages]),
|
|
28
|
+
markdowns: to_messages(@status_report[:markdowns])
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_messages(items)
|
|
33
|
+
Array(items).map do |item|
|
|
34
|
+
item.respond_to?(:message) ? item.message : item.to_s
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/ruby-grape-danger.gemspec
CHANGED
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.add_development_dependency 'rake'
|
|
19
19
|
s.add_development_dependency 'rspec'
|
|
20
20
|
s.add_runtime_dependency 'danger', '~> 9'
|
|
21
|
-
s.add_runtime_dependency 'danger-changelog', '~> 0.
|
|
21
|
+
s.add_runtime_dependency 'danger-changelog', '~> 0.8'
|
|
22
22
|
s.add_runtime_dependency 'danger-toc', '~> 0.2'
|
|
23
23
|
end
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'json'
|
|
3
|
+
require 'tempfile'
|
|
4
|
+
|
|
5
|
+
RSpec.describe RubyGrapeDanger::Reporter do
|
|
6
|
+
let(:status_report) do
|
|
7
|
+
{
|
|
8
|
+
errors: ['Error 1', 'Error 2'],
|
|
9
|
+
warnings: ['Warning 1'],
|
|
10
|
+
messages: ['Message 1', 'Message 2'],
|
|
11
|
+
markdowns: ['## Markdown 1']
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let(:event_json) do
|
|
16
|
+
{
|
|
17
|
+
'pull_request' => {
|
|
18
|
+
'number' => 42
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
let(:reporter) { RubyGrapeDanger::Reporter.new(status_report) }
|
|
24
|
+
|
|
25
|
+
describe '#initialize' do
|
|
26
|
+
it 'stores the status_report' do
|
|
27
|
+
expect(reporter.instance_variable_get(:@status_report)).to eq(status_report)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe '#export_json' do
|
|
32
|
+
let(:report_file) { Tempfile.new('danger_report.json') }
|
|
33
|
+
let(:event_file) { Tempfile.new('event.json') }
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
event_file.write(JSON.generate(event_json))
|
|
37
|
+
event_file.close
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
after do
|
|
41
|
+
report_file.unlink
|
|
42
|
+
event_file.unlink
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'creates a JSON report with all fields' do
|
|
46
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
47
|
+
|
|
48
|
+
report = JSON.parse(File.read(report_file.path))
|
|
49
|
+
expect(report['pr_number']).to eq(42)
|
|
50
|
+
expect(report['errors']).to eq(['Error 1', 'Error 2'])
|
|
51
|
+
expect(report['warnings']).to eq(['Warning 1'])
|
|
52
|
+
expect(report['messages']).to eq(['Message 1', 'Message 2'])
|
|
53
|
+
expect(report['markdowns']).to eq(['## Markdown 1'])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'formats the JSON nicely (pretty printed)' do
|
|
57
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
58
|
+
|
|
59
|
+
content = File.read(report_file.path)
|
|
60
|
+
expect(content).to include("\n")
|
|
61
|
+
expect(content).to include(" ")
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context 'with message objects (not strings)' do
|
|
65
|
+
let(:status_report) do
|
|
66
|
+
error_obj = double('error', message: 'Object error')
|
|
67
|
+
warning_obj = double('warning', message: 'Object warning')
|
|
68
|
+
|
|
69
|
+
{
|
|
70
|
+
errors: [error_obj],
|
|
71
|
+
warnings: [warning_obj],
|
|
72
|
+
messages: [],
|
|
73
|
+
markdowns: []
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'converts objects with message method to strings' do
|
|
78
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
79
|
+
|
|
80
|
+
report = JSON.parse(File.read(report_file.path))
|
|
81
|
+
expect(report['errors']).to eq(['Object error'])
|
|
82
|
+
expect(report['warnings']).to eq(['Object warning'])
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context 'with mixed message types' do
|
|
87
|
+
let(:status_report) do
|
|
88
|
+
obj = double('mixed', message: 'Object message')
|
|
89
|
+
|
|
90
|
+
{
|
|
91
|
+
errors: ['String error', obj],
|
|
92
|
+
warnings: [],
|
|
93
|
+
messages: [],
|
|
94
|
+
markdowns: []
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'handles both strings and objects' do
|
|
99
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
100
|
+
|
|
101
|
+
report = JSON.parse(File.read(report_file.path))
|
|
102
|
+
expect(report['errors']).to eq(['String error', 'Object message'])
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'with empty arrays' do
|
|
107
|
+
let(:status_report) do
|
|
108
|
+
{
|
|
109
|
+
errors: [],
|
|
110
|
+
warnings: [],
|
|
111
|
+
messages: [],
|
|
112
|
+
markdowns: []
|
|
113
|
+
}
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'creates report with empty arrays' do
|
|
117
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
118
|
+
|
|
119
|
+
report = JSON.parse(File.read(report_file.path))
|
|
120
|
+
expect(report['errors']).to eq([])
|
|
121
|
+
expect(report['warnings']).to eq([])
|
|
122
|
+
expect(report['messages']).to eq([])
|
|
123
|
+
expect(report['markdowns']).to eq([])
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
context 'with nil values' do
|
|
128
|
+
let(:status_report) do
|
|
129
|
+
{
|
|
130
|
+
errors: nil,
|
|
131
|
+
warnings: nil,
|
|
132
|
+
messages: nil,
|
|
133
|
+
markdowns: nil
|
|
134
|
+
}
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'converts nil to empty array' do
|
|
138
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
139
|
+
|
|
140
|
+
report = JSON.parse(File.read(report_file.path))
|
|
141
|
+
expect(report['errors']).to eq([])
|
|
142
|
+
expect(report['warnings']).to eq([])
|
|
143
|
+
expect(report['messages']).to eq([])
|
|
144
|
+
expect(report['markdowns']).to eq([])
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
context 'when report_path is nil' do
|
|
149
|
+
it 'does not create a file' do
|
|
150
|
+
reporter.export_json(nil, event_file.path)
|
|
151
|
+
|
|
152
|
+
# If file was created, we would have a different path
|
|
153
|
+
expect(File.exist?(report_file.path)).to be true
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
context 'when event_path is nil' do
|
|
158
|
+
it 'does not create a file' do
|
|
159
|
+
reporter.export_json(report_file.path, nil)
|
|
160
|
+
|
|
161
|
+
expect(File.size(report_file.path)).to eq(0)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
context 'when event file does not exist' do
|
|
166
|
+
it 'does not create a report file' do
|
|
167
|
+
reporter.export_json(report_file.path, '/nonexistent/path/event.json')
|
|
168
|
+
|
|
169
|
+
expect(File.size(report_file.path)).to eq(0)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
context 'when event has no pull_request.number' do
|
|
174
|
+
let(:event_json) do
|
|
175
|
+
{
|
|
176
|
+
'pull_request' => {}
|
|
177
|
+
}
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
it 'does not create a report file' do
|
|
181
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
182
|
+
|
|
183
|
+
expect(File.size(report_file.path)).to eq(0)
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
context 'when event has no pull_request key' do
|
|
188
|
+
let(:event_json) do
|
|
189
|
+
{}
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'does not create a report file' do
|
|
193
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
194
|
+
|
|
195
|
+
expect(File.size(report_file.path)).to eq(0)
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
context 'with multiline markdown' do
|
|
200
|
+
let(:status_report) do
|
|
201
|
+
{
|
|
202
|
+
errors: [],
|
|
203
|
+
warnings: [],
|
|
204
|
+
messages: [],
|
|
205
|
+
markdowns: ["## Details\n\nSome content"]
|
|
206
|
+
}
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'preserves multiline markdown' do
|
|
210
|
+
reporter.export_json(report_file.path, event_file.path)
|
|
211
|
+
|
|
212
|
+
report = JSON.parse(File.read(report_file.path))
|
|
213
|
+
expect(report['markdowns']).to eq(["## Details\n\nSome content"])
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-grape-danger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dblock
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '0.
|
|
61
|
+
version: '0.8'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '0.
|
|
68
|
+
version: '0.8'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: danger-toc
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -88,7 +88,8 @@ executables: []
|
|
|
88
88
|
extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
|
90
90
|
files:
|
|
91
|
-
- ".github/workflows/danger.yml"
|
|
91
|
+
- ".github/workflows/danger-comment.yml"
|
|
92
|
+
- ".github/workflows/danger-run.yml"
|
|
92
93
|
- ".gitignore"
|
|
93
94
|
- ".rspec"
|
|
94
95
|
- ".rubocop.yml"
|
|
@@ -101,8 +102,11 @@ files:
|
|
|
101
102
|
- README.md
|
|
102
103
|
- RELEASING.md
|
|
103
104
|
- Rakefile
|
|
105
|
+
- lib/ruby-grape-danger.rb
|
|
106
|
+
- lib/ruby-grape-danger/reporter.rb
|
|
104
107
|
- lib/ruby-grape-danger/version.rb
|
|
105
108
|
- ruby-grape-danger.gemspec
|
|
109
|
+
- spec/ruby-grape-danger/reporter_spec.rb
|
|
106
110
|
- spec/ruby-grape-danger/version_spec.rb
|
|
107
111
|
- spec/spec_helper.rb
|
|
108
112
|
homepage: https://github.com/ruby-grape/danger
|
|
@@ -123,10 +127,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
127
|
- !ruby/object:Gem::Version
|
|
124
128
|
version: '0'
|
|
125
129
|
requirements: []
|
|
126
|
-
rubygems_version: 3.5.
|
|
130
|
+
rubygems_version: 3.5.22
|
|
127
131
|
signing_key:
|
|
128
132
|
specification_version: 4
|
|
129
133
|
summary: Danger.systems conventions for ruby-grape projects.
|
|
130
134
|
test_files:
|
|
135
|
+
- spec/ruby-grape-danger/reporter_spec.rb
|
|
131
136
|
- spec/ruby-grape-danger/version_spec.rb
|
|
132
137
|
- spec/spec_helper.rb
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
name: danger
|
|
2
|
-
on: pull_request
|
|
3
|
-
|
|
4
|
-
jobs:
|
|
5
|
-
danger:
|
|
6
|
-
runs-on: ubuntu-latest
|
|
7
|
-
steps:
|
|
8
|
-
- uses: actions/checkout@v4
|
|
9
|
-
with:
|
|
10
|
-
fetch-depth: 100
|
|
11
|
-
- name: Set up Ruby
|
|
12
|
-
uses: ruby/setup-ruby@v1
|
|
13
|
-
with:
|
|
14
|
-
ruby-version: 3.2
|
|
15
|
-
bundler-cache: true
|
|
16
|
-
rubygems: latest
|
|
17
|
-
- name: Run Danger
|
|
18
|
-
run: |
|
|
19
|
-
# the token is public, has public_repo scope and belongs to the grape-bot user owned by @dblock, this is ok
|
|
20
|
-
TOKEN=$(echo -n Z2hwX2lYb0dPNXNyejYzOFJyaTV3QUxUdkNiS1dtblFwZTFuRXpmMwo= | base64 --decode)
|
|
21
|
-
DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose
|