def process_comment_jobs(self, event: PullRequestCommentEvent) -> HandlerResults: # packit_command can be `/packit build` or `/packit build <with_args>` msg = f"PR comment '{event.comment[:35]}'" try: (packit_mark, *packit_command) = event.comment.split(maxsplit=3) except ValueError: return HandlerResults(success=False, details={"msg": f"{msg} is empty."}) if REQUESTED_PULL_REQUEST_COMMENT != packit_mark: return HandlerResults( success=False, details={"msg": f"{msg} is not handled by packit-service."}, ) if not packit_command: return HandlerResults( success=False, details={ "msg": f"{msg} does not contain a packit-service command." }, ) # packit has command `copr-build`. But PullRequestCommentAction has enum `copr_build`. try: packit_action = PullRequestCommentAction[packit_command[0].replace( "-", "_")] except KeyError: return HandlerResults( success=False, details={ "msg": f"{msg} does not contain a valid packit-service command." }, ) handler_kls: Type[ PullRequestCommentHandler] = PULL_REQUEST_COMMENT_HANDLER_MAPPING.get( packit_action, None) if not handler_kls: return HandlerResults( success=False, details={"msg": f"{msg} is not a packit-service command."}, ) handler = handler_kls(self.config, event) try: # check whitelist approval for every job to be able to track down which jobs # failed because of missing whitelist approval whitelist = Whitelist() if not whitelist.check_and_report(event, event.get_project()): handlers_results = HandlerResults( success=False, details={"msg": "Account is not whitelisted!"}) return handlers_results handlers_results = handler.run() finally: handler.clean() return handlers_results
def __init__(self, config: ServiceConfig, event: PullRequestCommentEvent): super().__init__(config=config, event=event) self.config = config self.event = event self.project: GitProject = event.get_project() # Get the latest pull request commit self.event.commit_sha = self.project.get_all_pr_commits( self.event.pr_id)[-1] self.event.base_ref = self.event.commit_sha self.package_config: PackageConfig = self.get_package_config_from_repo( self.project, self.event.commit_sha, self.event.pr_id) self.package_config.upstream_project_url = event.project_url
def __init__(self, config: ServiceConfig, event: PullRequestCommentEvent): super().__init__(config=config, event=event) self.config = config self.event = event self.project: GitProject = event.get_project() # Get the latest pull request commit self.event.commit_sha = self.project.get_all_pr_commits(self.event.pr_id)[-1] self.event.base_ref = self.event.commit_sha self.package_config: PackageConfig = get_package_config_from_repo( self.project, self.event.commit_sha ) if not self.package_config: raise ValueError(f"No config file found in {self.project.full_repo_name}") self.package_config.upstream_project_url = event.project_url