def get_student_repositories( context: "Context", students: Optional[List["Student"]] = None, ) -> List["Repository"]: from student.utils import get_all_students if students is None or len(students) == 0: students = get_all_students(context) return [context.get_repository(student) for student in students]
def get_all_pull_requests(self) -> List["PullRequest"]: from student.utils import get_all_students pulls = [] for student in get_all_students(self.context): pulls.extend( self.context.get_repository( student).get_remote_pull_requests()) return pulls
def print_info(): context = Context() print(f"token = '{context.token}'") print(f"organization name = '{context.organization_name}'") print(f"user repository prefix = '{context.user_repository_prefix}'") print(f"template repository name = '{context.template_repository_name}'") students = get_all_students(context) if len(students) == 0: print("Students: NONE") else: print("Students: ") for student in students: print(f" {student}")
def get_remote_pull_requests( context: Context, students: Optional[List["Student"]] = None, filters: Optional[Dict[str, Any]] = None, ) -> List["PullRequest"]: if students is None: from student.utils import get_all_students students = get_all_students(context) pulls = [] for student_pull_requests in context.organization.get_student_pull_requests( students).values(): pulls.extend( filter( lambda student_pull_request: student_pull_request. passes_filters(filters), student_pull_requests)) return pulls
def checkout(args): context = Context() university_login = args.university_login student = list( filter( lambda x: x.university_login == university_login, get_all_students(context), )) if len(student) != 1: print( f"No student with university login=({university_login}) found in active students" ) else: student = student[0] student_repository = context.get_repository(student) pull_number = args.pr_number pulls = list( filter( lambda x: x.number == pull_number, student_repository.get_local_pull_requests(), )) if len(pulls) != 1: print( f"Pull request for {student} with number = ({pull_number}) was not found fetching new pull requests" ) pulls = list( filter( lambda x: x.number == pull_number, student_repository.get_remote_pull_requests(), )) if len(pulls) != 1: print("Pull request does not exists") return pull_request = pulls[0] pull_request.save() pull_request.checkout_pull_request()