Skip to content

Commit e9f7ca4

Browse files
committed
Merge branch 'main' into feature
2 parents 859e1ef + de954b7 commit e9f7ca4

File tree

7 files changed

+87
-30
lines changed

7 files changed

+87
-30
lines changed

.hooks/mkdocs-build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
echo "Running mkdocs build..."
5+
6+
TEMP_SITE_DIR=$(mktemp -d)
7+
8+
# Run mkdocs build into temp dir
9+
if mkdocs build --site-dir "$TEMP_SITE_DIR" --strict; then
10+
echo "Build successful."
11+
else
12+
echo "Build failed." >&2
13+
exit 1
14+
fi
15+
16+
# Cleanup
17+
rm -rf "$TEMP_SITE_DIR"

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.11.12
4+
hooks:
5+
- id: ruff
6+
name: "Ruff linter"
7+
args: [ netbox_branching/ ]
8+
- repo: local
9+
hooks:
10+
- id: mkdocs-build
11+
name: "Build documentation"
12+
description: "Build the documentation with mkdocs"
13+
files: 'docs/'
14+
entry: .hooks/mkdocs-build.sh
15+
language: system
16+
pass_filenames: false

docs/changelog.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Change Log
22

3+
## v0.5.6
4+
5+
### Enhancements
6+
7+
* [#262](https://github.com/netboxlabs/netbox-branching/issues/262) - Copy migrations table when provisioning a branch
8+
9+
### Bug Fixes
10+
11+
* [#256](https://github.com/netboxlabs/netbox-branching/issues/256) - Fix "changes ahead" count on branches pending provisioning
12+
* [#260](https://github.com/netboxlabs/netbox-branching/issues/260) - Ignore duplicate SQL indexes when provisioning a branch
13+
* [#275](https://github.com/netboxlabs/netbox-branching/issues/275) - Set `sync_time` on branch during initial provisioning
14+
15+
---
16+
317
## v0.5.5
418

519
### Bug Fixes

netbox_branching/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AppConfig(PluginConfig):
1111
name = 'netbox_branching'
1212
verbose_name = 'NetBox Branching'
1313
description = 'A git-like branching implementation for NetBox'
14-
version = '0.5.5'
14+
version = '0.5.6'
1515
base_url = 'branching'
1616
min_version = '4.2.3'
1717
middleware = [

netbox_branching/models/branches.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,6 @@ def schema_name(self):
136136
def connection_name(self):
137137
return f'schema_{self.schema_name}'
138138

139-
@property
140-
def synced_time(self):
141-
return self.last_sync or self.created
142-
143139
def clean(self):
144140

145141
# Enforce the maximum number of total branches
@@ -222,32 +218,36 @@ def get_unsynced_changes(self):
222218
"""
223219
Return a queryset of all ObjectChange records created in main since the Branch was last synced or created.
224220
"""
225-
if self.status not in BranchStatusChoices.WORKING:
226-
return ObjectChange.objects.none()
227-
return ObjectChange.objects.using(DEFAULT_DB_ALIAS).exclude(
228-
application__branch=self
229-
).filter(
230-
changed_object_type__in=get_branchable_object_types(),
231-
time__gt=self.synced_time
232-
)
221+
# TODO: Remove this fallback logic in a future release
222+
# Backward compatibility for branches created before v0.5.6, which did not have last_sync set automatically
223+
# upon provisioning. Defaults to the branch creation time.
224+
last_sync = self.last_sync or self.created
225+
if self.status == BranchStatusChoices.READY:
226+
return ObjectChange.objects.using(DEFAULT_DB_ALIAS).exclude(
227+
application__branch=self
228+
).filter(
229+
changed_object_type__in=get_branchable_object_types(),
230+
time__gt=last_sync
231+
)
232+
return ObjectChange.objects.none()
233233

234234
def get_unmerged_changes(self):
235235
"""
236236
Return a queryset of all unmerged ObjectChange records within the Branch schema.
237237
"""
238-
if self.status not in BranchStatusChoices.WORKING:
239-
return ObjectChange.objects.none()
240-
return ObjectChange.objects.using(self.connection_name)
238+
if self.status == BranchStatusChoices.READY:
239+
return ObjectChange.objects.using(self.connection_name)
240+
return ObjectChange.objects.none()
241241

242242
def get_merged_changes(self):
243243
"""
244244
Return a queryset of all merged ObjectChange records for the Branch.
245245
"""
246-
if self.status not in (BranchStatusChoices.MERGED, BranchStatusChoices.ARCHIVED):
247-
return ObjectChange.objects.none()
248-
return ObjectChange.objects.using(DEFAULT_DB_ALIAS).filter(
249-
application__branch=self
250-
)
246+
if self.status in (BranchStatusChoices.MERGED, BranchStatusChoices.ARCHIVED):
247+
return ObjectChange.objects.using(DEFAULT_DB_ALIAS).filter(
248+
application__branch=self
249+
)
250+
return ObjectChange.objects.none()
251251

252252
def get_event_history(self):
253253
history = []
@@ -269,10 +269,13 @@ def is_stale(self):
269269
"""
270270
Indicates whether the branch is too far out of date to be synced.
271271
"""
272+
if self.last_sync is None:
273+
# Branch has not yet been provisioned
274+
return False
272275
if not (changelog_retention := get_config().CHANGELOG_RETENTION):
273276
# Changelog retention is disabled
274277
return False
275-
return self.synced_time < timezone.now() - timedelta(days=changelog_retention)
278+
return self.last_sync < timezone.now() - timedelta(days=changelog_retention)
276279

277280
#
278281
# Branch action indicators
@@ -718,7 +721,10 @@ def provision(self, user):
718721

719722
logger.info('Provisioning completed')
720723

721-
Branch.objects.filter(pk=self.pk).update(status=BranchStatusChoices.READY)
724+
Branch.objects.filter(pk=self.pk).update(
725+
status=BranchStatusChoices.READY,
726+
last_sync=timezone.now(),
727+
)
722728
BranchEvent.objects.create(branch=self, user=user, type=BranchEventTypeChoices.PROVISIONED)
723729

724730
provision.alters_data = True

netbox_branching/templates/netbox_branching/branch.html

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,17 @@ <h5 class="card-header">{% trans "Branch" %}</h5>
8383
<tr>
8484
<th scope="row">{% trans "Last synced" %}</th>
8585
<td>
86-
{{ object.synced_time|isodatetime }}
87-
{% if object.is_stale %}
88-
<span class="text-danger" title="{% trans "Branch is stale and can no longer be synced" %}">
89-
<i class="mdi mdi-alert-circle"></i>
90-
</span>
86+
{% if object.last_sync %}
87+
{{ object.last_sync|isodatetime }}
88+
{% if object.is_stale %}
89+
<span class="text-danger" title="{% trans "Branch is stale and can no longer be synced" %}">
90+
<i class="mdi mdi-alert-circle"></i>
91+
</span>
92+
{% endif %}
93+
<div class="small text-muted">{{ object.last_sync|timesince }} {% trans "ago" %}</div>
94+
{% else %}
95+
{{ ''|placeholder }}
9196
{% endif %}
92-
<div class="small text-muted">{{ object.synced_time|timesince }} {% trans "ago" %}</div>
9397
</td>
9498
</tr>
9599
<tr>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "netboxlabs-netbox-branching"
3-
version = "0.5.5"
3+
version = "0.5.6"
44
description = "A git-like branching implementation for NetBox"
55
readme = "README.md"
66
requires-python = ">=3.10"

0 commit comments

Comments
 (0)