How to use the spectacles.runner.BranchState function in spectacles

To help you get started, we’ve selected a few spectacles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spectacles-ci / spectacles / tests / test_branch_manager.py View on Github external
project = "eye_exam"
    starting_branch = "master"
    ref = "e2d21d"
    dependent_project = "welcome_to_looker"
    looker_client.update_workspace(project, "production")

    new_branch = "pytest"
    assert new_branch != starting_branch
    manager = LookerBranchManager(
        looker_client, project, name=new_branch, import_projects=True, commit_ref=ref
    )
    assert manager.original_branch == starting_branch

    manager.__enter__()
    assert len(manager.temp_branches) == 2
    temp_branches: List[BranchState] = manager.temp_branches.copy()
    for state in temp_branches:
        branch_info = looker_client.get_active_branch(state.project)
        if state.project == project:
            assert branch_info["ref"][:6] == ref
        assert branch_info["name"] == state.temp_branch

    manager.__exit__()
    branch_info = looker_client.get_active_branch(project)
    assert branch_info["name"] == starting_branch
    assert branch_info["ref"][:6] != ref
    looker_client.update_workspace(project, "dev")
    all_branches = set(looker_client.get_all_branches(dependent_project))
    # Confirm that no temp branches still remain
    assert set(state.temp_branch for state in temp_branches).isdisjoint(all_branches)
github spectacles-ci / spectacles / spectacles / runner.py View on Github external
def setup_temp_branch(self, project: str, original_branch: str) -> str:
        name = "tmp_spectacles_" + time_hash()
        logger.debug(
            f"Branch '{name}' will be restored to branch '{original_branch}' in "
            f"project '{project}'"
        )
        self.temp_branches.append(BranchState(project, original_branch, name))
        return name
github spectacles-ci / spectacles / spectacles / runner.py View on Github external
def setup_temp_branch(self, project: str, original_branch: str) -> str:
        name = "tmp_spectacles_" + time_hash()
        logger.debug(
            f"Branch '{name}' will be restored to branch '{original_branch}' in "
            f"project '{project}'"
        )
        self.temp_branches.append(BranchState(project, original_branch, name))
        return name
github spectacles-ci / spectacles / spectacles / runner.py View on Github external
name: Optional[str] = None,
        remote_reset: bool = False,
        import_projects: bool = False,
        commit_ref: Optional[str] = None,
    ):
        """Context manager for Git branch checkout, creation, and deletion."""
        self.client = client
        self.project = project
        self.commit_ref = commit_ref
        self.name = name
        self.remote_reset = remote_reset
        self.import_projects = import_projects

        # Get the current branch so we can return to it afterwards
        self.original_branch = self.client.get_active_branch_name(self.project)
        self.temp_branches: List[BranchState] = []
github spectacles-ci / spectacles / spectacles / runner.py View on Github external
import_projects: bool = False,
        commit_ref: Optional[str] = None,
    ):
        """Context manager for Git branch checkout, creation, and deletion."""
        self.client = client
        self.project = project
        self.name = name
        self.remote_reset = remote_reset
        self.import_projects = import_projects
        self.commit_ref = commit_ref

        # Get the current branch so we can return to it afterwards
        self.original_branch = self.client.get_active_branch(self.project)
        # If the desired branch is master and no ref is passed, we can stay in prod
        self.workspace = "production" if name == "master" and not commit_ref else "dev"
        self.temp_branches: List[BranchState] = []