Branch Review for NetBox
Project description
Netbox-Branch-Review
Branch-aware change request & approval workflow for NetBox that can gate branch merges until a Change Request (CR) is approved.
Features
- Create and track Change Requests linked to branches
- One- or two-level approvals (configurable)
- Merge gate: blocks merges until CR is approved or scheduled
- Simple UI actions: Approve and Merge from the CR detail page
- API serializers/viewset for integration
- Optional peer review action & audit log of approvals / merge events
- Revoke (undo) approvals before implementation, resetting status to Pending
Requirements
- NetBox 4.x
- Netbox-Branching plugin for branch operations (the merge gate integrates with it)
- Python 3.10+
Installation
- Install the plugin:
pip install netbox-branch-review
- Enable in NetBox configuration.py:
PLUGINS = [
"netbox_branch_review",
"netbox_branching",
]
PLUGINS_CONFIG = {
"netbox_branch_review": {
# Require two approvals before merge (default: True)
"require_two_approvals": True,
# Enforce branching integration (default: True)
"enforce_branching": True,
# Approval implies branch changes are acceptable; merge button appears once approved.
}
}
- Migrate:
python manage.py migrate
- Restart NetBox.
Quick Start (Groups & Permissions)
Run the management command to create/sync default groups and permissions:
python manage.py sync_change_review
This will ensure:
- Group "Change Managers" gets approve / merge / peer review permissions.
- Group "Change Reviewers" gets only the peer review permission.
Customize names:
python manage.py sync_change_review --managers "My Managers" --reviewers "My Reviewers"
Skip peer group creation:
python manage.py sync_change_review --no-peer-group
Usage
- Navigate to Plugins → Change Requests (menu declared in
menu.py) - Create a CR (form:
ChangeRequestForm) - The CR form includes an optional Ticket field for referencing external systems.
- From the CR page, Approve and Merge using the actions in the header
See also: Quick Tour with screenshots.
Approval & Peer Review Flow
Config key: require_two_approvals (default True)
Self full approval: allow_self_full_approval (default True) lets the CR creator (who has approval permission) fully approve in one action even when two approvals are normally required (records both levels in audit with an implicit second approval entry).
| Scenario | Action 1 | Action 2 | Status progression |
|---|---|---|---|
| Two approvals required | First approval (different user recorded, or creator self-approval if allowed) | Second approval (must be different user unless self full approval triggered) | Pending → In review → Approved (or direct to Approved if self full) |
| Single approval mode | First approval | (Further approvals blocked for same user) | Pending → Approved |
Peer Review (optional): A user with only peer_review_changerequest can record a peer review before approval. Peer reviews do NOT change status; they are logged for audit & visibility.
Merge sets status to “Implemented”. Duplicate approvals or attempts after final approval are logged and safely ignored.
The merge gate validator require_cr_approved_before_merge enforces:
- Two approvals when configured
- Status must be Approved or Scheduled
Permissions & Suggested Groups
Custom permissions defined on the model: ChangeRequest.Meta.permissions
| Codename | Purpose |
|---|---|
| approve_changerequest | Perform L1/L2 approvals (depending on config) |
| merge_changerequest | Execute merge / implement action |
| peer_review_changerequest | Record a peer review (no status change) |
| revoke_changerequest | Revoke existing approvals (pre-implementation) |
Because NetBox’s Group UI currently only lists standard model permissions in the multiselect, custom codenames may not appear for manual selection. The plugin’s post_migrate signal ensures they are created; you can assign them via shell if needed.
Suggested groups:
- Change Managers:
approve_changerequest,merge_changerequest(optionally alsopeer_review_changerequest). - Change Reviewers:
peer_review_changerequest(andview_changerequestif not already provided globally).
Example shell assignment:
python manage.py shell -c "from django.contrib.auth.models import Group,Permission; mgr,_=Group.objects.get_or_create(name='Change Managers'); rev,_=Group.objects.get_or_create(name='Change Reviewers'); mgr.permissions.add(*Permission.objects.filter(codename__in=['approve_changerequest','merge_changerequest','peer_review_changerequest'])); rev.permissions.add(Permission.objects.get(codename='peer_review_changerequest'))"
Check a user’s effective perms:
python manage.py shell -c "from django.contrib.auth import get_user_model; u=get_user_model().objects.get(username='alice'); print([p for p in sorted(u.get_all_permissions()) if p.startswith('netbox_branch_review.')])"
Audit Log
Each approval, peer review, merge, revoke, or blocked duplicate attempt writes an entry to ChangeRequestAudit (displayed on the CR detail page). The last 10 entries render as badges; extend as needed.
Revoking Approvals (Undo)
Users with revoke_changerequest can revert a Change Request back to Pending (prior to implementation). This:
- Creates audit entries for each revoked level (L2 then L1) plus a summary revoke_full entry.
- Clears
approver_1,approver_2and their timestamps. - Sets status to
pending.
Limitations:
- Can't revoke after status reaches Implemented.
- Self full approvals (implicit level 2) will be fully cleared in one revoke action.
UI: A Revoke Approvals button appears when (a) the user has the permission, (b) the CR isn't implemented, and (c) at least one approval exists.
API
- Serializer:
ChangeRequestSerializer - ViewSet:
ChangeRequestViewSet
Note: Expose routes via the NetBox plugin API router as needed. The serializer exposes all CR fields, including ticket.
Project layout
netbox-branch-review/
├── pyproject.toml
├── README.md
└── netbox_branch_review/
├── __init__.py
# (plugin.py not used; configuration lives in __init__.py)
├── models.py
├── choices.py
├── forms.py
├── filtersets.py
├── tables.py
├── navigation.py
├── menu.py
├── urls.py
├── views.py
├── signals.py
├── validators.py
├── api/
│ ├── __init__.py
│ ├── serializers.py
│ └── views.py
├── templates/
│ └── netbox_branch_review/
│ ├── changerequest_list.html
│ ├── changerequest.html
│ └── includes/
│ └── changerequest_header.html
└── migrations/
├── 0001_initial.py
├── 0002_add_description.py
├── 0003_merge.py
└── 0004_add_comments.py
Notes
- The plugin registers the merge gate during
ready()by callingregister_pre_merge_validator()if available (see__init__.py). If the branching plugin is not present, merge enforcement gracefully no-ops, and UI will warn when branch data - Default groups may also be auto-created during
post_migratebased on plugin settings (see__init__.pyandsignals.py), but the management command provides a clear, repeatable onboarding step.
Project details
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 netbox_branch_review-0.2.0.tar.gz.
File metadata
- Download URL: netbox_branch_review-0.2.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fe521f4cd9da237c13164b6a48885b4741df2488cb6a5e16887a87ebb7afcb1
|
|
| MD5 |
e2b45a33d271ec8e41394f54e404df50
|
|
| BLAKE2b-256 |
12bb08dd5b9f73fdafc3c339ebc845ae9d18c80f71099b8f3793f89ef70b702f
|
File details
Details for the file netbox_branch_review-0.2.0-py3-none-any.whl.
File metadata
- Download URL: netbox_branch_review-0.2.0-py3-none-any.whl
- Upload date:
- Size: 27.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f846f1e489a62bc907a2d18bddd3f68391ae4854e738e52108cd646e7c555bb
|
|
| MD5 |
862e21320b477a90ed5dba26cabe1c6a
|
|
| BLAKE2b-256 |
9ca16a7d5bbcf8ccff61c17e186521ab2224695009109dfbff6cf5f739859415
|