예제 #1
0
def create_teams(
    teams: Iterable[plug.StudentTeam],
    permission: plug.TeamPermission,
    api: plug.PlatformAPI,
) -> Iterable[plug.Team]:
    """Create teams.

    Args:
        teams: An iterable of teams to create.
        permission: The permission to assign to the team with respect to its
            repositories.
        api: A platform API instance.
    Returns:
        An iterable of wrappers around created teams.
    """
    teams = list(teams)
    existing_teams_dict = {
        existing.name: existing
        for existing in api.get_teams({t.name for t in teams})
    }
    for required_team in teams:
        team = existing_teams_dict.get(required_team.name) or api.create_team(
            required_team.name,
            members=required_team.members,
            permission=permission,
        )
        existing_members = set(team.members)
        new_members = set(required_team.members) - existing_members
        api.assign_members(team, new_members, permission)

        # FIXME the returned team won't have the correct members if any new
        # ones are added. This should be fixed by disconnecting members
        # from teams, and having an api call "get_team_members"

        yield team
예제 #2
0
 def command(self, api: plug.PlatformAPI):
     team = api.get_teams(team_names=[self.team_name])
     api.create_repo(
         self.repo_name,
         description=description,
         private=private,
         team=team,
     )
예제 #3
0
def _get_or_create_team(team_name: str, api: plug.PlatformAPI) -> plug.Team:
    matches = api.get_teams(team_names=[team_name])

    try:
        return next(iter(matches))
    except StopIteration:
        return api.create_team(TEACHERS_TEAM_NAME,
                               permission=plug.TeamPermission.PULL)
예제 #4
0
def _get_anonymous_review_team(
    student_team: plug.StudentTeam,
    assignment: str,
    key: str,
    api: plug.PlatformAPI,
) -> plug.Team:
    review_team, *_ = list(
        api.get_teams([_repobee.hash.keyed_hash(student_team.name, key, 20)]))
    return review_team
예제 #5
0
def get_teams(
    teams: Iterable[Union[plug.StudentTeam, str]],
    api: plug.PlatformAPI,
    desc: str = "Fetching teams",
    **kwargs: Any,
) -> Iterable[plug.Team]:
    """Wrapper around :py:meth:`repobee_plug.PlatformAPI.get_teams` that also
    displays a progress bar.

    Args:
        teams: An iterable of teams or team names.
        api: An instance of the platform API.
        desc: Description of the action.
        args: Keyword arguments for the underlying implementation of the
            progress bar.
    Returns:
        An iterable of fetched teams that also updates a CLI progress bar.
    """
    teams = list(teams)
    fetched_teams = api.get_teams(str(t) for t in teams)
    return plug.cli.io.progress_bar(fetched_teams,
                                    desc=desc,
                                    total=len(teams),
                                    **kwargs)