mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-06-29 15:59:42 +02:00
feat: +tool lib git clone, push
This commit is contained in:
parent
f02f371af5
commit
16c1818582
5 changed files with 335 additions and 67 deletions
|
|
@ -3,12 +3,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from github import Auth, Github
|
||||
from pydantic import BaseModel
|
||||
|
||||
from metagpt.tools.libs.git import git_checkout, git_clone
|
||||
from metagpt.utils.common import awrite
|
||||
from metagpt.utils.git_repository import GitRepository
|
||||
|
||||
|
||||
|
|
@ -17,7 +19,7 @@ class SWEBenchItem(BaseModel):
|
|||
repo: str
|
||||
|
||||
|
||||
def get_env(key):
|
||||
async def get_env(key: str, app_name: str = ""):
|
||||
return os.environ.get(key)
|
||||
|
||||
|
||||
|
|
@ -37,8 +39,9 @@ async def test_git(url: str, commit_id: str):
|
|||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_login():
|
||||
auth = Auth.Login(get_env("GITHUB_USER"), get_env("GITHUB_PWD"))
|
||||
@pytest.mark.asyncio
|
||||
async def test_login():
|
||||
auth = Auth.Login(await get_env("GITHUB_USER"), await get_env("GITHUB_PWD"))
|
||||
g = Github(auth=auth)
|
||||
repo = g.get_repo("geekan/MetaGPT")
|
||||
topics = repo.get_topics()
|
||||
|
|
@ -55,7 +58,7 @@ async def test_new_issue():
|
|||
repo_name="iorisa/MetaGPT",
|
||||
title="This is a new issue",
|
||||
body="This is the issue body",
|
||||
access_token=get_env("GITHUB_PERSONAL_ACCESS_TOKEN"),
|
||||
access_token=await get_env(key="access_token", app_name="github"),
|
||||
)
|
||||
print(issue)
|
||||
assert issue.number
|
||||
|
|
@ -74,20 +77,21 @@ async def test_new_pr():
|
|||
>>> - [x] Send 'POST' request with/without body
|
||||
"""
|
||||
pr = await GitRepository.create_pull(
|
||||
repo_name="iorisa/MetaGPT",
|
||||
base_repo_name="iorisa/MetaGPT",
|
||||
base="send18",
|
||||
head="fixbug/gbk",
|
||||
title="Test pr",
|
||||
body=body,
|
||||
access_token=get_env("GITHUB_PERSONAL_ACCESS_TOKEN"),
|
||||
access_token=await get_env(key="access_token", app_name="github"),
|
||||
)
|
||||
print(pr)
|
||||
assert pr
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_auth():
|
||||
access_token = get_env("GITHUB_PERSONAL_ACCESS_TOKEN")
|
||||
@pytest.mark.asyncio
|
||||
async def test_auth():
|
||||
access_token = await get_env(key="access_token", app_name="github")
|
||||
auth = Auth.Token(access_token)
|
||||
g = Github(auth=auth)
|
||||
u = g.get_user()
|
||||
|
|
@ -98,5 +102,24 @@ def test_auth():
|
|||
pass
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.asyncio
|
||||
async def test_github(context):
|
||||
repo = await GitRepository.clone_from(url="https://github.com/iorisa/snake-game.git")
|
||||
content = uuid.uuid4().hex
|
||||
await awrite(filename=repo.workdir / "README.md", data=content)
|
||||
branch = await repo.push(
|
||||
new_branch=f"feature/{content[0:8]}", access_token=await get_env(key="access_token", app_name="github")
|
||||
)
|
||||
pr = await GitRepository.create_pull(
|
||||
base=branch.base,
|
||||
head=branch.head,
|
||||
base_repo_name=branch.repo_name,
|
||||
title=f"new pull {content[0:8]}",
|
||||
access_token=await get_env(key="access_token", app_name="github"),
|
||||
)
|
||||
assert pr
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
|
|
|
|||
|
|
@ -3,57 +3,13 @@
|
|||
|
||||
import pytest
|
||||
|
||||
from metagpt.tools.libs import (
|
||||
fix_bug,
|
||||
git_archive,
|
||||
run_qa_test,
|
||||
write_codes,
|
||||
write_design,
|
||||
write_prd,
|
||||
write_project_plan,
|
||||
)
|
||||
from metagpt.context import Context
|
||||
from metagpt.roles.di.data_interpreter import DataInterpreter
|
||||
from metagpt.schema import UserMessage
|
||||
from metagpt.tools.libs.software_development import import_git_repo
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_software_team():
|
||||
path = await write_prd("snake game")
|
||||
assert path
|
||||
|
||||
path = await write_design(path)
|
||||
assert path
|
||||
|
||||
path = await write_project_plan(path)
|
||||
assert path
|
||||
|
||||
path = await write_codes(path)
|
||||
assert path
|
||||
|
||||
path = await run_qa_test(path)
|
||||
assert path
|
||||
|
||||
issue = """
|
||||
pygame 2.0.1 (SDL 2.0.14, Python 3.9.17)
|
||||
Hello from the pygame community. https://www.pygame.org/contribute.html
|
||||
Traceback (most recent call last):
|
||||
File "/Users/ix/github/bak/MetaGPT/workspace/snake_game/snake_game/main.py", line 10, in <module>
|
||||
main()
|
||||
File "/Users/ix/github/bak/MetaGPT/workspace/snake_game/snake_game/main.py", line 7, in main
|
||||
game.start_game()
|
||||
File "/Users/ix/github/bak/MetaGPT/workspace/snake_game/snake_game/game.py", line 81, in start_game
|
||||
x
|
||||
NameError: name 'x' is not defined
|
||||
"""
|
||||
path = await fix_bug(path, issue)
|
||||
assert path
|
||||
|
||||
new_path = await write_prd("snake game with moving enemy", path)
|
||||
assert new_path == path
|
||||
|
||||
git_log = await git_archive(new_path)
|
||||
assert git_log
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
@pytest.mark.asyncio
|
||||
async def test_import_repo():
|
||||
url = "https://github.com/spec-first/connexion.git"
|
||||
|
|
@ -61,5 +17,24 @@ async def test_import_repo():
|
|||
assert path
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"content",
|
||||
[
|
||||
# "create a new issue to github repo 'iorisa/snake-game' :'The snake did not grow longer after eating'",
|
||||
"Resolve the issue #1 'Snake not growing longer after eating' in the GitHub repository https://github.com/iorisa/snake-game.git', and create a new pull request about the issue"
|
||||
],
|
||||
)
|
||||
async def test_git_create_issue(content: str):
|
||||
context = Context()
|
||||
di = DataInterpreter(context=context, tools=["<all>"])
|
||||
|
||||
prerequisite = "from metagpt.tools.libs import get_env"
|
||||
await di.execute_code.run(code=prerequisite, language="python")
|
||||
di.put_message(UserMessage(content=content))
|
||||
while not di.is_idle:
|
||||
await di.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pytest.main([__file__, "-s"])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue