Skip to content

Commit

Permalink
Fix GH Clones Needing Explicit Directory Name (#10)
Browse files Browse the repository at this point in the history
* Fix cloning issue - cloning then infers repo name to match assignment specs

* Fix string formating in information output
  • Loading branch information
willGraham01 authored Nov 1, 2024
1 parent cf67c3a commit a00ba26
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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

0 comments on commit a00ba26

Please sign in to comment.