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]
|
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)
|
||||||
repo.index.add(str(path))
|
if repo.index.diff(None):
|
||||||
c = repo.index.commit(f'{name}: Update to {latest}')
|
log.debug('Committing changes to %s', path)
|
||||||
log.info('Commited %s %s', str(c)[:7], c.summary)
|
repo.index.add(str(path))
|
||||||
return c
|
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:
|
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(
|
||||||
|
|
Loading…
Reference in New Issue