GitHub Action that scores pull requests by structural risk
Project description
pr-risk-scorer
A GitHub Action that scores pull requests by structural risk across five dimensions and posts the result as a PR comment.
Quick Start
Add this step to any workflow that runs on pull_request events:
- name: Score PR Risk
uses: FasterApiWeb/pr-risk-scorer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
threshold: 70 # fail if score > 70
fail_on_high: true
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
github_token |
Yes | — | Token used to post the PR comment (secrets.GITHUB_TOKEN works) |
threshold |
No | 70 |
Scores above this value are flagged as high risk |
fail_on_high |
No | true |
Exit with a non-zero code when score exceeds threshold |
Outputs
| Output | Description |
|---|---|
risk_score |
Numeric score 0–100 |
risk_level |
LOW, MEDIUM, or HIGH |
Score Breakdown
The total score is a weighted average of five analyzers (0 = no risk, 100 = maximum risk):
| Dimension | Weight | Method |
|---|---|---|
| Diff Size | 20% | Lines added + deleted, scaled to 1 000 max |
| Complexity | 30% | Average cyclomatic complexity of changed .py files via radon |
| Coverage Gap | 20% | 1 − line_rate from coverage.xml (inverse of test coverage) |
| Dead Code | 15% | Count of unused symbols via vulture, capped at 20 items |
| Migrations | 15% | Presence of DB migration files (0 → 0, 1 → 60, 2 → 80, 3+ → 100) |
Risk Tiers
| Emoji | Level | Score Range |
|---|---|---|
| 🟢 | LOW | < 40 |
| 🟡 | MEDIUM | 40 – 70 |
| 🔴 | HIGH | > 70 |
Example PR Comment
Screenshot placeholder — paste a screenshot of a real PR comment here after first run.
## PR Risk Score: 🟡 MEDIUM (54.5 / 100)
> Threshold: 70 | Status: ✅ PASS
| Analyzer | Score | Risk |
|------------------|------:|-------------|
| Diff Size (20%) | 42.0 | 🟡 MEDIUM |
| Complexity (30%) | 60.0 | 🟡 MEDIUM |
| Coverage Gap (20%)| 55.0| 🟡 MEDIUM |
| Dead Code (15%) | 20.0 | 🟢 LOW |
| Migrations (15%) | 0.0 | 🟢 LOW |
Full Example Workflow
name: PR Quality Gate
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
risk-score:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # required for git diff HEAD~1
- name: Generate coverage report
run: |
pip install pytest pytest-cov
pytest --cov=src --cov-report=xml
- name: Score PR Risk
uses: FasterApiWeb/pr-risk-scorer@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
threshold: 70
fail_on_high: true
Local Development
# Install hatch
pip install hatch
# Run tests
hatch run test
# Type check
hatch run typecheck
# Lint for dead code
hatch run lint
Contributing
See CONTRIBUTING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pr_risk_scorer-0.2.0.tar.gz.
File metadata
- Download URL: pr_risk_scorer-0.2.0.tar.gz
- Upload date:
- Size: 72.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
837ffa2e095fde2225526639407de7e928c9618d5380330a56d129a91913b368
|
|
| MD5 |
ef9081f7882da5f99964dc8ccff8c071
|
|
| BLAKE2b-256 |
017d4a8150de6f18414934730ecec60dc74e2bdb90c1934f85528f6b1e7c001b
|
Provenance
The following attestation bundles were made for pr_risk_scorer-0.2.0.tar.gz:
Publisher:
publish.yml on FasterApiWeb/pr-risk-scorer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pr_risk_scorer-0.2.0.tar.gz -
Subject digest:
837ffa2e095fde2225526639407de7e928c9618d5380330a56d129a91913b368 - Sigstore transparency entry: 1369900852
- Sigstore integration time:
-
Permalink:
FasterApiWeb/pr-risk-scorer@df55698e8a3ccb676c336e5b743fa9a715a7586b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/FasterApiWeb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df55698e8a3ccb676c336e5b743fa9a715a7586b -
Trigger Event:
push
-
Statement type:
File details
Details for the file pr_risk_scorer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pr_risk_scorer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e74e2b053348ab5a241afbe73d23c521072f0032cd8c9ecfc2c7a72156790db1
|
|
| MD5 |
801daa9805461ed7ff7c538fd5a19e5b
|
|
| BLAKE2b-256 |
0f83d65b2be9c3b2920d931bbdca336824b4449cd129e669434ad7bdc29fa153
|
Provenance
The following attestation bundles were made for pr_risk_scorer-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on FasterApiWeb/pr-risk-scorer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pr_risk_scorer-0.2.0-py3-none-any.whl -
Subject digest:
e74e2b053348ab5a241afbe73d23c521072f0032cd8c9ecfc2c7a72156790db1 - Sigstore transparency entry: 1369900950
- Sigstore integration time:
-
Permalink:
FasterApiWeb/pr-risk-scorer@df55698e8a3ccb676c336e5b743fa9a715a7586b -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/FasterApiWeb
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@df55698e8a3ccb676c336e5b743fa9a715a7586b -
Trigger Event:
push
-
Statement type: