Repository navigation
Add local report previews, Actions summaries, and consumer tests - #23
Merged
Merged
Conversation
Contributor
Danger ReportNo issues found. |
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>
dblock
force-pushed
the
feat/report-preview-summary
branch
from
November 15, 2026 15:02
64a50ec to
117fbf2
Compare
numbata
reviewed
Nov 17, 2026
numbata
left a comment
Collaborator
There was a problem hiding this comment.
Two things to fix before merge. Both are small.
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>
numbata
approved these changes
Nov 17, 2026
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a shared Ruby Markdown renderer, a packaged
bin/danger-pr-commentexecutable, local report previews, and automatic Actions summaries:bundle exec danger-pr-comment render danger-report.jsonThe shared Dangerfile exports an additive
rendered_markdownfield and appends the same body toGITHUB_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 andcomment-emptyfeatures and version0.3.0. This remains one amended commit in #23.Data-driven consumer scenarios
Each folder under
spec/fixtures/consumer/contains its ownDangerfile, 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: dangerfailure 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 includeGem.bindirfor the isolated gem home and every dependency gem path, rather than relying on globally available executables. Offline dependency resolution is preserved.Validation
CI=true,GITHUB_ACTIONS=true, and an ambient PATH verified not to contain adangerexecutable.bundle exec rubocop: 30 files, no offenses.actionlint .github/workflows/danger-comment.ymlnode --check spec/fixtures/publish_consumer_report.jsgit diff --checkand staged whitespace checks.AI-authored by GitHub Copilot on behalf of @dblock.