예제 #1
0
    def execute(self) -> None:
        args = self.__args
        git_repo_api = GitRepoApiFactory.create(args, args.organisation,
                                                args.repository_name)

        pr_branch = git_repo_api.get_pull_request_branch(args.pr_id)
        git_hash = git_repo_api.get_branch_head_hash(pr_branch)

        add_pr_comment: Callable[
            [str],
            None] = lambda comment: git_repo_api.add_pull_request_comment(
                args.pr_id, comment, args.parent_id)

        create_preview_command = CreatePreviewCommand(
            CreatePreviewCommand.Args(
                username=args.username,
                password=args.password,
                git_user=args.git_user,
                git_email=args.git_email,
                organisation=args.organisation,
                repository_name=args.repository_name,
                git_provider=args.git_provider,
                git_provider_url=args.git_provider_url,
                git_hash=git_hash,
                preview_id=pr_branch,  # use pr_branch as preview id
            ), )
        create_preview_command.register_callbacks(
            deployment_already_up_to_date_callback=lambda route_host:
            add_pr_comment(
                f"The version `{git_hash}` has already been deployed. Access it here: https://{route_host}",
            ),
            deployment_updated_callback=lambda route_host: add_pr_comment(
                f"Preview environment updated to version `{git_hash}`. Access it here: https://{route_host}"
            ),
            deployment_created_callback=lambda route_host: add_pr_comment(
                f"New preview environment created for version `{git_hash}`. Access it here: https://{route_host}"
            ),
        )
        create_preview_command.execute()
예제 #2
0
 def __create_git_repo_api(self) -> GitRepoApi:
     return GitRepoApiFactory.create(self.__args, self.__args.organisation,
                                     self.__args.repository_name)
예제 #3
0
 def __create_preview_template_git_repo_api(
         self, gitops_config: GitOpsConfig) -> GitRepoApi:
     return GitRepoApiFactory.create(
         self.__args, gitops_config.preview_template_organisation,
         gitops_config.preview_template_repository)
예제 #4
0
 def __create_team_config_git_repo_api(
         self, gitops_config: GitOpsConfig) -> GitRepoApi:
     return GitRepoApiFactory.create(self.__args,
                                     gitops_config.team_config_org,
                                     gitops_config.team_config_repo)