-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7bb153b
commit 1d2e892
Showing
1 changed file
with
9 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import tempfile | ||
import subprocess | ||
import tempfile | ||
import time | ||
from pathlib import Path | ||
from urllib.parse import urlparse | ||
|
||
import click | ||
|
@@ -16,30 +14,31 @@ | |
# handling github by | ||
# checking if path is a URL | ||
def is_url(recipe_path): | ||
""" Check if the path is a valid URL.""" | ||
"""Check if the path is a valid URL.""" | ||
parsed = urlparse(recipe_path) | ||
return parsed.scheme in ('http', 'https') and parsed.netloc != '' | ||
return parsed.scheme in ("http", "https") and parsed.netloc != "" | ||
|
||
|
||
def convert_url_to_ssh(recipe_path): | ||
""" Convert https github url to ssh format.""" | ||
"""Convert https github url to ssh format.""" | ||
parsed = urlparse(recipe_path) | ||
if parsed.scheme != "https" or "github.com" not in parsed.netloc: | ||
raise ValueError("Invalid GitHub HTTPS URL") | ||
# extract just the repo path | ||
repo_path = parsed.path.lstrip("/") | ||
repo_path = parsed.path.lstrip("/") | ||
return f"[email protected]:{repo_path}.git" | ||
|
||
|
||
def clone_repo(ssh_url): | ||
"""Clone the repository into a temporary directory.""" | ||
temp_dir = tempfile.mkdtemp() | ||
try: | ||
subprocess.run(['git', 'clone', ssh_url, temp_dir], check=True) | ||
subprocess.run(["git", "clone", ssh_url, temp_dir], check=True) | ||
return temp_dir | ||
except subprocess.CalledProcessError as e: | ||
print(f"Error cloning repository: {e}") | ||
|
||
|
||
# use that as a local path for submission | ||
# need to figure out how to best do this for if its a url - this is a temporary solution | ||
recipe_path = click.argument( | ||
|
@@ -55,11 +54,7 @@ def clone_repo(ssh_url): | |
# path_type=Path, | ||
# ), | ||
) | ||
recipe_name = click.argument( | ||
"recipe_name", | ||
required=False, | ||
type = str | ||
) | ||
recipe_name = click.argument("recipe_name", required=False, type=str) | ||
|
||
|
||
@click.group | ||
|
@@ -72,7 +67,7 @@ def _submit_workflow(recipe_path) -> str: | |
print(f"Detected URL: {recipe_path}. Cloning repository...") | ||
ssh_url = convert_url_to_ssh(recipe_path) | ||
clone_repo(ssh_url) | ||
else: | ||
else: | ||
workflow = make_simple_workflow( | ||
recipe_dir=recipe_path, | ||
) | ||
|