Skip to content

Add local report previews, Actions summaries, and consumer tests - #23

Merged
dblock merged 2 commits into
danger:mainfrom
dblock:feat/report-preview-summary
Nov 18, 2026
Merged

dblock merged 2 commits into
danger:mainfrom
dblock:feat/report-preview-summary

Conversation

@dblock

@dblock dblock commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Add a shared Ruby Markdown renderer, a packaged bin/danger-pr-comment executable, local report previews, and automatic Actions summaries:

bundle exec danger-pr-comment render danger-report.json

The shared Dangerfile exports an additive rendered_markdown field and appends the same body to GITHUB_STEP_SUMMARY, preserving existing summary content and exporting reports even when Danger exits with reported errors. No summary path is required outside Actions.

The privileged commenter consumes pre-rendered Markdown as data while keeping its own marker, title, and workflow-run link. Older reports retain legacy rendering. It does not check out PR code, install the gem, execute Ruby, or require additional permissions.

The preview command renders existing reports without running Danger or posting comments. It returns nonzero for unreadable files, invalid JSON, and invalid report roots, not for findings in a valid report.

Rebased onto current main, retaining the merged sticky-comment and comment-empty features and version 0.3.0. This remains one amended commit in #23.

Data-driven consumer scenarios

Each folder under spec/fixtures/consumer/ contains its own Dangerfile, event JSON, YAML expectations, and supporting assets. The runner discovers folders automatically, builds and installs the actual gem in a temporary gem home, resolves a consumer bundle offline, and runs the real Danger and preview executables. Expectations specify the Danger exit status, complete exported report, CLI output, summary, and comment operation/body.

Ten scenarios cover all findings with an existing summary, empty reports, no summary path, multiline warnings, Markdown-only findings loaded from assets, legacy report fallback, pre-rendered-body precedence, suppressed new empty comments, clearing an existing comment, and missing PR metadata.

The comment harness executes the actual workflow JavaScript and configured input defaults with GitHub writes stubbed. No remote comments or releases are created.

CI fix

Fixes the bundler: command not found: danger failure in the reported CI job. The consumer bundle could resolve its dependency gems, but leaving the parent Bundler environment removed their executable paths. Consumer subprocesses now explicitly include Gem.bindir for the isolated gem home and every dependency gem path, rather than relying on globally available executables. Offline dependency resolution is preserved.

Validation

  • Full RSpec suite: 82 examples passed, including all ten installed-gem scenarios.
  • Ran with CI=true, GITHUB_ACTIONS=true, and an ambient PATH verified not to contain a danger executable.
  • After the lint refactor, reran all ten consumer scenarios under that restricted PATH: 10 passed.
  • bundle exec rubocop: 30 files, no offenses.
  • actionlint .github/workflows/danger-comment.yml
  • node --check spec/fixtures/publish_consumer_report.js
  • git diff --check and staged whitespace checks.

AI-authored by GitHub Copilot on behalf of @dblock.

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Danger Report

No issues found.

View run

Package the preview executable under bin, share Markdown rendering between reports and Actions summaries, and consume rendered Markdown as data in the commenter. Exercise the installed gem through ten self-contained fixture scenarios with data-driven expectations. Include dependency gem bindirs in consumer PATH so vendored CI bundles can find Danger without a global executable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@numbata numbata left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things to fix before merge. Both are small.

Comment thread .github/workflows/danger-comment.yml Resolved
Comment thread .github/workflows/danger-comment.yml Resolved
Respect pre-rendered overrides for quiet comments, retain all-clear updates, and normalize trailing newlines before the workflow-run link. Cover custom and empty overrides with installed-consumer scenarios and workflow regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dblock
dblock merged commit 80d4e0a into danger:main Nov 18, 2026
3 checks passed
@dblock
dblock deleted the feat/report-preview-summary branch November 18, 2026 00:45
dblock added a commit that referenced this pull request Nov 18, 2026
## Summary

Independent alternative to #20, based directly on `main`. This
implements the smaller API-only approach rather than adding
authenticated provenance. It leaves #20 and #23 unchanged and does not
supersede or close either PR.

- Resolve the destination independently of the untrusted report:
paginate open PRs by the triggering run's source owner/branch, then
match the exact head SHA, head branch, source repository ID, and caller
base repository ID.
- Require exactly one match across all bases before applying the base
policy. The report's positive safe-integer PR number must equal that
independently selected PR; it cannot choose between candidates.
- Fetch the selected PR again and recheck its number, open state, head,
creation timestamp, and current base before any comment listing,
creation, or update. Reject PRs created after the original run creation
timestamp, not the rerun start time.
- Accept only successful/failed `pull_request` runs delivered through
`workflow_run`. Preserve existing sticky comments, empty-report
behavior, writer serialization, and permissions.

No producer changes, additional jobs, signing permissions, attestations,
dependencies, PR checkout, or PR-controlled code execution are added.
Fork support uses the PR API lookup, not potentially empty
`workflow_run.pull_requests` associations.

## Base policy and compatibility

`base-branch` omitted/empty allows only the caller repository default
branch. A literal value such as `release` is an exact restriction.
Explicit `base-branch: "*"` allows changing stacked targets within the
caller repository.

These are intentional restrictions compared with current `main`, which
does not bind report targets: non-default-target callers must configure
a literal base or `"*"`, closed/merged PRs are rejected, and multiple
same-head open PRs are rejected even if a literal base would distinguish
them. Existing default-branch callers normally need no configuration
change.

## What's the worst that can happen?

**Someone could make Danger post a misleading report on the wrong PR, or
replace its existing Danger comment with a fake “all clear.”** The
destination is still restricted to an open PR in this repository with
the exact source repository, branch, and commit from the run, and an
allowed target branch. It cannot be just any unrelated PR.

For example, PRs A and B could use the same source branch and commit but
target different branches. Danger runs for A. If A closes before the
comment is posted, someone who controls the uploaded report could change
its PR number to B. B could then pass the checks—even if the original
workflow would not normally run for B's target branch. This version
checks what GitHub shows **now**; unlike the signed-record option in
#20, it cannot prove which PR originally started the run.

An old report can also be posted after a PR changes its target branch
without changing its code, or overwrite a newer report from another run
at the same commit. That can make the current PR look checked when its
current target was not. Run Danger again after changing the target, but
this version cannot guarantee that happened.

These are risks to the accuracy of the PR comments. This workflow does
not merge PRs, change code, or execute code from the uploaded report. If
GitHub's data is missing, inaccessible, or shows multiple matching open
PRs, it refuses to post rather than guessing. The creation-time check
blocks later-created PRs, but does not prove which PR started the run.

The new `SECURITY.md` documents these limits, and tests demonstrate both
the rejected cases and the misleading-routing cases this simpler
approach still allows.

## Validation

- `bundle exec rspec spec/scripts/current_pr_workflow_spec.rb
spec/scripts/sticky_comment_workflow_spec.rb
spec/scripts/empty_comment_workflow_spec.rb
spec/scripts/install_workflows_spec.rb` — 116 examples, 0 failures.
- `bundle exec rubocop` — 16 files, no offenses.
- `actionlint .github/workflows/danger-comment.yml` — passed.
- `node --check` for all three commenter workflow harnesses — passed.
- `git diff --check` — passed.

The tests execute the actual workflow JavaScript and job/environment
expressions with paginated API fixtures. They cover default and explicit
bases, upper stacked targets, forks, stale heads, re-fetch races,
absent/ambiguous/inaccessible matches, forged report targets, run
creation timestamps, and rejection before all comment access. No live
privileged workflow-run integration test was performed.

Authored by GitHub Copilot (AI), on behalf of @dblock.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dblock added a commit that referenced this pull request Nov 18, 2026
## Summary

Fix the main-branch [Test
failure](https://github.com/danger/danger-pr-comment/actions/runs/44210523732)
introduced when #23 and #24 were combined. Twelve installed-consumer
scenarios failed with `Triggering run is missing required PR matching
metadata`: the consumer commenter harness still supplied the old
run-only context and had no PR API stubs.

- Supply a separate workflow/PR fixture with caller repository metadata,
fork source/head information, timestamps, and an independently defined
PR response. The scenario's original event fixture supplies its PR
number; the uploaded report does not determine the API response.
- Evaluate the actual job condition and environment expressions,
including the default-base fallback, rather than only substituting
simple input expressions.
- Stub PR listing and fetching alongside comment operations. Require
consumer scenarios to reach PR lookup, re-fetch, and comment listing
without failures, notices, or job skips, so quiet-mode scenarios cannot
accidentally pass by skipping validation.

No production workflows, permissions, matching rules, dependencies, or
package APIs change.

## Validation

- `CI=true GITHUB_ACTIONS=true bundle exec rake spec` — **161 examples,
0 failures**, including all 13 installed-gem consumer scenarios.
- `bundle exec rubocop` — **34 files, no offenses**.
- `node --check spec/fixtures/publish_consumer_report.js` — passed.
- `git diff --check` — passed.

The consumer scenarios build and install the real gem in temporary
consumers and run the actual Danger and preview executables. GitHub API
calls remain stubbed; no remote comments or publication are performed.

Authored by GitHub Copilot (AI), on behalf of @dblock.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants