Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH Clones Needing Explicit Directory Name #10

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assignment_submission_checker/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def parse_into_output(
"Information reported here does not invalidate the submission, "
"though you may wish to check you expect everything here to apply "
"to your submission.\n\t"
) + "\n".join(s.replace("\n", "\n\t") for s in information)
) + "\n\t".join(s.replace("\n", "\n\t") for s in information)

if (not fatal_str) and (not warnings_str) and (not information_str):
return f"{heading_str}\nSubmission format matches specifications, nothing further to report."
Expand Down
22 changes: 20 additions & 2 deletions assignment_submission_checker/cli_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import shutil
from pathlib import Path
from tempfile import mkdtemp
from typing import Optional
Expand Down Expand Up @@ -31,6 +32,13 @@ def fetch_spec(assignment_spec: str) -> None:
return r.text


def infer_repo_name(repo: Repo) -> str:
"""
Attempt to infer the name of a repository cloned from GitHub.
"""
return repo.remotes.origin.url.split(".git")[0].split("/")[-1]


def main(
assignment_lookup: Optional[str] = None,
github_clone_url: Optional[str] = None,
Expand All @@ -51,10 +59,20 @@ def main(
if github_clone_url is not None:
# Attempt to clone GH repo and place into temp folder
# then set that as the submission directory
submission_dir = Path(mkdtemp("safe_clone"))
tmp_dir = Path(mkdtemp("safe_clone"))
clone_dir = tmp_dir / "cloned"
clone_dir.mkdir(exist_ok=True)

# Actually clone the repo from GH so it is available on the filesystem
r = Repo.clone_from(github_clone_url, to_path=submission_dir)
r = Repo.clone_from(github_clone_url, to_path=clone_dir)
repo_name = infer_repo_name(r)
r.close()

# Relocate the cloned repository deeper inside another temporary folder, so that
# names match up with those expected.
submission_dir = tmp_dir / repo_name
shutil.move(clone_dir, submission_dir)

elif submission is not None:
submission_dir = Path(submission)
else:
Expand Down
6 changes: 4 additions & 2 deletions assignment_submission_checker/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,14 @@ def investigate_subdir(

if not path_to_subdir.is_dir():
if subdir.is_optional:
information.append(f"Optional subfolder {subdir.name} of {self.name} not found.")
information.append(
f"Optional subfolder '{subdir.name}' of '{self.name}' not found."
)
return None, warning, information
else:
return (
AssignmentCheckerError(
f"Expected subdirectory {subdir.name} to be present in {self.name}, but it is not."
f"Expected subdirectory '{subdir.name}' to be present in '{self.name}', but it is not."
),
warning,
information,
Expand Down
Loading