Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.4.0 #79

Merged
merged 28 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c85ea5c
Release v0.3.0
jeremystretch Aug 12, 2024
a7d93d3
Add PR template
jeremystretch Aug 15, 2024
e7ed801
Update GitHub issue labels
jeremystretch Aug 15, 2024
61bc942
Fixes #42: Fix exception raised when viewing custom scripts
jeremystretch Aug 15, 2024
af99c92
Fixes #44: Handle truncated sequence names to avoid exception during …
jeremystretch Aug 15, 2024
d8fad3a
Fixes #48: Roll back the transaction before re-raising any exceptions…
jeremystretch Aug 15, 2024
2dfcb5d
Remove ability to publish to test PyPI
jeremystretch Aug 16, 2024
792da7f
Fixes #50: Branch state should remain 'merged' after dry-run revert
jeremystretch Aug 16, 2024
c16d68f
Release v0.3.1
jeremystretch Aug 16, 2024
3b34de3
Merge branch 'release' into develop
jeremystretch Aug 16, 2024
ade37d1
Closes #47: Clean up raw SQL queries & sanitize arguments to nextval()
jeremystretch Aug 16, 2024
eb783f5
Adjust migration dependencies for NetBox v4.1.0
jeremystretch Sep 2, 2024
d1ed4c3
Fixes #57: Record ChangeDiffs only for supported object types
jeremystretch Aug 20, 2024
ea5ea27
Closes #52: Introduce the `max_branches` config parameter (#63)
jeremystretch Sep 3, 2024
6644bbb
Fixes #59: BranchAwareRouter should disregard models which do not sup…
jeremystretch Sep 2, 2024
2393105
Update changelog
jeremystretch Sep 3, 2024
2b58427
Show schema ID under branch details
jeremystretch Sep 3, 2024
872e112
Fixes #61: Fix transaction rollback when performing a dry run sync
jeremystretch Sep 3, 2024
e9cefe6
Add GHA workflow to run lint and tests (#27)
mfiedorowicz Sep 4, 2024
f6db858
Fixes #66: Capture object representation on ChangeDiff when creating …
jeremystretch Sep 4, 2024
80362e6
#61: Address a regression in the original fix
jeremystretch Sep 4, 2024
73f7134
Closes #68: Replace ruff with pycodestyle
jeremystretch Sep 4, 2024
62f4203
Fixes #73: Ensure all relevant ChangeDiffs are updated when an object…
jeremystretch Sep 4, 2024
07904b2
Fixes #69: Represent null values for ChangeDiff fields consistently i…
jeremystretch Sep 4, 2024
2b6bd55
Closes #76: Check for required settings on init
jeremystretch Sep 5, 2024
54b3236
Closes #71: Apply logging consistently for all branch operations
jeremystretch Sep 5, 2024
c1b44e9
Release v0.4.0
jeremystretch Sep 5, 2024
dd3885b
Merge branch 'release' into develop
jeremystretch Sep 5, 2024
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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/01-feature_request.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: ✨ Feature Request
description: Propose a new NetBox feature or enhancement
labels: ["feature"]
labels: ["type: feature"]
body:
- type: input
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/02-bug_report.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 🐛 Bug Report
description: Report a reproducible bug in the current stable release
labels: ["bug"]
labels: ["type: bug"]
body:
- type: input
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/03-documentation_change.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 📖 Documentation Change
description: Suggest an addition or modification to the plugin's documentation
labels: ["documentation"]
labels: ["type: documentation"]
body:
- type: dropdown
attributes:
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/04-housekeeping.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: 🏡 Housekeeping
description: A change pertaining to the codebase itself (developers only)
labels: ["housekeeping"]
labels: ["type: housekeeping"]
body:
- type: textarea
attributes:
Expand Down
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!--
Please note that pull requests are accepted ONLY for approved
issues. Specify the issue resolved by this PR below.
-->
### Fixes: #1234

<!--
Please include a summary of the changes within this PR below.
-->
96 changes: 96 additions & 0 deletions .github/workflows/lint-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Lint and tests
on:
workflow_dispatch:
pull_request:
push:
branches:
- "!release"

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

permissions:
contents: write
checks: write
pull-requests: write

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install .[dev]
pip install .[test]
- name: Build documentation
run: mkdocs build
- name: Run pycodestyle
run: |
pycodestyle --ignore=W504,E501 netbox_branching/
tests:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres
env:
POSTGRES_USER: netbox
POSTGRES_PASSWORD: netbox
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout netbox-branching
uses: actions/checkout@v4
with:
path: netbox-branching
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Checkout netbox
uses: actions/checkout@v4
with:
repository: "netbox-community/netbox"
path: netbox
- name: Install netbox-branching
working-directory: netbox-branching
run: |
# Include tests directory for test
sed -i 's/exclude-package-data/#exclude-package-data/g' pyproject.toml
python -m pip install --upgrade pip
pip install .
pip install .[test]
- name: Install dependencies & configure plugin
working-directory: netbox
run: |
ln -s $(pwd)/../netbox-branching/testing/configuration.py netbox/netbox/configuration.py
ln -s $(pwd)/../netbox-branching/testing/local_settings.py netbox/netbox/local_settings.py

python -m pip install --upgrade pip
pip install -r requirements.txt -U
- name: Run tests
working-directory: netbox
run: |
python netbox/manage.py test netbox_branching.tests --keepdb
14 changes: 0 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
name: Release
on:
workflow_dispatch:
inputs:
pypi:
description: 'PyPI instance'
required: true
type: choice
default: 'production'
options:
- production
- testing
push:
branches: [ release ]

Expand All @@ -20,8 +10,6 @@ concurrency:
env:
PYTHON_RUNTIME_VERSION: "3.11"
PYTHON_PACKAGE_NAME: netboxlabs-netbox-branching
PYPI_URL_PRODUCTION: "https://upload.pypi.org/legacy/"
PYPI_URL_TESTING: "https://test.pypi.org/legacy/"

jobs:
get-package-name:
Expand Down Expand Up @@ -106,12 +94,10 @@ jobs:
- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ github.event.inputs.pypi == 'production' && env.PYPI_URL_PRODUCTION || env.PYPI_URL_TESTING }}
packages-dir: dist
release:
name: Release
needs: [ get-next-version, get-release-notes, build ]
if: github.event.inputs.pypi == 'production'
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
Expand Down
32 changes: 32 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Change Log

## v0.4.0

### Enhancements

* [#52](https://github.com/netboxlabs/nbl-netbox-branching/issues/52) - Introduce the `max_branches` config parameter
* [#71](https://github.com/netboxlabs/nbl-netbox-branching/issues/71) - Ensure the consistent application of logging messages
* [#76](https://github.com/netboxlabs/nbl-netbox-branching/issues/76) - Validate required configuration items on initialization

### Bug Fixes

* [#57](https://github.com/netboxlabs/nbl-netbox-branching/issues/57) - Avoid recording ChangeDiff records for unsupported object types
* [#59](https://github.com/netboxlabs/nbl-netbox-branching/issues/59) - `BranchAwareRouter` should consider branching support for model when determining database connection to use
* [#61](https://github.com/netboxlabs/nbl-netbox-branching/issues/61) - Fix transaction rollback when performing a dry run sync
* [#66](https://github.com/netboxlabs/nbl-netbox-branching/issues/66) - Capture object representation on ChangeDiff when creating a new object within a branch
* [#69](https://github.com/netboxlabs/nbl-netbox-branching/issues/69) - Represent null values for ChangeDiff fields consistently in REST API
* [#73](https://github.com/netboxlabs/nbl-netbox-branching/issues/73) - Ensure all relevant branch diffs are updated when an object is modified in main

---

## v0.3.1

### Bug Fixes

* [#42](https://github.com/netboxlabs/nbl-netbox-branching/issues/42) - Fix exception raised when viewing custom scripts
* [#44](https://github.com/netboxlabs/nbl-netbox-branching/issues/44) - Handle truncated SQL sequence names to avoid exceptions during branch provisioning
* [#48](https://github.com/netboxlabs/nbl-netbox-branching/issues/48) - Ensure background job is terminated in the event branch provisioning errors
* [#50](https://github.com/netboxlabs/nbl-netbox-branching/issues/50) - Branch state should remain as "merged" after dry-run revert

---

## v0.3.0

### Enhancements
Expand All @@ -22,6 +52,8 @@
* [#30](https://github.com/netboxlabs/nbl-netbox-branching/issues/30) - Include only unmerged branches with relevant changes in object view notifications
* [#31](https://github.com/netboxlabs/nbl-netbox-branching/issues/31) - Prevent the deletion of a branch in a transitional state

---

## v0.2.0

* Initial private release
17 changes: 17 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configuration Parameters

## `max_branches`

Default: None

The maximum number of branches that can exist simultaneously, including merged branches that have not been deleted. It may be desirable to limit the total number of provisioned branches to safeguard against excessive database size.

---

## `schema_prefix`

Default: `branch_`

The string to prefix to the unique branch ID when provisioning the PostgreSQL schema for a branch. Per [the PostgreSQL documentation](https://www.postgresql.org/docs/16/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS), this string must begin with a letter or underscore.

Note that a valid prefix is required, as the randomly-generated branch ID alone may begin with a digit, which would not qualify as a valid schema name.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nav:
- Syncing & Merging: 'using-branches/syncing-merging.md'
- Reverting a Branch: 'using-branches/reverting-a-branch.md'
- REST API: 'rest-api.md'
- Configuration: 'configuration.md'
- Data Model:
- Branch: 'models/branch.md'
- BranchEvent: 'models/branchevent.md'
Expand Down
29 changes: 27 additions & 2 deletions netbox_branching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from netbox.plugins import PluginConfig
from netbox.registry import registry


class AppConfig(PluginConfig):
name = 'netbox_branching'
verbose_name = 'NetBox Branching'
description = 'A git-like branching implementation for NetBox'
version = '0.3.0'
version = '0.4.0'
base_url = 'branching'
min_version = '4.1'
middleware = [
'netbox_branching.middleware.BranchMiddleware'
]
default_settings = {
# The maximum number of branches which can be provisioned simultaneously
'max_branches': None,

# This string is prefixed to the name of each new branch schema during provisioning
'schema_prefix': 'branch_',
}

def ready(self):
super().ready()
from . import events, search, signal_receivers
from . import constants, events, search, signal_receivers
from .utilities import DynamicSchemaDict

# Validate required settings
if type(settings.DATABASES) is not DynamicSchemaDict:
raise ImproperlyConfigured(
"netbox_branching: DATABASES must be a DynamicSchemaDict instance."
)
if 'netbox_branching.database.BranchAwareRouter' not in settings.DATABASE_ROUTERS:
raise ImproperlyConfigured(
"netbox_branching: DATABASE_ROUTERS must contain 'netbox_branching.database.BranchAwareRouter'."
)

# Record all object types which support branching in the NetBox registry
if 'branching' not in registry['model_features']:
registry['model_features']['branching'] = {
k: v for k, v in registry['model_features']['change_logging'].items()
if k not in constants.EXCLUDED_APPS
}


config = AppConfig
6 changes: 6 additions & 0 deletions netbox_branching/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@

# URL query parameter name
QUERY_PARAM = '_branch'

# Apps which are explicitly excluded from branching
EXCLUDED_APPS = (
'netbox_branching',
'netbox_changes',
)
18 changes: 13 additions & 5 deletions netbox_branching/database.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from netbox.registry import registry

from .contextvars import active_branch


Expand All @@ -11,15 +13,21 @@ class BranchAwareRouter:
A Django database router that returns the appropriate connection/schema for
the active branch (if any).
"""
def db_for_read(self, model, **hints):
def _get_db(self, model, **hints):
# Bail if the model does not support branching
app_label, model_name = model._meta.label.lower().split('.')
if model_name not in registry['model_features']['branching'].get(app_label, []):
return

# Return the schema for the active branch (if any)
if branch := active_branch.get():
return f'schema_{branch.schema_name}'
return None

def db_for_read(self, model, **hints):
return self._get_db(model, **hints)

def db_for_write(self, model, **hints):
if branch := active_branch.get():
return f'schema_{branch.schema_name}'
return None
return self._get_db(model, **hints)

def allow_relation(self, obj1, obj2, **hints):
# Permit relations from the branch schema to the main (public) schema
Expand Down
2 changes: 1 addition & 1 deletion netbox_branching/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('core', '0011_move_objectchange'),
('extras', '0118_notifications'),
('extras', '0119_notifications'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

Expand Down
Loading