Пример #1
0
def wrap_in_student_repo(path: Union[str, pathlib.Path]) -> plug.StudentRepo:
    return plug.StudentRepo(
        name=pathlib.Path(path).name,
        team=DUMMY_TEAM,
        url="dummy_url",
        _path=pathlib.Path(path),
    )
Пример #2
0
def _execute_post_setup_hook(push_tuples: List[git.Push],
                             api: plug.PlatformAPI) -> Mapping[Any, Any]:
    """Execute the post_setup hook on the given push tuples. Note that the push
    tuples are expected to have the "team" and "repo" keys set in the metadata.
    """
    post_setup_exists = any(
        ["post_setup" in dir(p) for p in plug.manager.get_plugins()])
    if not post_setup_exists or not push_tuples:
        return {}

    teams_and_repos = [(pt.metadata["team"], pt.metadata["repo"])
                       for pt in push_tuples]
    student_repos = [
        plug.StudentRepo(
            name=repo.name,
            url=repo.url,
            team=plug.StudentTeam(members=team.members),
        ) for team, repo in teams_and_repos
    ]
    student_repos_iter = plug.cli.io.progress_bar(
        student_repos, desc="Executing post_setup hooks")

    return plugin.execute_tasks(
        student_repos_iter,
        plug.manager.hook.post_setup,
        api,
        cwd=None,
        copy_repos=False,
    )
Пример #3
0
def _post_setup(
    pts: List[PushSpec], newly_created: bool, api: plug.PlatformAPI
) -> Mapping[Any, Any]:
    teams_and_repos = [
        (pt.metadata["team"], pt.metadata["repo"]) for pt in pts
    ]
    student_repos = [
        plug.StudentRepo(
            name=repo.name,
            url=repo.url,
            team=plug.StudentTeam(name=team.name, members=team.members),
        )
        for team, repo in teams_and_repos
    ]
    student_repos_iter = plug.cli.io.progress_bar(
        student_repos, desc="Executing post_setup hooks"
    )

    return plugin.execute_tasks(
        student_repos_iter,
        plug.manager.hook.post_setup,
        api,
        cwd=None,
        copy_repos=False,
        extra_kwargs=dict(newly_created=newly_created),
    )
Пример #4
0
def _repo_tuple_generator(
    assignment_names: List[str],
    teams: List[plug.StudentTeam],
    api: plug.PlatformAPI,
) -> Iterable[plug.StudentRepo]:
    for assignment_name in assignment_names:
        for team in teams:
            url, *_ = api.get_repo_urls([assignment_name],
                                        team_names=[team.name])
            name = plug.generate_repo_name(team, assignment_name)
            yield plug.StudentRepo(name=name, url=url, team=team)
Пример #5
0
def _discover_repos(student_teams: List[plug.StudentTeam],
                    api: plug.PlatformAPI) -> Iterable[plug.StudentRepo]:
    student_teams_dict = {t.name: t for t in student_teams}
    fetched_teams = progresswrappers.get_teams(student_teams,
                                               api,
                                               desc="Discovering team repos")
    for team in fetched_teams:
        repos = api.get_team_repos(team)
        yield from (plug.StudentRepo(
            name=repo.name,
            url=repo.url,
            team=student_teams_dict[team.name],
        ) for repo in repos)
Пример #6
0
def _clone_to_student_repos(
    team_repo_tuples: List[Tuple[plug.Team, List[plug.Repo]]],
    workdir: pathlib.Path,
    clone_dir: pathlib.Path,
    api: plug.PlatformAPI,
) -> List[plug.StudentRepo]:
    student_repos = [
        plug.StudentRepo(
            name=repo.name,
            team=plug.StudentTeam(name=team.name, members=list(team.members)),
            url=repo.url,
            _path=workdir / team.name / repo.name,
        ) for team, repos in team_repo_tuples for repo in repos
    ]
    list(
        _repobee.git.clone_student_repos(student_repos,
                                         clone_dir,
                                         update_local=False,
                                         api=api))
    return student_repos
Пример #7
0
def _create_anonymized_repo(
        student_repo: plug.StudentRepo, key: str,
        api: plug.PlatformAPI) -> Tuple[plug.StudentRepo, plug.Repo]:
    anon_repo_name = _hash_if_key(student_repo.name, key=key)
    anon_review_team_name = _hash_if_key(student_repo.team.name, key=key)
    fingerprint = _anonymous_repo_fingerprint(anon_review_team_name,
                                              anon_repo_name)
    platform_repo = api.create_repo(
        name=anon_repo_name,
        description=f"Review copy. Fingerprint: {fingerprint}",
        private=True,
    )
    _anonymize_commit_history(student_repo.path)
    return (
        plug.StudentRepo(
            name=anon_repo_name,
            team=student_repo.team,
            url=student_repo.url.replace(student_repo.name, anon_repo_name),
            _path=student_repo.path,
        ),
        platform_repo,
    )
Пример #8
0
    assignments=ASSIGNMENT_NAMES,
    students=list(STUDENTS),
    issue=ISSUE,
    title_regex="some regex",
    traceback=False,
    state=plug.IssueState.OPEN,
    show_body=True,
    author=None,
    token=TOKEN,
    num_reviews=1,
    hook_results_file=None,
    repos=[
        plug.StudentRepo(
            name=plug.generate_repo_name(team, master_name),
            team=team,
            url=generate_repo_url(
                plug.generate_repo_name(team, master_name), ORG_NAME
            ),
        )
        for team, master_name in itertools.product(STUDENTS, ASSIGNMENT_NAMES)
    ],
    secrets=False,
    update_local=False,
    double_blind_key=None,
    directory_layout=fileutil.DirectoryLayout.BY_TEAM,
)


@pytest.fixture(autouse=True)
def load_default_plugins_auto(load_default_plugins):
    """The only point of this fixture is to make load_default_plugins