Skip to content

Commit 33b7866

Browse files
authored
Merge pull request Significant-Gravitas#1229 from edcohen08/clone-github-repository
command clone github repository
2 parents 17cdeee + 71abd6f commit 33b7866

File tree

7 files changed

+36
-0
lines changed

7 files changed

+36
-0
lines changed

.env.template

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ IMAGE_PROVIDER=dalle
9595
# HUGGINGFACE_API_TOKEN - HuggingFace API token (Example: my-huggingface-api-token)
9696
HUGGINGFACE_API_TOKEN=your-huggingface-api-token
9797

98+
################################################################################
99+
### GIT Provider for repository actions
100+
################################################################################
101+
102+
### GITHUB
103+
# GITHUB_API_KEY - Github API key / PAT (Example: github_pat_123)
104+
# GITHUB_USERNAME - Github username
105+
GITHUB_API_KEY=github_pat_123
106+
GITHUB_USERNAME=your-github-username
107+
98108
################################################################################
99109
### SEARCH PROVIDER
100110
################################################################################

Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Use an official Python base image from the Docker Hub
22
FROM python:3.11-slim
33

4+
# Install git
5+
RUN apt-get -y update
6+
RUN apt-get -y install git
7+
48
# Set environment variables
59
ENV PIP_NO_CACHE_DIR=yes \
610
PYTHONUNBUFFERED=1 \

autogpt/app.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from autogpt.processing.text import summarize_text
2323
from autogpt.speech import say_text
2424
from autogpt.commands.web_selenium import browse_website
25+
from autogpt.commands.git_operations import clone_repository
2526

2627

2728
CFG = Config()
@@ -126,6 +127,8 @@ def execute_command(command_name: str, arguments):
126127
return get_text_summary(arguments["url"], arguments["question"])
127128
elif command_name == "get_hyperlinks":
128129
return get_hyperlinks(arguments["url"])
130+
elif command_name == "clone_repository":
131+
return clone_repository(arguments["repository_url"], arguments["clone_path"])
129132
elif command_name == "read_file":
130133
return read_file(arguments["file"])
131134
elif command_name == "write_to_file":

autogpt/commands/git_operations.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import git
2+
from config import Config
3+
4+
cfg = Config()
5+
6+
7+
def clone_repository(repo_url, clone_path):
8+
"""Clone a github repository locally"""
9+
split_url = repo_url.split("//")
10+
auth_repo_url = f"//{cfg.github_username}:{cfg.github_api_key}@".join(split_url)
11+
git.Repo.clone_from(auth_repo_url, clone_path)
12+
result = f"""Cloned {repo_url} to {clone_path}"""
13+
14+
return result

autogpt/config/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def __init__(self) -> None:
5757
self.use_brian_tts = False
5858
self.use_brian_tts = os.getenv("USE_BRIAN_TTS")
5959

60+
self.github_api_key = os.getenv("GITHUB_API_KEY")
61+
self.github_username = os.getenv("GITHUB_USERNAME")
62+
6063
self.google_api_key = os.getenv("GOOGLE_API_KEY")
6164
self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID")
6265

autogpt/prompt.py

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def get_prompt() -> str:
5555
),
5656
("List GPT Agents", "list_agents", {}),
5757
("Delete GPT Agent", "delete_agent", {"key": "<key>"}),
58+
("Clone Repository", "clone_repository", {"repository_url": "<url>", "clone_path": "<directory>"}),
5859
("Write to file", "write_to_file", {"file": "<file>", "text": "<text>"}),
5960
("Read file", "read_file", {"file": "<file>"}),
6061
("Append to file", "append_to_file", {"file": "<file>", "text": "<text>"}),

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ pre-commit
2626
black
2727
sourcery
2828
isort
29+
gitpython==3.1.31

0 commit comments

Comments
 (0)