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
parent
457f9a3321
commit
54ef1fe206
21
updatebot.py
21
updatebot.py
|
@ -224,19 +224,25 @@ class Arguments:
|
|||
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)
|
||||
log.debug('Checking for latest version of %s', name)
|
||||
latest = project.source.get_latest_version()
|
||||
log.info('Found version %s for %s', latest, name)
|
||||
log.debug('Applying update for %s version %s', name, latest)
|
||||
path = basedir / (project.path or name)
|
||||
log.debug('Committing changes to %s', path)
|
||||
project.apply_update(path, latest)
|
||||
repo.index.add(str(path))
|
||||
c = repo.index.commit(f'{name}: Update to {latest}')
|
||||
log.info('Commited %s %s', str(c)[:7], c.summary)
|
||||
return c
|
||||
if repo.index.diff(None):
|
||||
log.debug('Committing changes to %s', path)
|
||||
repo.index.add(str(path))
|
||||
c = repo.index.commit(f'{name}: Update to {latest}')
|
||||
log.info('Commited %s %s', str(c)[:7], c.summary)
|
||||
return c
|
||||
else:
|
||||
log.info('No changes to commit')
|
||||
return None
|
||||
|
||||
|
||||
def parse_args() -> Arguments:
|
||||
|
@ -309,7 +315,7 @@ def main() -> None:
|
|||
title = None
|
||||
for project in projects:
|
||||
commit = update_project(repo, project, config.projects[project])
|
||||
if not title:
|
||||
if commit and not title:
|
||||
if not isinstance(commit.summary, str):
|
||||
title = bytes(commit.summary).decode(
|
||||
'utf-8', errors='replace'
|
||||
|
@ -317,6 +323,7 @@ def main() -> None:
|
|||
else:
|
||||
title = commit.summary
|
||||
if not title:
|
||||
log.info('No changes made')
|
||||
return
|
||||
repo.head.reference.set_tracking_branch(
|
||||
git.RemoteReference(
|
||||
|
|
Loading…
Reference in New Issue