danger-pr-comment 0.1.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 +7 -0
- data/Dangerfile +18 -0
- data/LICENSE.txt +21 -0
- data/README.md +128 -0
- data/lib/danger-pr-comment/reporter.rb +40 -0
- data/lib/danger-pr-comment/version.rb +5 -0
- data/lib/danger-pr-comment.rb +4 -0
- metadata +61 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bed333a43c4c6883fbeea22eb24a5b1e7f92a3232fc446dfe0103b044c7b7579
|
|
4
|
+
data.tar.gz: 10e13269a7c517aa0f6539c728f5e6428960e1200e2577f4e58bdfa049f76d08
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bf4f9f6a348f7ab8bcd42f5827a9c018e4a75fa12f3606613363bb6dfbc1983f9d8e9a1b4db36a06ece3f1bd4d5b232acf867d6f01699a31f7e56358cfa558a5
|
|
7
|
+
data.tar.gz: 15634bc538e51a3c634839bc36efb31fd5f37c960e7e97cc8c353ca7a55d1fdb5b52b04eb2048326303e27a573eff34dcf10578715e9a2b31b278acf6ddd53f9
|
data/Dangerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'danger-pr-comment'
|
|
4
|
+
require 'English'
|
|
5
|
+
|
|
6
|
+
# Shared Dangerfile to export a JSON report for the danger-pr-comment workflows.
|
|
7
|
+
dangerfile_instance = self if defined?(Danger::Dangerfile) && is_a?(Danger::Dangerfile)
|
|
8
|
+
at_exit do
|
|
9
|
+
# Only skip if there's an actual exception (not SystemExit from danger calling exit)
|
|
10
|
+
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
|
|
11
|
+
next unless dangerfile_instance
|
|
12
|
+
|
|
13
|
+
reporter = DangerPrComment::Reporter.new(dangerfile_instance.status_report)
|
|
14
|
+
reporter.export_json(
|
|
15
|
+
ENV.fetch('DANGER_REPORT_PATH', nil),
|
|
16
|
+
ENV.fetch('GITHUB_EVENT_PATH', nil)
|
|
17
|
+
)
|
|
18
|
+
end
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Andrei Subbota
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Danger PR Comment
|
|
2
|
+
|
|
3
|
+
Reusable GitHub Actions workflows for running Danger and posting a PR comment from a JSON report.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Quick Install
|
|
8
|
+
|
|
9
|
+
From your repository root:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
curl -fsSL https://raw.githubusercontent.com/numbata/danger-pr-comment/main/scripts/install-workflows.sh | bash
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Use `--force` to overwrite existing workflow files. To target a specific directory:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
curl -fsSL https://raw.githubusercontent.com/numbata/danger-pr-comment/main/scripts/install-workflows.sh | bash -s -- --root /path/to/repo
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Manual Setup
|
|
22
|
+
|
|
23
|
+
Create `.github/workflows/danger.yml` in your repository:
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
name: Danger
|
|
27
|
+
on:
|
|
28
|
+
pull_request:
|
|
29
|
+
types: [opened, reopened, edited, synchronize]
|
|
30
|
+
|
|
31
|
+
jobs:
|
|
32
|
+
danger:
|
|
33
|
+
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@main
|
|
34
|
+
secrets: inherit
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Create `.github/workflows/danger-comment.yml` in your repository:
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
name: Danger Comment
|
|
41
|
+
on:
|
|
42
|
+
workflow_run:
|
|
43
|
+
workflows: [Danger]
|
|
44
|
+
types: [completed]
|
|
45
|
+
|
|
46
|
+
jobs:
|
|
47
|
+
comment:
|
|
48
|
+
uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@main
|
|
49
|
+
secrets: inherit
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
54
|
+
- Your repository must run `bundle exec danger` successfully.
|
|
55
|
+
- Your Dangerfile must write a JSON report to `ENV['DANGER_REPORT_PATH']` (for example, via a custom `at_exit` hook or a shared Dangerfile).
|
|
56
|
+
- The `Danger Comment` workflow needs `actions: read` and `issues: write` permissions to download artifacts and post comments.
|
|
57
|
+
|
|
58
|
+
### Dangerfile report example
|
|
59
|
+
|
|
60
|
+
If you want a shared Dangerfile, add the gem and import it:
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
# Gemfile
|
|
64
|
+
gem 'danger-pr-comment', require: false
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
# Dangerfile
|
|
69
|
+
# Import danger-pr-comment for automatic danger report export
|
|
70
|
+
danger.import_dangerfile(gem: 'danger-pr-comment')
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or add this to your project's `Dangerfile` (or a shared Dangerfile) to emit the JSON report yourself:
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
# Dangerfile
|
|
77
|
+
require 'json'
|
|
78
|
+
require 'English'
|
|
79
|
+
|
|
80
|
+
dangerfile_instance = self if defined?(Danger::Dangerfile) && is_a?(Danger::Dangerfile)
|
|
81
|
+
at_exit do
|
|
82
|
+
next if $ERROR_INFO && !$ERROR_INFO.is_a?(SystemExit)
|
|
83
|
+
next unless dangerfile_instance
|
|
84
|
+
|
|
85
|
+
report_path = ENV.fetch('DANGER_REPORT_PATH', nil)
|
|
86
|
+
event_path = ENV.fetch('GITHUB_EVENT_PATH', nil)
|
|
87
|
+
next unless report_path && event_path && File.exist?(event_path)
|
|
88
|
+
|
|
89
|
+
event = JSON.parse(File.read(event_path))
|
|
90
|
+
pr_number = event.dig('pull_request', 'number')
|
|
91
|
+
next unless pr_number
|
|
92
|
+
|
|
93
|
+
to_messages = lambda do |items|
|
|
94
|
+
Array(items).map { |item| item.respond_to?(:message) ? item.message : item.to_s }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
report = {
|
|
98
|
+
pr_number: pr_number,
|
|
99
|
+
errors: to_messages.call(dangerfile_instance.status_report[:errors]),
|
|
100
|
+
warnings: to_messages.call(dangerfile_instance.status_report[:warnings]),
|
|
101
|
+
messages: to_messages.call(dangerfile_instance.status_report[:messages]),
|
|
102
|
+
markdowns: to_messages.call(dangerfile_instance.status_report[:markdowns])
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
File.write(report_path, JSON.pretty_generate(report))
|
|
106
|
+
end
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Inputs
|
|
110
|
+
|
|
111
|
+
`danger-run.yml` inputs:
|
|
112
|
+
|
|
113
|
+
- `ruby-version`: Ruby version for `ruby/setup-ruby`. Leave empty to use `.ruby-version`/`.tool-versions`.
|
|
114
|
+
- `bundler-cache`: Enable Bundler caching (default `true`).
|
|
115
|
+
- `danger-args`: Arguments passed to `bundle exec danger` (default `dry_run`).
|
|
116
|
+
- `report-artifact-name`: Artifact name for the report (default `danger-report`).
|
|
117
|
+
- `report-file`: Report filename (default `danger-report.json`).
|
|
118
|
+
|
|
119
|
+
`danger-comment.yml` inputs:
|
|
120
|
+
|
|
121
|
+
- `report-artifact-name`: Artifact name to download (default `danger-report`).
|
|
122
|
+
- `report-file`: Report filename inside the artifact (default `danger-report.json`).
|
|
123
|
+
- `comment-title`: Heading for the PR comment (default `Danger Report`).
|
|
124
|
+
- `comment-marker`: Marker string used to update the comment (default `<!-- danger-report -->`).
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
MIT License. See [LICENSE](LICENSE.txt) for details.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module DangerPrComment
|
|
6
|
+
class Reporter
|
|
7
|
+
def initialize(status_report)
|
|
8
|
+
@status_report = status_report
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def export_json(report_path, event_path)
|
|
12
|
+
return unless report_path && event_path && File.exist?(event_path)
|
|
13
|
+
|
|
14
|
+
event = JSON.parse(File.read(event_path))
|
|
15
|
+
pr_number = event.dig('pull_request', 'number')
|
|
16
|
+
return unless pr_number
|
|
17
|
+
|
|
18
|
+
report = build_report(pr_number)
|
|
19
|
+
File.write(report_path, JSON.pretty_generate(report))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def build_report(pr_number)
|
|
25
|
+
{
|
|
26
|
+
pr_number: pr_number,
|
|
27
|
+
errors: to_messages(@status_report[:errors]),
|
|
28
|
+
warnings: to_messages(@status_report[:warnings]),
|
|
29
|
+
messages: to_messages(@status_report[:messages]),
|
|
30
|
+
markdowns: to_messages(@status_report[:markdowns])
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_messages(items)
|
|
35
|
+
Array(items).map do |item|
|
|
36
|
+
item.respond_to?(:message) ? item.message : item.to_s
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: danger-pr-comment
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrei Subbota
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: danger
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '9'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '9'
|
|
26
|
+
description: Shared Dangerfile that exports a JSON report for posting Danger results
|
|
27
|
+
as a PR comment.
|
|
28
|
+
email:
|
|
29
|
+
- numbata@users.noreply.github.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- Dangerfile
|
|
35
|
+
- LICENSE.txt
|
|
36
|
+
- README.md
|
|
37
|
+
- lib/danger-pr-comment.rb
|
|
38
|
+
- lib/danger-pr-comment/reporter.rb
|
|
39
|
+
- lib/danger-pr-comment/version.rb
|
|
40
|
+
homepage: https://github.com/numbata/danger-pr-comment
|
|
41
|
+
licenses:
|
|
42
|
+
- MIT
|
|
43
|
+
metadata: {}
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 3.6.8
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: Reusable workflows and shared Dangerfile for PR comment reporting.
|
|
61
|
+
test_files: []
|