diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 0b2e911..f796af2 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -20,7 +20,7 @@ jobs: with: dockerfiles: ./Dockerfile image: betka - tags: latest 1 ${{ github.sha }} 0.9.8 + tags: latest 1 ${{ github.sha }} 0.10.0 - name: Push betka image to Quay.io id: push-to-quay diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 7cc51ea..db9fe2a 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - tox_env: [py36, py38, py39, py310, py311, py312] + tox_env: [py311, py312] # Use GitHub's Linux Docker host runs-on: ubuntu-latest steps: diff --git a/Dockerfile b/Dockerfile index b9e4ba4..d074446 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM quay.io/fedora/fedora:37 ENV NAME=betka-fedora \ - RELEASE=0.9.8 \ + RELEASE=0.10.0 \ ARCH=x86_64 \ SUMMARY="Syncs changes from upstream repository to downstream" \ DESCRIPTION="Syncs changes from upstream repository to downstream" \ diff --git a/betka/core.py b/betka/core.py index 4477cbe..2ed0e18 100644 --- a/betka/core.py +++ b/betka/core.py @@ -356,10 +356,28 @@ def sync_to_downstream_branches(self, branch, origin_branch: str = ""): git_status = Git.git_add_all( upstream_msg=self.upstream_message, related_msg=Git.get_msg_from_jira_ticket(self.config), + ) if not git_status: self.info( - "There were no changes in repository. Do not file a pull request." + f"There were no changes in repository. Do not file a pull request." + ) + BetkaEmails.send_email( + text=f"There were no changes in repository {self.image} to {branch}. Fork status {self.is_fork_enabled()}.", + receivers=["phracek@redhat.com"], + subject="[betka-diff] No git changes", + ) + return + + git_push_status = Git.git_push(fork_enabled=self.is_fork_enabled(), source_branch=branch) + if not git_push_status: + self.info( + f"Pushing to dist-git was not successful {branch}. Original_branch {origin_branch}." + ) + BetkaEmails.send_email( + text=f"Pushing to {branch}. See logs from the bot.", + receivers=["phracek@redhat.com"], + subject="[betka-push] Pushing was not successful.", ) return # Prepare betka_schema used for sending mail and Pagure Pull Request @@ -421,10 +439,12 @@ def get_master_fedmsg_info(self, message): # https://apps.fedoraproject.org/datagrepper/id?id=2018-ab4ad1f9-36a0-483a-9401-6b5c2a314383&is_raw=true&size=extra-large self.message = message if "head_commit" not in self.message or self.message["head_commit"] == "": - self.info( - "Fedora Messaging does not contain head_commit or is head_commit is empty %r", - self.message, - ) + if self.message.get("body"): + body = self.message.get("body") + self.info( + f"Fedora Messaging does not contain head_commit or is " + f"head_commit is empty {body['ref']}", + ) return False href = self.message.get("ref") head_commit = self.message.get("head_commit") @@ -660,7 +680,7 @@ def _sync_valid_branches(self, valid_branches): self.downstream_git_branch = f"betka-{datetime.now().strftime('%Y%m%d%H%M%S')}-{branch}" self.downstream_git_origin_branch = branch Git.call_git_cmd( - f"checkout -b {self.downstream_git_branch} {branch}", + f"checkout -b {self.downstream_git_branch} --track origin/{branch}", msg="Create a new downstream branch" ) if not self._get_bot_cfg(branch=branch): diff --git a/betka/git.py b/betka/git.py index 86b36c7..c00275b 100644 --- a/betka/git.py +++ b/betka/git.py @@ -64,11 +64,13 @@ def git_add_all(upstream_msg: str, related_msg: str) -> bool: Add and push all files into the fork. :param upstream_msg: :param related_msg: + :param fork_enabled: + :param source_branch: """ - #git_show_status = Git.call_git_cmd( - # "diff HEAD", ignore_error=True, msg="Check git status" - #) - #logger.debug(f"Show git diff {git_show_status}") + git_show_status = Git.call_git_cmd( + "diff HEAD", ignore_error=True, msg="Check git status" + ) + logger.debug(f"Show git diff {git_show_status}") Git.call_git_cmd("add -A", msg="Add all") upstream_msg += f"\n{related_msg}\n" @@ -88,11 +90,21 @@ def git_add_all(upstream_msg: str, related_msg: str) -> bool: return False except CalledProcessError: pass + return True - try: - Git.call_git_cmd("push -u origin", msg="Push changes into git") - except CalledProcessError: - pass + @staticmethod + def git_push(fork_enabled: bool = False, source_branch: str = "") -> bool: + + if fork_enabled: + try: + Git.call_git_cmd("push", msg="Push changes into git") + except CalledProcessError: + return False + else: + try: + Git.call_git_cmd(f"push -u origin {source_branch}", msg="Push changes into git") + except CalledProcessError: + return False return True @staticmethod diff --git a/setup.py b/setup.py index 6cc09ec..b10a892 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ def get_requirements(): setup( name="betka", - version="0.9.8", + version="0.10.0", packages=find_packages(exclude=["examples", "tests"]), url="https://github.com/sclorg/betka", license="GPLv3+", diff --git a/tox.ini b/tox.ini index fafcba7..cc659b1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] skipsdist = True -envlist = py36,py38,py39,py310,py311,py312 +envlist = py311,py312 DEPLOYMENT=test [testenv] commands = python3 -m pytest --color=yes -v --showlocals tests/