Ejemplo n.º 1
0
def test_handler(args: List[str]):
    parser = ArgumentParser(prog="test",
                            description="Test if glm is setup correctly")
    parser.parse_args(args)

    context = Context()
    test = context.get_test()
    test.do_tests()
Ejemplo n.º 2
0
def report_handler(args: List[str]):
    parser = ArgumentParser(
        prog="report", description="Generate and push report for students")
    parser.add_argument(
        "report_path",
        action="store",
        type=str,
        help="Shell script file path that generates reports for students",
    )
    parser.add_argument(
        "--output-filename",
        action="store",
        metavar="filename",
        type=str,
        help=
        "Name of the output file for the report. This will be pushed to students",
    )
    parsed_args = parser.parse_args(args)

    context = Context()

    output_filename = parsed_args.output_filename
    if output_filename is None:
        output_filename = context.report_file_name

    generate_report(
        context,
        report_command=parsed_args.report_command,
        output_filename=output_filename,
    )
Ejemplo n.º 3
0
def parse_worklist_line(context: Context, line: str) -> Optional[Worklist]:
    try:
        university_login, pr_number = line.split("#")
        pr_number = int(pr_number)
    except ValueError:
        print(warn | f"Error parsing ({line})")
        return

    student = StudentFactory.get_student(context, university_login)
    try:
        student.load_properties()
    except FileNotFoundError:
        print(fatal | f"Student ({university_login}) doesn't exist")
        return

    pull_request = context.get_pull_request(pr_number, student)
    try:
        pull_request.load_properties()
    except FileNotFoundError:
        print(
            fatal
            |
            f"Pull request with number = ({pr_number}) for student ({university_login}) doesn't exist locally"
        )
        return

    return student, pull_request
Ejemplo n.º 4
0
def worklist_handler(args: List[str]):
    parser = argparse.ArgumentParser(
        prog="worklist",
        description="Worklist related functionality",
    )
    parser.add_argument("action",
                        action="store",
                        choices=["next", "prev", "list"])
    parsed_args = parser.parse_args(args)

    context = Context()

    worklist = get_worklist(context)
    current_worklist_index = get_current_worklist_index(worklist)

    if parsed_args.action == "list":
        list_worklist(worklist, current_worklist_index)
    elif parsed_args.action == "next":
        if current_worklist_index is None:
            worklist[0][1].checkout_pull_request()
        elif len(worklist) > current_worklist_index + 1:
            worklist[current_worklist_index + 1][1].checkout_pull_request()
        else:
            print("End of worklist")
    elif parsed_args.action == "prev":
        if current_worklist_index is None:
            worklist[-1][1].checkout_pull_request()
        elif current_worklist_index > 0:
            worklist[current_worklist_index - 1][1].checkout_pull_request()
        else:
            print("Start of worklist")
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
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}")
Ejemplo n.º 7
0
def distribute_handler(args: List[str]):
    parser = ArgumentParser(prog="distribute", description="Distribute branches")
    parser.add_argument("branch_name", type=str, action="store")
    parser.add_argument(
        "--students",
        "-s",
        type=str,
        action="store",
        default="",
        help="Comma separated university logins",
    )
    parsed_args = parser.parse_args(args)

    context = Context()

    distribute_branch(context, parsed_args.branch_name, parsed_args.students)
Ejemplo n.º 8
0
def pull_handler(args: List[str]):
    parser = ArgumentParser(prog="pull",
                            description="Pull request manipulation")
    parser.add_argument("--comments",
                        "-c",
                        help="Load comments made on PR",
                        action="store_true")

    # Sub-parser: comment
    pull_sub_parsers = parser.add_subparsers()
    pull_sub_parsers_comment = pull_sub_parsers.add_parser(
        "comment", help="Comment on checked out pull request")
    pull_sub_parsers_comment.add_argument("message", action="store", type=str)
    pull_sub_parsers_comment.set_defaults(func=pull_comment_handle)
    # Sub-parser: close
    pull_sub_parsers_comment = pull_sub_parsers.add_parser(
        "merge", help="Comment on checked out pull request")
    pull_sub_parsers_comment.add_argument("message", action="store", type=str)
    pull_sub_parsers_comment.set_defaults(func=pull_merge_handle)

    parser_args = parser.parse_args(args)

    if hasattr(parser_args, "func"):
        parser_args.func(parser_args)
    else:
        context = Context()

        student, pull_request = get_checked_out_student_and_pull_request(
            context)

        if parser_args.comments:
            for issue in pull_request.get_issue_comments():
                print(issue)
        else:
            print(f"Currently checked out student = '{student}'")
            print(f"Currently checked out PR = '{pull_request}'")
            mergeable = pull_request.mergeable
            if mergeable is not None:
                print(f"Can merge = {mergeable}")
            else:
                print("Already merged")
Ejemplo n.º 9
0
def get_local_pull_requests(
    context: Context,
    students: Optional[List["Student"]] = None,
    filters: Optional[Dict[str, Any]] = None,
) -> List["PullRequest"]:
    from student.student import StudentFactory
    from core.config_loader import get_directory_path

    if students is None:
        students = [
            StudentFactory.get_student(context, student_name)
            for student_name in os.listdir(get_directory_path("pulls/"))
        ]

    pulls = []
    for student in students:
        for student_pull_file in os.listdir(student.pulls_directory_path()):
            pr = context.get_pull_request(student_pull_file, student)
            if pr.passes_filters(filters):
                pulls.append(pr)

    return pulls
Ejemplo n.º 10
0
def pulls_handler(args: List[str]):
    parser = ArgumentParser(prog="pulls",
                            description="pull requests manipulation")
    parser.add_argument(
        "--students",
        "-s",
        nargs="+",
        action="store",
        metavar="students",
        help="List of students",
    )
    parser.add_argument("--cached",
                        "-c",
                        help="Load PR from localconfig",
                        action="store_true")
    parser.add_argument(
        "--branch",
        "-b",
        help="Narrow pulls to specific branch",
        action="store",
    )

    parser.add_argument(
        "pr_status",
        help="Status of PR",
        choices=["open", "closed", "merged", "all"],
    )
    parser.add_argument(
        "--save",
        help="Save pr into worklist",
        action="store_true",
    )

    parsed_args = parser.parse_args(args)

    context = Context()

    students = None

    if parsed_args.students:
        students = get_students_from_university_logins(context,
                                                       parsed_args.students)
        if len(students) == 0:
            return

    filters = {}

    if parsed_args.pr_status != "all":
        filters["status"] = PullRequestState(parsed_args.pr_status)

    if parsed_args.branch:
        filters["base_branch"] = parsed_args.branch

    pulls = []
    if parsed_args.cached:
        from remote.pull_request.utils import get_local_pull_requests

        pulls.extend(get_local_pull_requests(context, students, filters))
    else:
        from remote.pull_request.utils import get_remote_pull_requests

        pulls.extend(get_remote_pull_requests(context, students, filters))
        for pull in pulls:
            pull.save()

    if len(pulls) == 0:
        print("No pull requests")
    else:
        for pull in pulls:
            print(pull)
        if parsed_args.save:
            generate_and_save_worklist(pulls)
            print("Saved")
Ejemplo n.º 11
0
def generate_students(file_path: str):
    context = Context()

    students = utils_generate_students(context, file_path)
    context.organization.setup_student_repositories(students)
Ejemplo n.º 12
0
def pull_merge_handle(args):
    context = Context()

    _, pull_request = get_checked_out_student_and_pull_request(context)

    pull_request.merge_pull_request(args.message)
Ejemplo n.º 13
0
def pull_comment_handle(args):
    context = Context()

    _, pull_request = get_checked_out_student_and_pull_request(context)

    pull_request.create_issue_comment(args.message)