def test_mixed(self, students): """One student is done, one has performed half, one has too few assigned, one has more. """ num_reviews = 2 reviews = { "ham": strs_to_reviews("spam-week-1", "bacon-week-1", done=False), "spam": [ plug.Review("bacon-week-1", False), plug.Review("eggs-week-1", False), ], "bacon": strs_to_reviews("eggs-week-1", done=False), "eggs": strs_to_reviews("ham-week-1", "spam-week-1", "bacon-week-1", done=True), } expected_output = r""" Color coding: grey: not done, green: done, red: num done + num remaining != num_reviews [0mreviewer num done num remaining repos remaining [48;5;239m[38;5;15mham 0 2 spam-week-1,bacon-week-1[0m [48;5;235m[38;5;15mspam 0 2 bacon-week-1,eggs-week-1[0m [48;5;1m[38;5;15mbacon 0 1 eggs-week-1 [0m [48;5;1m[38;5;15meggs 3 0 [0m """ # noqa: E501,W291 actual_output = formatters.format_peer_review_progress_output( reviews, students, num_reviews) assert actual_output.strip() == expected_output.strip()
def check_reviews_repobee_4(allocations_file: pathlib.Path, title_regex: str, api: plug.PlatformAPI) -> None: """Preview version of the `reviews check` command for RepoBee 4.""" data = json.loads(allocations_file.read_text(sys.getdefaultencoding())) review_allocations = data["allocations"] num_reviews = int(data["num_reviews"]) expected_reviewers = { allocation["reviewed_repo"]["url"]: allocation["review_team"]["members"] for allocation in review_allocations } reviewed_repos = progresswrappers.get_repos(expected_reviewers.keys(), api) reviews = collections.defaultdict(list) for reviewed_repo in reviewed_repos: review_issue_authors = { issue.author for issue in api.get_repo_issues(reviewed_repo) if re.match(title_regex, issue.title) } for expected_reviewer in expected_reviewers[reviewed_repo.url]: reviews[expected_reviewer].append( plug.Review( repo=reviewed_repo.name, done=expected_reviewer in review_issue_authors, )) plug.echo( formatters.format_peer_review_progress_output( reviews, list(itertools.chain.from_iterable(expected_reviewers.values())), num_reviews, ))
def check_peer_review_progress( assignment_names: Iterable[str], teams: Iterable[plug.Team], title_regex: str, num_reviews: int, api: plug.PlatformAPI, ) -> None: """Check which teams have opened peer review issues in their allotted review repos Args: assignment_names: Names of assignments. teams: An iterable of student teams. title_regex: A regex to match against issue titles. num_reviews: Amount of reviews each student is expected to have made. api: An implementation of :py:class:`repobee_plug.PlatformAPI` used to interface with the platform (e.g. GitHub or GitLab) instance. """ teams = list(teams) reviews = collections.defaultdict(list) review_team_names = [ plug.generate_review_team_name(team, assignment_name) for team in teams for assignment_name in assignment_names ] review_teams = progresswrappers.get_teams(review_team_names, api, desc="Processing review teams") for review_team in review_teams: repos = list(api.get_team_repos(review_team)) if len(repos) != 1: plug.log.warning( f"Expected {review_team.name} to have 1 associated " f"repo, found {len(repos)}. " f"Skipping...") continue reviewed_repo = repos[0] expected_reviewers = set(review_team.members) reviewing_teams = _extract_reviewing_teams(teams, expected_reviewers) review_issue_authors = { issue.author for issue in api.get_repo_issues(reviewed_repo) if re.match(title_regex, issue.title) } for team in reviewing_teams: reviews[str(team)].append( plug.Review( repo=reviewed_repo.name, done=any( map(review_issue_authors.__contains__, team.members)), )) plug.echo( formatters.format_peer_review_progress_output( reviews, [team.name for team in teams], num_reviews))
def strs_to_reviews(*repo_names, done=True): return [plug.Review(repo, done) for repo in repo_names]