Handle the case where no changes are needed

Naturally, there will be times when `updatebot` runs and there are no
changes to make, because the deployed applications are already
up-to-date.  In this scenario, we need to avoid making empty commits and
attempting to create a PR with no changes.
master
Updatebot 2024-08-26 08:31:38 -05:00 committed by Dustin C. Hatch
parent 457f9a3321
commit 54ef1fe206
1 changed files with 14 additions and 7 deletions

View File

@ -224,19 +224,25 @@ class Arguments:
projects: list[str] projects: list[str]
def update_project(repo: git.Repo, name: str, project: Project) -> git.Commit: def update_project(
repo: git.Repo, name: str, project: Project
) -> Optional[git.Commit]:
basedir = Path(repo.working_dir) basedir = Path(repo.working_dir)
log.debug('Checking for latest version of %s', name) log.debug('Checking for latest version of %s', name)
latest = project.source.get_latest_version() latest = project.source.get_latest_version()
log.info('Found version %s for %s', latest, name) log.info('Found version %s for %s', latest, name)
log.debug('Applying update for %s version %s', name, latest) log.debug('Applying update for %s version %s', name, latest)
path = basedir / (project.path or name) path = basedir / (project.path or name)
log.debug('Committing changes to %s', path)
project.apply_update(path, latest) project.apply_update(path, latest)
if repo.index.diff(None):
log.debug('Committing changes to %s', path)
repo.index.add(str(path)) repo.index.add(str(path))
c = repo.index.commit(f'{name}: Update to {latest}') c = repo.index.commit(f'{name}: Update to {latest}')
log.info('Commited %s %s', str(c)[:7], c.summary) log.info('Commited %s %s', str(c)[:7], c.summary)
return c return c
else:
log.info('No changes to commit')
return None
def parse_args() -> Arguments: def parse_args() -> Arguments:
@ -309,7 +315,7 @@ def main() -> None:
title = None title = None
for project in projects: for project in projects:
commit = update_project(repo, project, config.projects[project]) commit = update_project(repo, project, config.projects[project])
if not title: if commit and not title:
if not isinstance(commit.summary, str): if not isinstance(commit.summary, str):
title = bytes(commit.summary).decode( title = bytes(commit.summary).decode(
'utf-8', errors='replace' 'utf-8', errors='replace'
@ -317,6 +323,7 @@ def main() -> None:
else: else:
title = commit.summary title = commit.summary
if not title: if not title:
log.info('No changes made')
return return
repo.head.reference.set_tracking_branch( repo.head.reference.set_tracking_branch(
git.RemoteReference( git.RemoteReference(