fix(dependencies): only open PR if there are changes

This commit is contained in:
Carlo Sala 2024-05-21 20:43:26 +02:00
parent 309129f651
commit 0621944db5
No known key found for this signature in database
GPG key ID: DA6FB450C1A4FE9A

View file

@ -228,8 +228,9 @@ class Dependency:
self.__apply_upstream_changes()
# Add all changes and commit
Git.add_and_commit(self.name, short_sha)
has_new_commit = Git.add_and_commit(self.name, short_sha)
if has_new_commit:
# Push changes to remote
Git.push(branch)
@ -377,7 +378,21 @@ class Git:
return branch_name
@staticmethod
def add_and_commit(scope: str, version: str):
def add_and_commit(scope: str, version: str) -> bool:
"""
Returns `True` if there were changes and were indeed commited.
Returns `False` if the repo was clean and no changes were commited.
"""
# check if repo is clean (clean => no error, no commit)
try:
CommandRunner.run_or_fail(
["git", "diff", "--exit-code"], stage="CheckRepoClean"
)
return False
except CommandRunner.Exception:
# if it's other kind of error just throw!
pass
user_name = os.environ.get("GIT_APP_NAME")
user_email = os.environ.get("GIT_APP_EMAIL")
@ -390,12 +405,6 @@ class Git:
clean_env["GIT_CONFIG_GLOBAL"] = "/dev/null"
clean_env["GIT_CONFIG_NOSYSTEM"] = "1"
# check if repo is clean (clean => no error, no commit)
try:
CommandRunner.run_or_fail(
["git", "diff", "--exit-code"], stage="CheckRepoClean", env=clean_env
)
except CommandRunner.Exception:
# Commit with settings above
CommandRunner.run_or_fail(
[
@ -411,6 +420,7 @@ class Git:
stage="CreateCommit",
env=clean_env,
)
return True
@staticmethod
def push(branch: str):