def merge_pull_request(self, comment: str):
     try:
         self.remote_pull_request.merge(comment)
     except GithubException as e:
         if e.status == 405: # Status code for cannot merge PR
             raise GLMException("Cannot merge pull request") from e
         raise
示例#2
0
def generate_students(context, file_path: str) -> List["Student"]:
    from core.core import read_lines
    from student.student import Student

    students = get_all_students(context)

    active_students_university_login = set(student.university_login
                                           for student in students)

    try:
        lines = list(read_lines(file_path))
    except FileNotFoundError:
        raise GLMException(f"File '{file_path}' does not exists")

    for line in lines:
        university_login, remote_login, name, email = line.split("\t")
        if university_login in active_students_university_login:
            print(
                f"student with university login = {university_login} already exists, skipping"
            )
        else:
            student = Student(context, university_login, remote_login, name,
                              email)
            student.save()
            print(f"student ({student}) created and saved")
            students.append(student)

    return students
示例#3
0
def get_worklist(context: Context) -> List[Worklist]:
    try:
        worklist_filepath = get_file_path("worklist.yaml")
    except FileNotFoundError:
        raise GLMException("worklist.yaml doesn't exists",
                           "You first need to create worklist")

    with open(worklist_filepath) as file:
        parsed_worklist = yaml.safe_load(file)

    worklist = list()

    parsed_worklist_lines = set()

    for line in parsed_worklist:
        if line in parsed_worklist_lines:
            print(warn | f"Duplicity found, {line} has already been parsed")
            continue
        else:
            parsed_worklist_lines.add(line)

        worklist_line = parse_worklist_line(context, line)
        if worklist_line is not None:
            worklist.append(worklist_line)

    return worklist
示例#4
0
    def get_local_pull_requests(self) -> List["PullRequest"]:
        pulls = []

        for student_pull_file in listdir(self.student.pulls_directory_path()):
            try:
                pr_number = int(student_pull_file)
            except ValueError as e:
                raise GLMException(
                    "Student PR file error",
                    f"Student PR files should be named after their numbers in remote. So it should be integer, not '{student_pull_file}'.",
                    True,
                ) from e
            pr = self.context.get_pull_request(pr_number, self.student)
            pulls.append(pr)

        return pulls
示例#5
0
def get_checked_out_student_and_pull_request(
    context: "Context", ) -> Tuple[Student, PullRequest]:
    if not is_in_octopus_directory():
        raise WrongLocationException("You are not in octopus directory",
                                     f"type: cd {get_octopus_path()}")

    current_branch = get_current_branch()
    if current_branch is None or "#" not in current_branch:
        raise GLMException(
            "The current branch needs to be a PR student branch in format (university_login#number)"
        )

    student_university_login, number = current_branch.split("#")
    number = int(number)

    student = StudentFactory.get_student(context, student_university_login)
    student.load_properties()
    pull_request = context.get_pull_request(number, student)

    return student, pull_request