def delete_close_merged_pull_requests(self): """ Delete or close or update already merged upstream Pull Requests. :param pr_dict: dictionary with relevant pull request # TODO document pr_dict """ self.debug("delete_close_merged_pull_requests()") # Check for state of the upstream pull request. # If the upstream pull request was close/merged, # then updates the relevant downstream pull request state = self.github_api.check_upstream_pr(self.pr_number) if state != "OPEN": # If Upstream Pull Request is closed or merged, close also downstream # relevant Pull Request. msg_to_check = f"{self.betka_config['downstream_pr_msg']} #{self.pr_number}" # Checks downstream pull request according to upstream PR message. pr_id = self.pagure_api.check_downstream_pull_requests( msg_to_check, check_user=False) if pr_id: url_address = self.pagure_api.get_comment_url(self.repo, pr_id) link = "{url}/pull/{n}".format(n=self.pr_number, url=Git.strip_dot_git( self.msg_upstream_url)) comment = (f"Upstream PR {link} was {state}. " f"This downstream PR {pr_id} can be closed. " f"Feel free to close this upstream Pull Request.") data = {"comment": comment} # Updates downstream PR according to upstream PR. self.pagure_api.pagure_post_action(url_address, data)
def fake_git_clone(self, clone_url, tempdir): repodir = Git.strip_dot_git(clone_url.split("/")[-2]) Git.call_git_cmd( "clone --recurse-submodules {u} {d}".format(u=clone_url, d=os.path.join( tempdir, repodir)), msg=clone_url, ) return os.path.join(tempdir, repodir)
def _sync_valid_branches(self, valid_branches): """ Syncs valid branches in namespace :param valid_branches: valid branches to sync :return: """ try: self.prepare_upstream_git() except subprocess.CalledProcessError: self.error( f"!!!! Cloning upstream repo {self.msg_upstream_url} FAILED") raise for branch in valid_branches: self.timestamp_dir: Path = None self.downstream_git_branch = branch # This loads downstream bot-cfg.yml file # and update betka's dictionary (self.config). # We need to have information up to date if not self._get_bot_cfg(branch=self.downstream_git_branch): continue # Gets repo url without .git for cloning self.repo = Git.strip_dot_git(self.msg_upstream_url) if self.master_sync: self.info("SYNCING UPSTREAM TO DOWNSTREAM.") if not self.config.get("master_checker"): self.info( "Syncing upstream repo to downstream repo is not allowed." ) continue self.create_and_copy_timestamp_dir() self.sync_to_downstream_branches(self.downstream_git_branch) elif self.pr_sync: self.info("SYNCING UPSTREAM PR TO DOWNSTREAM PR. DISABLED") # 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." ) continue self.create_and_copy_timestamp_dir() if self.sync_pull_requests(self.downstream_git_branch): # Updates pull request from downstream self.delete_close_merged_pull_requests() self.delete_timestamp_dir()