Skip to content

Commit

Permalink
Added Method for Repo Creation (agno-agi#1655)
Browse files Browse the repository at this point in the history
## Description

Added a new Method in Github Tools which helps in creating a new
repository
  • Loading branch information
srexrg authored Jan 9, 2025
1 parent c035715 commit 854533e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cookbook/tools/github_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
# agent.print_response("What is the latest opened issue?", markdown=True)
# # Example usage: Create an issue
# agent.print_response("Explain the comments for the most recent issue", markdown=True)
# # Example usage: Create a Repo
# agent.print_response("Create a repo called phi-test and add description hello", markdown=True)
58 changes: 57 additions & 1 deletion phi/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def __init__(
get_pull_request: bool = True,
get_pull_request_changes: bool = True,
create_issue: bool = True,
get_repository_languages: bool = True,
create_repository: bool = True,
get_repository_languages: bool = True
):
super().__init__(name="github")

Expand All @@ -46,6 +47,9 @@ def __init__(
self.register(self.get_pull_request_changes)
if create_issue:
self.register(self.create_issue)
if create_repository:
self.register(self.create_repository)

if get_repository_languages:
self.register(self.get_repository_languages)

Expand Down Expand Up @@ -109,6 +113,58 @@ def list_repositories(self) -> str:
logger.error(f"Error listing repositories: {e}")
return json.dumps({"error": str(e)})

def create_repository(
self,
name: str,
private: bool = False,
description: Optional[str] = None,
auto_init: bool = False,
organization: Optional[str] = None,
) -> str:
"""Create a new repository on GitHub.
Args:
name (str): The name of the repository.
private (bool, optional): Whether the repository is private. Defaults to False.
description (str, optional): A short description of the repository.
auto_init (bool, optional): Whether to initialize the repository with a README. Defaults to False.
organization (str, optional): Name of organization to create repo in. If None, creates in user account.
Returns:
A JSON-formatted string containing the created repository details.
"""
logger.debug(f"Creating repository: {name}")
try:
description = description if description is not None else ""

if organization:
logger.debug(f"Creating in organization: {organization}")
org = self.g.get_organization(organization)
repo = org.create_repo(
name=name,
private=private,
description=description,
auto_init=auto_init,
)
else:
repo = self.g.get_user().create_repo(
name=name,
private=private,
description=description,
auto_init=auto_init,
)

repo_info = {
"name": repo.full_name,
"url": repo.html_url,
"private": repo.private,
"description": repo.description,
}
return json.dumps(repo_info, indent=2)
except GithubException as e:
logger.error(f"Error creating repository: {e}")
return json.dumps({"error": str(e)})

def get_repository(self, repo_name: str) -> str:
"""Get details of a specific repository.
Expand Down

0 comments on commit 854533e

Please sign in to comment.