-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'mono/0.6.0.dev1' into comm_pkg5
- Loading branch information
Showing
32 changed files
with
2,066 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Swarmauri Example Community Package |
63 changes: 63 additions & 0 deletions
63
pkgs/community/swarmauri_tool_communitygithub/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
[tool.poetry] | ||
name = "swarmauri_tool_communitygithub" | ||
version = "0.6.0.dev1" | ||
description = "Github Tool" | ||
authors = ["Jacob Stewart <[email protected]>"] | ||
license = "Apache-2.0" | ||
readme = "README.md" | ||
repository = "http://github.com/swarmauri/swarmauri-sdk" | ||
classifiers = [ | ||
"License :: OSI Approved :: Apache Software License", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12" | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
python = ">=3.10,<3.13" | ||
|
||
# Swarmauri | ||
swarmauri_core = { path = "../../core" } | ||
swarmauri_base = { path = "../../base" } | ||
|
||
# Dependencies | ||
pygithub = "^2.4.0" | ||
|
||
|
||
|
||
[tool.poetry.group.dev.dependencies] | ||
flake8 = "^7.0" | ||
pytest = "^8.0" | ||
pytest-asyncio = ">=0.24.0" | ||
pytest-xdist = "^3.6.1" | ||
pytest-json-report = "^1.5.0" | ||
python-dotenv = "*" | ||
requests = "^2.32.3" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.pytest.ini_options] | ||
norecursedirs = ["combined", "scripts"] | ||
|
||
markers = [ | ||
"test: standard test", | ||
"unit: Unit tests", | ||
"integration: Integration tests", | ||
"acceptance: Acceptance tests", | ||
"experimental: Experimental tests" | ||
] | ||
log_cli = true | ||
log_cli_level = "INFO" | ||
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s" | ||
log_cli_date_format = "%Y-%m-%d %H:%M:%S" | ||
asyncio_default_fixture_loop_scope = "function" | ||
|
||
[tool.poetry.plugins."swarmauri.tools"] | ||
GithubBranchTool = "swarmauri_tool_communitygithub.GithubBranchTool" | ||
GithubCommitTool = "swarmauri_tool_communitygithub.GithubCommitTool" | ||
GithubIssueTool = "swarmauri_tool_communitygithub.GithubIssueTool" | ||
GithubPRTool = "swarmauri_tool_communitygithub.GithubPRTool" | ||
GithubTool = "swarmauri_tool_communitygithub.GithubTool" | ||
GithubRepoTool = "swarmauri_tool_communitygithub.GithubRepoTool" |
106 changes: 106 additions & 0 deletions
106
...mmunity/swarmauri_tool_communitygithub/swarmauri_tool_communitygithub/GithubBranchTool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# swarmauri/community/tools/concrete/GithubCommunityTool.py | ||
|
||
from github import Github, GithubException | ||
from typing import List, Dict, Literal, Any | ||
from pydantic import Field, ConfigDict | ||
from swarmauri_base.tools.ToolBase import ToolBase | ||
from swarmauri_standard.tool.Parameter import Parameter | ||
|
||
|
||
class GithubBranchTool(ToolBase): | ||
version: str = "1.1.0" | ||
parameters: List[Parameter] = Field( | ||
default_factory=lambda: [ | ||
Parameter( | ||
name="action", | ||
type="string", | ||
description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.", | ||
required=True, | ||
), | ||
Parameter( | ||
name="repo_name", | ||
type="string", | ||
description="The full name of the repository to interact with, e.g. 'owner/repository'.", | ||
required=True, | ||
), | ||
Parameter( | ||
name="branch_name", | ||
type="string", | ||
description="The name of the branch to interact with.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="source_branch", | ||
type="string", | ||
description="The name of the source branch to create a branch from.", | ||
required=False, | ||
), | ||
] | ||
) | ||
name: str = "GithubBranchTool" | ||
description: str = "Interacts with GitHub branches using PyGithub." | ||
type: Literal["GithubBranchTool"] = "GithubBranchTool" | ||
token: str | ||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
def __call__(self, action: str, **kwargs) -> Dict[str, Any]: | ||
""" | ||
Central method to call various GitHub API actions. | ||
Args: | ||
action (str): The action to perform. | ||
**kwargs: Additional keyword arguments related to the action. | ||
Returns: | ||
Dict[str, Any]: The result of the action. | ||
""" | ||
action_map = { | ||
"create_branch": self.create_branch, | ||
"delete_branch": self.delete_branch, | ||
"list_branches": self.list_branches, | ||
"get_branch": self.get_branch, | ||
} | ||
|
||
if action in action_map: | ||
self._github = Github(self.token) | ||
return {action: action_map[action](**kwargs)} | ||
|
||
raise ValueError(f"Action '{action}' is not supported.") | ||
|
||
# Branch Management Methods | ||
def create_branch( | ||
self, repo_name: str, branch_name: str, source: str = "main" | ||
) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
source_branch = repo.get_branch(source) | ||
repo.create_git_ref( | ||
ref=f"refs/heads/{branch_name}", sha=source_branch.commit.sha | ||
) | ||
return f"Branch '{branch_name}' created successfully." | ||
except GithubException as e: | ||
return f"Error creating branch: {e}" | ||
|
||
def delete_branch(self, repo_name: str, branch_name: str) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
ref = repo.get_git_ref(f"heads/{branch_name}") | ||
ref.delete() | ||
return f"Branch '{branch_name}' deleted successfully." | ||
except GithubException as e: | ||
return f"Error deleting branch: {e}" | ||
|
||
def list_branches(self, repo_name: str) -> List[str]: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
return [branch.name for branch in repo.get_branches()] | ||
except GithubException as e: | ||
return f"Error listing branches: {e}" | ||
|
||
def get_branch(self, repo_name: str, branch_name: str) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
branch = repo.get_branch(branch_name) | ||
return f"Branch {branch.name}: {branch.commit.sha}" | ||
except GithubException as e: | ||
return f"Error retrieving branch: {e}" |
141 changes: 141 additions & 0 deletions
141
...mmunity/swarmauri_tool_communitygithub/swarmauri_tool_communitygithub/GithubCommitTool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
# swarmauri/standard/tools/concrete/GithubTool.py | ||
|
||
from github import Github, GithubException | ||
from typing import List, Dict, Literal, Any | ||
from pydantic import Field, ConfigDict | ||
from swarmauri_base.tools.ToolBase import ToolBase | ||
from swarmauri_standard.tool.Parameter import Parameter | ||
|
||
|
||
class GithubCommitTool(ToolBase): | ||
version: str = "1.1.0" | ||
parameters: List[Parameter] = Field( | ||
default_factory=lambda: [ | ||
Parameter( | ||
name="action", | ||
type="string", | ||
description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.", | ||
required=True, | ||
), | ||
Parameter( | ||
name="repo_name", | ||
type="string", | ||
description="The full name of the repository to interact with, e.g. 'owner/repository'.", | ||
required=True, | ||
), | ||
Parameter( | ||
name="file_path", | ||
type="string", | ||
description="The path to the file in the repository, e.g. 'path/to/file.txt'.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="message", | ||
type="string", | ||
description=".", | ||
required=False, | ||
), | ||
Parameter( | ||
name="content", | ||
type="string", | ||
description="The name of the branch to interact with.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="branch_name", | ||
type="string", | ||
description="The name of the branch to interact with.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="sha", | ||
type="string", | ||
description="The sha of the commit to interact with.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="base", | ||
type="string", | ||
description="The base of the commit to interact with.", | ||
required=False, | ||
), | ||
Parameter( | ||
name="head", | ||
type="string", | ||
description="The head of the commit to interact with.", | ||
required=False, | ||
), | ||
] | ||
) | ||
name: str = "GithubCommitTool" | ||
description: str = ( | ||
"Interacts with GitHub repositories using PyGithub to submit commits." | ||
) | ||
type: Literal["GithubCommitTool"] = "GithubCommitTool" | ||
token: str | ||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
def __call__(self, action: str, **kwargs) -> Dict[str, Any]: | ||
""" | ||
Central method to call various GitHub API actions. | ||
Args: | ||
action (str): The action to perform. | ||
**kwargs: Additional keyword arguments related to the action. | ||
Returns: | ||
Dict[str, Any]: The result of the action. | ||
""" | ||
action_map = { | ||
"create_commit": self.create_commit, | ||
"list_commits": self.list_commits, | ||
"get_commit": self.get_commit, | ||
"compare_commits": self.compare_commits, | ||
} | ||
|
||
if action in action_map: | ||
self._github = Github(self.token) | ||
return {action: action_map[action](**kwargs)} | ||
|
||
raise ValueError(f"Action '{action}' is not supported.") | ||
|
||
# Commit Management Methods | ||
def create_commit( | ||
self, | ||
repo_name: str, | ||
file_path: str, | ||
message: str, | ||
content: str, | ||
branch: str = "main", | ||
) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
repo.create_file( | ||
path=file_path, message=message, content=content, branch=branch | ||
) | ||
return f"Commit created successfully at {file_path}." | ||
except GithubException as e: | ||
return f"Error creating commit: {e}" | ||
|
||
def list_commits(self, repo_name: str) -> List[str]: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
return [commit.commit.message for commit in repo.get_commits()] | ||
except GithubException as e: | ||
return f"Error listing commits: {e}" | ||
|
||
def get_commit(self, repo_name: str, sha: str) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
commit = repo.get_commit(sha=sha) | ||
return f"Commit {commit.sha}: {commit.commit.message}" | ||
except GithubException as e: | ||
return f"Error retrieving commit: {e}" | ||
|
||
def compare_commits(self, repo_name: str, base: str, head: str) -> str: | ||
try: | ||
repo = self._github.get_repo(repo_name) | ||
comparison = repo.compare(base, head) | ||
return f"Comparison from {base} to {head}:\n{comparison.diff_url}" | ||
except GithubException as e: | ||
return f"Error comparing commits: {e}" |
Oops, something went wrong.