1
0
mirror of https://github.com/robbyrussell/oh-my-zsh.git synced 2025-12-06 15:30:40 +01:00

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

Fixes cases like #13453
This commit is contained in:
Carlo Sala
2025-12-01 09:59:09 +01:00
committed by GitHub
parent a449c0247d
commit ca5c467db1

View File

@@ -219,32 +219,33 @@ class Dependency:
# Create new branch # Create new branch
branch = Git.checkout_or_create_branch(branch_name) branch = Git.checkout_or_create_branch(branch_name)
# Update dependencies.yml file
self.__update_yaml(
f"tag:{new_version}" if is_tag else status["version"]
)
# Update dependency files # Update dependency files
self.__apply_upstream_changes() self.__apply_upstream_changes()
# Add all changes and commit if not Git.repo_is_clean():
has_new_commit = Git.add_and_commit(self.name, new_version) # Update dependencies.yml file
self.__update_yaml(
if has_new_commit: f"tag:{new_version}" if is_tag else status["version"]
# Push changes to remote
Git.push(branch)
# Create GitHub PR
GitHub.create_pr(
branch,
f"feat({self.name}): update to version {new_version}",
f"""## Description
Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}).
Check out the [list of changes]({status['compare_url']}).
""",
) )
# Add all changes and commit
has_new_commit = Git.add_and_commit(self.name, new_version)
if has_new_commit:
# Push changes to remote
Git.push(branch)
# Create GitHub PR
GitHub.create_pr(
branch,
f"feat({self.name}): update to version {new_version}",
f"""## Description
Update for **{self.desc}**: update to version [{new_version}]({status["head_url"]}).
Check out the [list of changes]({status["compare_url"]}).
""",
)
# Clean up repository # Clean up repository
Git.clean_repo() Git.clean_repo()
except (CommandRunner.Exception, shutil.Error) as e: except (CommandRunner.Exception, shutil.Error) as e:
@@ -275,8 +276,8 @@ Check out the [list of changes]({status['compare_url']}).
There is a new version of `{self.name}` {self.kind} available. There is a new version of `{self.name}` {self.kind} available.
New version: [{new_version}]({status['head_url']}) New version: [{new_version}]({status["head_url"]})
Check out the [list of changes]({status['compare_url']}). Check out the [list of changes]({status["compare_url"]}).
""" """
print("Creating GitHub issue", file=sys.stderr) print("Creating GitHub issue", file=sys.stderr)
@@ -377,21 +378,28 @@ class Git:
) )
return branch_name return branch_name
@staticmethod
def repo_is_clean() -> bool:
"""
Returns `True` if the repo is clean.
Returns `False` if the repo is dirty.
"""
try:
CommandRunner.run_or_fail(
["git", "diff", "--exit-code"], stage="CheckRepoClean"
)
return True
except CommandRunner.Exception:
return False
@staticmethod @staticmethod
def add_and_commit(scope: str, version: str) -> bool: def add_and_commit(scope: str, version: str) -> bool:
""" """
Returns `True` if there were changes and were indeed commited. Returns `True` if there were changes and were indeed commited.
Returns `False` if the repo was clean and no changes were commited. Returns `False` if the repo was clean and no changes were commited.
""" """
# check if repo is clean (clean => no error, no commit) if Git.repo_is_clean():
try:
CommandRunner.run_or_fail(
["git", "diff", "--exit-code"], stage="CheckRepoClean"
)
return False return False
except CommandRunner.Exception:
# if it's other kind of error just throw!
pass
user_name = os.environ.get("GIT_APP_NAME") user_name = os.environ.get("GIT_APP_NAME")
user_email = os.environ.get("GIT_APP_EMAIL") user_email = os.environ.get("GIT_APP_EMAIL")