|
4 | 4 | import sys |
5 | 5 | from typing import List |
6 | 6 | import rich_click as click |
7 | | -from git import Repo, GitCommandError |
| 7 | +try: |
| 8 | + from git import Repo, GitCommandError |
| 9 | +except Exception: |
| 10 | + pass |
8 | 11 | from devchat._cli.utils import init_dir, handle_errors, valid_git_repo, clone_git_repo |
| 12 | +from devchat._cli.utils import download_and_extract_workflow |
9 | 13 | from devchat.engine import Namespace, CommandParser, RecursivePrompter |
10 | 14 | from devchat.utils import get_logger |
11 | 15 |
|
12 | 16 | logger = get_logger(__name__) |
13 | 17 |
|
14 | | - |
15 | 18 | @click.command( |
16 | 19 | help="The 'command' argument is the name of the command to run or get information about.") |
17 | 20 | @click.argument('command', required=False, default='') |
@@ -44,7 +47,11 @@ def run(command: str, list_flag: bool, recursive_flag: bool, update_sys_flag: bo |
44 | 47 | 'https://gitee.com/devchat-ai/workflows.git', |
45 | 48 | 'https://github.com/devchat-ai/workflows.git' |
46 | 49 | ] |
47 | | - _clone_or_pull_git_repo(sys_dir, git_urls) |
| 50 | + zip_urls = [ |
| 51 | + 'https://gitlab.com/devchat-ai/workflows/-/archive/main/workflows-main.zip', |
| 52 | + 'https://codeload.github.com/devchat-ai/workflows/zip/refs/heads/main' |
| 53 | + ] |
| 54 | + _clone_or_pull_git_repo(sys_dir, git_urls, zip_urls) |
48 | 55 | return |
49 | 56 |
|
50 | 57 | if list_flag: |
@@ -72,13 +79,23 @@ def run(command: str, list_flag: bool, recursive_flag: bool, update_sys_flag: bo |
72 | 79 | return |
73 | 80 |
|
74 | 81 |
|
75 | | -def _clone_or_pull_git_repo(target_dir: str, repo_urls: List[str]): |
| 82 | +def _clone_or_pull_git_repo(target_dir: str, repo_urls: List[str], zip_urls: List[str]): |
76 | 83 | """ |
77 | 84 | Clone a Git repository to a specified location, or pull it if it already exists. |
78 | 85 |
|
79 | 86 | :param target_dir: The path where the repository should be cloned. |
80 | 87 | :param repo_urls: A list of possible Git repository URLs. |
81 | 88 | """ |
| 89 | + if shutil.which('git') is None: |
| 90 | + # If Git is not installed, download and extract the workflow |
| 91 | + for url in zip_urls: |
| 92 | + try: |
| 93 | + download_and_extract_workflow(url, target_dir) |
| 94 | + break |
| 95 | + except Exception as err: |
| 96 | + logger.exception("Failed to download and extract workflow: %s", err) |
| 97 | + return |
| 98 | + |
82 | 99 | if os.path.exists(target_dir): |
83 | 100 | if valid_git_repo(target_dir, repo_urls): |
84 | 101 | try: |
|
0 commit comments