예제 #1
0
파일: core.py 프로젝트: sclorg/betka
    def sync_pull_requests(self, branch) -> bool:
        """
        Sync upstream pr into downstream pr.
        :return: False if Pull Request is not synced
                 True if Pull Request is filed or updated
        """
        # Get all pull requests from upstream for correct image
        if not self.config.get("pr_checker"):
            self.info("Syncing upstream PR to downstream repo is not allowed.")
            return False

        # Get all upstream OPENED pull request
        pr_dict = self.github_api.get_pull_requests("OPEN")
        self.debug("pr_dict: %s", pr_dict)
        os.chdir(self.betka_tmp_dir.name)
        state = self.github_api.check_upstream_pr(self.pr_number)
        if state == "OPEN":
            # Commit message has to be the same as in the latest comment message
            comment = self.config.get("pr_comment_message")
            if not self.upstream_pr_comment.startswith(comment):
                return False
            os.chdir(str(self.upstream_synced_dir))
            Git.fetch_pr_origin(self.pr_number,
                                f"Checkout to PR{self.pr_number} branch")
            # Copy upstream directory into downstream directory
            title = f"{self.betka_config['downstream_pr_msg']} #{self.pr_number}"
            description_msg = COMMIT_PR_MSG.format(pr_num=self.pr_number,
                                                   repo=self.repo)
            pr_id = self.pagure_api.check_downstream_pull_requests(title)

            os.chdir(str(self.downstream_dir))
            # Switch to downstream dist-git repo
            if not self.sync_upstream_to_downstream_directory():
                return False

            # git {add,commit,push} all files in local dist-git repo
            Git.git_add_all(
                self.upstream_message,
                related_msg=Git.get_msg_from_jira_ticket(self.config),
            )
            # Prepare betka_schema used for sending mail and Pagure Pull Request
            # The function also checks if downstream does not already contain pull request
            betka_schema = self.pagure_api.file_pull_request(
                title=title,
                pr_msg=description_msg,
                upstream_hash=self.upstream_hash,
                branch=branch,
                pr_id=pr_id,
                pr=True,
                pr_num=self.pr_number,
            )
            self.send_result_email(betka_schema=betka_schema)

        self.delete_close_merged_pull_requests()
        return True
예제 #2
0
파일: core.py 프로젝트: sclorg/betka
    def sync_to_downstream_branches(self, branch) -> bool:
        """
        Sync upstream repository into relevant downstream dist-git branch
        based on the configuration file.
        :param branch: downstream branch to check and to sync
        """
        if not self.config.get("master_checker"):
            self.info(
                "Syncing upstream repo to downstream repo is not allowed.")
            return False
        self.info("Syncing upstream %r to downstream %r",
                  self.msg_upstream_url, self.image)
        description_msg = COMMIT_MASTER_MSG.format(hash=self.upstream_hash,
                                                   repo=self.repo)
        pr_id = self.pagure_api.check_downstream_pull_requests(branch=branch)
        if not pr_id:
            Git.get_changes_from_distgit(
                url=self.pagure_api.full_downstream_url)
            Git.push_changes_to_fork(branch=branch)

        if not self.sync_upstream_to_downstream_directory():
            return False

        # git {add,commit,push} all files in local dist-git repo
        Git.git_add_all(
            upstream_msg=self.upstream_message,
            related_msg=Git.get_msg_from_jira_ticket(self.config),
        )

        # Prepare betka_schema used for sending mail and Pagure Pull Request
        # The function also checks if downstream does not already contain pull request
        betka_schema = self.pagure_api.file_pull_request(
            pr_msg=description_msg,
            upstream_hash=self.upstream_hash,
            branch=branch,
            pr_id=pr_id,
        )
        self.send_result_email(betka_schema=betka_schema)
        return True
예제 #3
0
def test_jira_msg(config, commit_msg):
    assert Git.get_msg_from_jira_ticket(config) == commit_msg