Skip to content

Commit

Permalink
Get commit message from branch instead of main when updating template
Browse files Browse the repository at this point in the history
branch sync status for devices
  • Loading branch information
indy-independence committed Oct 28, 2024
1 parent f4c4c58 commit a810f92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cnaas_nms/db/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _refresh_repo_task(repo_type: RepoType = RepoType.TEMPLATES, job_id: Optiona
devtype: DeviceType
for devtype, platform in updated_devtypes:
Device.set_devtype_syncstatus(session, devtype, ret, "templates", platform, job_id)
refresh_existing_templates_worktrees(ret, job_id, get_group_settings_asdict(), get_device_primary_groups())
refresh_existing_templates_worktrees(job_id, get_group_settings_asdict(), get_device_primary_groups())

return ret

Expand Down
17 changes: 15 additions & 2 deletions src/cnaas_nms/db/git_worktrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WorktreeError(Exception):
pass


def refresh_existing_templates_worktrees(by: str, job_id: int, group_settings: dict, device_primary_groups: dict):
def refresh_existing_templates_worktrees(job_id: int, group_settings: dict, device_primary_groups: dict):
"""Look for existing worktrees and refresh them"""
logger = get_logger()
updated_groups: Set[str] = set()
Expand All @@ -28,6 +28,19 @@ def refresh_existing_templates_worktrees(by: str, job_id: int, group_settings: d
diff = wt_repo.remotes.origin.pull()
if not diff:
continue

ret: str = ""
for item in diff:
# only check for changes in our branch
if item.ref.remote_head != wt_repo.head.ref.name:
continue

ret += "Commit {} by {} at {}\n".format(
item.commit.name_rev, item.commit.committer, item.commit.committed_datetime
)
# don't update updated_groups if changes were only in other branches
if not ret:
continue
except Exception as e:
logger.exception(e)
shutil.rmtree("/tmp/worktrees/" + subdir, ignore_errors=True)
Expand All @@ -43,7 +56,7 @@ def refresh_existing_templates_worktrees(by: str, job_id: int, group_settings: d
dev: Device = session.query(Device).filter_by(hostname=hostname).one_or_none()
if dev:
dev.synchronized = False
add_sync_event(hostname, "refresh_templates", by, job_id)
add_sync_event(hostname, "refresh_templates", ret, job_id)
updated_hostnames.add(hostname)
if updated_hostnames:
logger.debug(
Expand Down

0 comments on commit a810f92

Please sign in to comment.