Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,41 @@ jobs:
COMPARISON_REPORT: ${{ steps.comparison.outputs.comparison-report }}
run: python -c "import os, pathlib; report = pathlib.Path(os.environ['COMPARISON_REPORT']).read_text(encoding='utf-8'); assert 'Devscope PR comparison' in report and '| Metric | Base | Head | Delta |' in report"

- name: Test advanced review and HTML artifacts
if: github.event_name == 'pull_request'
uses: ./
id: review
with:
review: 'true'
fail-on-new: 'true'
devscope-ref: 68c1fa668de53f71920e263bbb1f2325cb5f44d0

- name: Verify advanced reports and real CLI regression gate
if: github.event_name == 'pull_request'
shell: bash
env:
HTML_REPORT: ${{ steps.review.outputs.review-html }}
JSON_REPORT: ${{ steps.review.outputs.review-json }}
NEW_WARNINGS: ${{ steps.review.outputs.new-warnings }}
run: |
python - <<'PY'
import json, os, pathlib, subprocess
html = pathlib.Path(os.environ['HTML_REPORT']).read_text(encoding='utf-8')
data = json.loads(pathlib.Path(os.environ['JSON_REPORT']).read_text(encoding='utf-8'))
assert data['kind'] == 'review' and data['new_warnings'] == 0
assert os.environ['NEW_WARNINGS'] == '0'
assert 'Filter files and evidence' in html and 'History-aware hotspots' in html
fixture = pathlib.Path('test-repo').resolve()
base = subprocess.check_output(['git', '-C', str(fixture), 'rev-parse', 'HEAD'], text=True).strip()
(fixture / 'regression.py').write_text('pass\n' * 501, encoding='utf-8')
subprocess.run(['git', '-C', str(fixture), 'add', '.'], check=True)
subprocess.run(['git', '-C', str(fixture), '-c', 'commit.gpgsign=false', 'commit', '-m', 'Regression fixture'], check=True)
output = fixture / 'gate.json'
result = subprocess.run(['devscope', 'review', str(fixture), '--base', base, '--fail-on-new', '--format', 'json', '--output', str(output)])
assert result.returncode == 2
assert json.loads(output.read_text(encoding='utf-8'))['new_warnings'] == 1
PY

- name: Report test results
if: always()
shell: bash
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Development: advanced review

- Opt-in review checklists, history evidence and package scopes.
- New-warning gates that retain reports before failing.
- Coverage input and exact-head provenance assertion.
- HTML/JSON/Markdown artifacts and structured outputs.
- Validated review options, bounded summaries and cross-platform integration tests.
- Development default CLI version moves to published 0.2.0; advanced review uses a source pin until 0.3.0 is released.

## 1.2.0 — 2026-12-04

Published reliable PR/push gates, structured outputs, read-only comment behavior,
Windows threshold rendering fixes and opt-in PR comparisons. The v1 tag points
to this release; comparisons can use the published CLI 0.2.0.

# Changelog

All notable changes to this project will be documented in this file.
Expand Down
92 changes: 80 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: EhsanAzish80/devscope-action@ee711970e3a18ea07430ca9027f862af4311239c
- uses: EhsanAzish80/devscope-action@v1.2.0
id: devscope
with:
fail-under: B
devscope-version: '0.2.0'
```

The quick start pins the merged gate fixes; the floating `@v1` tag has not yet been updated. By default, the Action installs the published PyPI package. Results are available as `health`, `risk`, `onboarding`, and `grade` outputs. It posts one updated PR comment when the workflow token has write permission. PRs from forks often receive a read-only token; in that case the comment is skipped and the analysis and threshold check still run.
Action 1.2.0 is released and is also available through `@v1`. By default, the Action installs the published PyPI package. Results are available as `health`, `risk`, `onboarding`, and `grade` outputs. It posts one updated PR comment when the workflow token has write permission. PRs from forks often receive a read-only token; in that case the comment is skipped and the analysis and threshold check still run.

## Inputs

Expand All @@ -34,9 +35,16 @@ The quick start pins the merged gate fixes; the floating `@v1` tag has not yet b
| `max-risk` | unset | Highest accepted risk label: Low, Medium, High |
| `max-onboarding` | unset | Highest accepted onboarding label: Easy, Moderate, Hard |
| `github-token` | `github.token` | Token for PR comments |
| `devscope-version` | `0.1.1` | Published PyPI version to install |
| `devscope-version` | `0.2.0` | Published PyPI version to install |
| `devscope-ref` | unset | Full upstream CLI commit SHA to install instead of the PyPI version |
| `compare` | `false` | Add an advisory comparison on `pull_request` events |
| `review` | `false` | Advanced checklist, history, new-warning gate and report artifacts |
| `fail-on-new` | `false` | Fail for new review warnings; requires `review: true` |
| `package` | unset | One repository-relative package scope for review |
| `coverage` | unset | LCOV or Cobertura report path, generated before this step |
| `coverage-commit` | unset | Coverage producer's commit; must match the PR head |
| `coverage-root` | unset | Original repository-root prefix in coverage paths |
| `artifact-name` | `devscope-review` | Review artifact name prefix (OS is appended) |

When a threshold is set, it applies to **both pull requests and pushes**. Analysis errors fail the job instead of producing a default grade. The grade is based on file layout, test-file ratio, Git activity, and hotspots. The test-file ratio is not code coverage. Read [the CLI guide](https://github.com/EhsanAzish80/Devscope#what-the-report-tells-you) before using a grade as a gate.

Expand All @@ -45,8 +53,7 @@ For a fork PR, do not switch to `pull_request_target` and execute untrusted code
## PR comparison

Save this as `.github/workflows/devscope.yml`, or copy the complete
[example workflow](examples/pr-comparison.yml). The Action integration commit is
pinned so the workflow can run before a new Action tag or CLI package is released.
[example workflow](examples/pr-comparison.yml). It uses the released comparison engine.

```yaml
name: Devscope PR comparison
Expand All @@ -62,13 +69,11 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
# Pinned integration commit; @v1 does not include comparison yet.
- uses: EhsanAzish80/devscope-action@b2058cd71ef51077b36cf1b9e84958f6d4b0a45a
- uses: EhsanAzish80/devscope-action@v1.2.0
id: devscope
with:
compare: 'true'
# Merged CLI commit containing compare; not an unreleased PyPI version.
devscope-ref: d9849fddd644f98a67985115af74c74ff0a5230e
devscope-version: '0.2.0'
```

The report includes count deltas and added, removed or changed review areas from
Expand All @@ -79,8 +84,9 @@ advisory; the existing grade/risk/onboarding thresholds remain absolute gates.

`compare` defaults to `false` and is skipped outside pull requests. When enabled:

- Use a compare-capable CLI. The pinned `devscope-ref` above is a verified merged
commit; the default PyPI version `0.1.1` does not have `compare`.
- Use CLI 0.2.0 or newer for comparison. The released Action 1.2.0 retains its
older 0.1.1 default; set `devscope-version` as shown. The development Action
defaults to 0.2.0.
- Check out the exact PR head with full history. Both event SHAs must be available.
Shallow or missing history fails the comparison with a setup message.
- Set `path` to the Git repository root. Subdirectory comparisons are not supported.
Expand All @@ -92,6 +98,68 @@ later steps in the same job. It is empty when comparison is disabled or skipped.
Long comments are truncated with a pointer to the full job summary. Git activity,
symlinks, submodules and Git archive export-ignored files are excluded.

## Advanced review (development)

Advanced review requires the 0.3.0 CLI source and this development Action; it is
not included in the released Action 1.2.0 or CLI 0.2.0. The complete
[review workflow](examples/review.yml) uses exact source pins:

```yaml
name: Devscope review guidance
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
# Source pins until the advanced Action and CLI are released.
- uses: EhsanAzish80/devscope-action@2c2f8f7d7e9d873057708bc6bb42e9c49c840dc9
with:
devscope-ref: 68c1fa668de53f71920e263bbb1f2325cb5f44d0
review: 'true'
fail-on-new: 'true'
# After generating coverage in an earlier step, optionally add:
# coverage: coverage.info
# coverage-commit: ${{ github.event.pull_request.head.sha }}
```

Review mode supersedes the basic comparison when both flags are enabled. It adds:

- A changed-file checklist with exact-commit source links, target-history counts,
co-change suggestions and evidence for each warning.
- Repo-wide history hotspots, package summaries, and optional measured patch coverage.
- HTML, JSON and Markdown artifacts retained for 7 days. Download `review.html`
for the self-contained, filterable offline report. The OS is appended to the
artifact name; set a different `artifact-name` for repeated uses in one job.
- `review-html`, `review-json` and `new-warnings` outputs, alongside the existing
`comparison-report` Markdown path.

Commit `.devscope.json` and an optional `.devscope-baseline.json` on the target
branch. Both snapshots use target policy, so a PR cannot disable its own gate.
`fail-on-new` is opt-in and only blocks new configured warnings; it does not
block existing or accepted warnings. Invalid Boolean values and review-only
options without `review: true` fail setup. The report and artifacts are produced
before a new-warning gate failure, allowing reviewers to inspect the evidence.
Absolute grade/risk/onboarding gates remain separate.

Generate coverage for the exact PR head before invoking the Action. When setting
`coverage`, also set `coverage-commit` to that SHA. This is a caller assertion,
not independent verification of freshness. Lines absent from the report remain
unmapped/unknown, not automatically uncovered. The initial warning rules are
configurable large source files and zero-hit added executable lines in supplied
coverage. Size, churn and co-change signals remain heuristics.

Configuration, baseline identity, package scopes, coverage mapping and onboarding
commands are explained in the [CLI feature guide](https://github.com/EhsanAzish80/Devscope/blob/68c1fa668de53f71920e263bbb1f2325cb5f44d0/README.md#review-guidance-030-development).
For repository exploration use `devscope onboard`; it displays declared commands
without executing them. Reports contain paths and metadata, not source code.

## Development

Run the shell integration checks locally:
Expand All @@ -102,6 +170,6 @@ python3 -m unittest discover -s tests -p 'test_*.py'
node --test tests/comment.test.cjs
```

The published `@v1` tag is unchanged. Use the pinned commits above to try the relevant behavior. Once a CLI package containing `compare` is released, you can use its `devscope-version` and omit `devscope-ref`; until then, the default remains the published `0.1.1` package. CI exercises the comparison against the pinned CLI on Ubuntu, macOS and Windows.
Released Action 1.2.0 is available via `@v1`; CLI 0.2.0 is on PyPI. Advanced review remains source-only pending review and release. CI tests comparison, advanced report artifacts, permissive gates and a real new-warning regression gate on Ubuntu, macOS and Windows.

MIT licensed. See [LICENSE](LICENSE).
74 changes: 72 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ inputs:
devscope-version:
description: 'PyPI version of devscope to install'
required: false
default: '0.1.1'
default: '0.2.0'
devscope-ref:
description: 'Optional full commit SHA from EhsanAzish80/Devscope; overrides devscope-version'
required: false
Expand All @@ -39,8 +39,45 @@ inputs:
description: 'Include an advisory PR comparison (requires a compare-capable CLI, full history and repository-root path)'
required: false
default: 'false'
review:
description: 'Enable history-aware review guidance and HTML/JSON artifacts on pull requests (requires CLI 0.3.0 or matching source ref)'
required: false
default: 'false'
fail-on-new:
description: 'Fail only for new configured warnings (requires review: true)'
required: false
default: 'false'
package:
description: 'Optional repository-relative package scope for review'
required: false
default: ''
coverage:
description: 'Optional path to an LCOV or Cobertura report generated before this step'
required: false
default: ''
coverage-commit:
description: 'Commit for which coverage was generated; must match the PR head'
required: false
default: ''
coverage-root:
description: 'Source-root prefix recorded in the coverage report'
required: false
default: ''
artifact-name:
description: 'Review artifact name prefix; change when using review more than once per job'
required: false
default: 'devscope-review'

outputs:
review-html:
description: 'Path to the offline HTML review report'
value: ${{ steps.compare.outputs.html-path }}
review-json:
description: 'Path to structured review data'
value: ${{ steps.compare.outputs.json-path }}
new-warnings:
description: 'Number of new review warnings (empty outside review mode)'
value: ${{ steps.compare.outputs.new-warnings }}
comparison-report:
description: 'Path to the Markdown comparison report (empty when disabled or outside a PR)'
value: ${{ steps.compare.outputs.report-path }}
Expand All @@ -60,6 +97,16 @@ outputs:
runs:
using: 'composite'
steps:
- name: Validate review options
shell: bash
env:
REVIEW_ENABLED: ${{ inputs.review }}
COMPARE_ENABLED: ${{ inputs.compare }}
NEW_GATE: ${{ inputs.fail-on-new }}
PACKAGE_SCOPE: ${{ inputs.package }}
COVERAGE_REPORT: ${{ inputs.coverage }}
run: bash "${{ github.action_path }}/scripts/validate-options.sh"

- name: Set up Python
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -90,14 +137,30 @@ runs:

- name: Compare PR snapshots
id: compare
if: github.event_name == 'pull_request' && inputs.compare == 'true'
if: github.event_name == 'pull_request' && (inputs.compare == 'true' || inputs.review == 'true')
shell: bash
env:
DEVSCOPE_PATH: ${{ inputs.path }}
DEVSCOPE_REVIEW: ${{ inputs.review }}
DEVSCOPE_FAIL_ON_NEW: ${{ inputs.fail-on-new }}
DEVSCOPE_PACKAGE: ${{ inputs.package }}
DEVSCOPE_COVERAGE: ${{ inputs.coverage }}
DEVSCOPE_COVERAGE_COMMIT: ${{ inputs.coverage-commit }}
DEVSCOPE_COVERAGE_ROOT: ${{ inputs.coverage-root }}
DEVSCOPE_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
DEVSCOPE_BASE: ${{ github.event.pull_request.base.sha }}
DEVSCOPE_HEAD: ${{ github.event.pull_request.head.sha }}
run: python "${{ github.action_path }}/scripts/compare.py"

- name: Upload review reports
if: github.event_name == 'pull_request' && inputs.review == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}-${{ runner.os }}
path: ${{ steps.compare.outputs.artifacts-dir }}
if-no-files-found: error
retention-days: 7

- name: Post PR comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
Expand All @@ -124,3 +187,10 @@ runs:
DEVSCOPE_MAX_RISK: ${{ inputs.max-risk }}
DEVSCOPE_MAX_ONBOARDING: ${{ inputs.max-onboarding }}
run: bash "${{ github.action_path }}/scripts/check-thresholds.sh"

- name: Enforce new-issue gate
if: steps.compare.outputs.gate-failed == 'true'
shell: bash
run: |
echo 'Devscope found new configured review warnings. See the PR report or downloaded artifact.' >&2
exit 2
6 changes: 2 additions & 4 deletions examples/pr-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
# Pinned integration commit; @v1 does not include comparison yet.
- uses: EhsanAzish80/devscope-action@b2058cd71ef51077b36cf1b9e84958f6d4b0a45a
- uses: EhsanAzish80/devscope-action@v1.2.0
id: devscope
with:
compare: 'true'
# Merged CLI commit containing compare; not an unreleased PyPI version.
devscope-ref: d9849fddd644f98a67985115af74c74ff0a5230e
devscope-version: '0.2.0'
22 changes: 22 additions & 0 deletions examples/review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Devscope review guidance
on: pull_request
permissions:
contents: read
pull-requests: write
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
# Source pins until the advanced Action and CLI are released.
- uses: EhsanAzish80/devscope-action@2c2f8f7d7e9d873057708bc6bb42e9c49c840dc9
with:
devscope-ref: 68c1fa668de53f71920e263bbb1f2325cb5f44d0
review: 'true'
fail-on-new: 'true'
# After generating coverage in an earlier step, optionally add:
# coverage: coverage.info
# coverage-commit: ${{ github.event.pull_request.head.sha }}
Loading
Loading