Пример #1
0
def create_local_repo(
    path: pathlib.Path,
    files: Iterable[Tuple[str, str]],
    default_branch: str = "master",
) -> str:
    """Create a local repository in the provided basedir and return a
    hash of the contents.

    Args:
        path: Path to put the repository at. Parent directories are created if
            they don't exist.
        files: Files to add to the repository. Should be tuples on the form
            (relpath, content), where relpath is a filepath relative to the
            root of the repository.
        default_branch: The default branch to use for the repository.
    Returns:
        The sha1 hash of the repository.
    """
    path.mkdir(parents=True)
    for filename, content in files:
        file = path / filename
        file.parent.mkdir(parents=True, exist_ok=True)
        (path / filename).write_text(content, encoding="utf8")
    sha = funcs.hash_directory(path)
    funcs.initialize_repo(path, default_branch)
    return sha
Пример #2
0
def platform_dir():
    """Setup the platform emulation with a template organization with git
    repositories, the students and teacher as users,  and return the the
    workdirectory for the platform.
    """
    with tempfile.TemporaryDirectory() as tmpdir:
        template_org_dir = pathlib.Path(tmpdir) / TEMPLATE_ORG_NAME
        shutil.copytree(src=TEMPLATE_REPO_DIR, dst=template_org_dir)
        for template_repo in template_org_dir.iterdir():
            if not template_repo.is_dir():
                continue
            funcs.initialize_repo(template_repo)

        api = funcs.get_api("https://" + str(tmpdir))
        api._add_users(
            itertools.chain.from_iterable([t.members for t in STUDENT_TEAMS]))

        yield pathlib.Path(tmpdir)
Пример #3
0
    def test_setup_with_custom_template_repo(self, platform_dir, platform_url,
                                             tmp_path_factory):
        api = funcs.get_api(platform_url, org_name=const.TEMPLATE_ORG_NAME)

        template_repo = api.create_repo("epIcRepo",
                                        description="dontcare",
                                        private=False)
        local_template_dir = tmp_path_factory.mktemp("template")
        (local_template_dir /
         "file.txt").write_text("this is a brand new file!")

        branch = "master"
        local_template_repo = funcs.initialize_repo(local_template_dir,
                                                    default_branch=branch)
        local_template_repo.git.push(api.insert_auth(template_repo.url),
                                     branch)

        funcs.run_repobee(
            f"repos setup -a {template_repo.name} --base-url {platform_url}")