feat: add _create_repo

This commit is contained in:
莘权 马 2024-03-26 22:20:27 +08:00
parent 643450388a
commit 02f0096438
2 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from typing import List
from metagpt.actions import Action
from metagpt.schema import Message
from metagpt.tools.libs.git import git_clone
from metagpt.utils.git_repository import GitRepository
from metagpt.utils.project_repo import ProjectRepo
class ImportRepo(Action):
repo_path: str
async def run(self, with_messages: List[Message] = None, **kwargs) -> Message:
await self._create_repo()
pass
async def _create_repo(self):
path = await git_clone(url=self.repo_path, output_dir=self.config.workspace.path)
self.repo_path = str(path)
self.config.project_path = path
self.context.git_repo = GitRepository(local_path=path, auto_init=True)
self.context.repo = ProjectRepo(self.context.git_repo)

View file

@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest
from metagpt.actions.import_repo import ImportRepo
from metagpt.context import Context
@pytest.mark.asyncio
@pytest.mark.parametrize("repo_path", ["https://github.com/geekan/MetaGPT.git"])
async def test_import_repo(repo_path):
context = Context()
action = ImportRepo(repo_path=repo_path, context=context)
await action.run()
if __name__ == "__main__":
pytest.main([__file__, "-s"])