Skip to content

Commit 9ccb137

Browse files
Implement GitHub code source
1 parent c98ff83 commit 9ccb137

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • src/mkcd2app/build_project/inputs

src/mkcd2app/build_project/inputs/code.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,28 @@ def fetch_code(config_yaml: str, node_modules_for_mkc: ContentDir) -> ContentDir
4646
if code_path.exists():
4747
rmtree_robust(code_path)
4848

49-
# TODO: Implement source code download from GitHub
5049
match config.inputs.code.root:
5150
case ShareLinkCodeSource(value=url):
5251
logger.debug(f"Downloading source code from {url}")
5352
code_path.mkdir(parents=True)
5453
logger.debug(f"Using `mkc` from {node_modules_for_mkc}")
5554
run_cmd(["npx", "mkc", "download", str(url)], cwd=code_path)
5655
case GitHubCodeSource(value=url, checkout=checkout_target):
57-
logger.debug(f"Downloading source code from {url}@{checkout_target}")
58-
raise NotImplementedError("GitHub code source not implemented yet")
56+
logger.debug(f"Cloning source code from {url}@{checkout_target}")
57+
abs_code_path = code_path.resolve()
58+
abs_code_path.parent.mkdir(parents=True, exist_ok=True)
59+
run_cmd(
60+
[
61+
"git",
62+
"clone",
63+
"--filter=blob:none",
64+
"--no-checkout",
65+
str(url),
66+
str(abs_code_path),
67+
],
68+
cwd=abs_code_path.parent,
69+
)
70+
run_cmd(["git", "checkout", checkout_target], cwd=abs_code_path)
5971
case PathCodeSource(value=path):
6072
logger.debug(f"Copying source code from {path}")
6173
shutil.copytree(path, code_path)

0 commit comments

Comments
 (0)