ca5c467db1d495a4b5c0049a4cf476ca7f34b790

Author
Carlo Sala <carlosalag@protonmail.com>
Committer
GitHub <noreply@github.com>
Date

Message

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

Fixes cases like #13453

Diff

  1diff --git a/.github/workflows/dependencies/updater.py b/.github/workflows/dependencies/updater.py
  2index 02cff90304e8ae54dfa42597f8d4629b2dcc8d38..aee15d9e06e625c5de353934169d33d1b7e63058 100644
  3--- a/.github/workflows/dependencies/updater.py
  4+++ b/.github/workflows/dependencies/updater.py
  5@@ -219,31 +219,32 @@ class Dependency:
  6                     # Create new branch
  7                     branch = Git.checkout_or_create_branch(branch_name)
  8 
  9-                    # Update dependencies.yml file
 10-                    self.__update_yaml(
 11-                        f"tag:{new_version}" if is_tag else status["version"]
 12-                    )
 13-
 14                     # Update dependency files
 15                     self.__apply_upstream_changes()
 16 
 17-                    # Add all changes and commit
 18-                    has_new_commit = Git.add_and_commit(self.name, new_version)
 19+                    if not Git.repo_is_clean():
 20+                        # Update dependencies.yml file
 21+                        self.__update_yaml(
 22+                            f"tag:{new_version}" if is_tag else status["version"]
 23+                        )
 24+
 25+                        # Add all changes and commit
 26+                        has_new_commit = Git.add_and_commit(self.name, new_version)
 27 
 28-                    if has_new_commit:
 29-                        # Push changes to remote
 30-                        Git.push(branch)
 31+                        if has_new_commit:
 32+                            # Push changes to remote
 33+                            Git.push(branch)
 34 
 35-                        # Create GitHub PR
 36-                        GitHub.create_pr(
 37-                            branch,
 38-                            f"feat({self.name}): update to version {new_version}",
 39-                            f"""## Description
 40+                            # Create GitHub PR
 41+                            GitHub.create_pr(
 42+                                branch,
 43+                                f"feat({self.name}): update to version {new_version}",
 44+                                f"""## Description
 45 
 46-Update for **{self.desc}**: update to version [{new_version}]({status['head_url']}).
 47-Check out the [list of changes]({status['compare_url']}).
 48+Update for **{self.desc}**: update to version [{new_version}]({status["head_url"]}).
 49+Check out the [list of changes]({status["compare_url"]}).
 50 """,
 51-                        )
 52+                            )
 53 
 54                     # Clean up repository
 55                     Git.clean_repo()
 56@@ -275,8 +276,8 @@ Check out the [list of changes]({status['compare_url']}).
 57 
 58 There is a new version of `{self.name}` {self.kind} available.
 59 
 60-New version: [{new_version}]({status['head_url']})
 61-Check out the [list of changes]({status['compare_url']}).
 62+New version: [{new_version}]({status["head_url"]})
 63+Check out the [list of changes]({status["compare_url"]}).
 64 """
 65 
 66                     print("Creating GitHub issue", file=sys.stderr)
 67@@ -378,20 +379,27 @@ class Git:
 68         return branch_name
 69 
 70     @staticmethod
 71-    def add_and_commit(scope: str, version: str) -> bool:
 72+    def repo_is_clean() -> bool:
 73         """
 74-        Returns `True` if there were changes and were indeed commited.
 75-        Returns `False` if the repo was clean and no changes were commited.
 76+        Returns `True` if the repo is clean.
 77+        Returns `False` if the repo is dirty.
 78         """
 79-        # check if repo is clean (clean => no error, no commit)
 80         try:
 81             CommandRunner.run_or_fail(
 82                 ["git", "diff", "--exit-code"], stage="CheckRepoClean"
 83             )
 84-            return False
 85+            return True
 86         except CommandRunner.Exception:
 87-            # if it's other kind of error just throw!
 88-            pass
 89+            return False
 90+
 91+    @staticmethod
 92+    def add_and_commit(scope: str, version: str) -> bool:
 93+        """
 94+        Returns `True` if there were changes and were indeed commited.
 95+        Returns `False` if the repo was clean and no changes were commited.
 96+        """
 97+        if Git.repo_is_clean():
 98+            return False
 99 
100         user_name = os.environ.get("GIT_APP_NAME")
101         user_email = os.environ.get("GIT_APP_EMAIL")