swarmauri_toolkit_github 0.6.1.dev3__py3-none-any.whl → 0.6.1.dev5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,108 +1,108 @@
1
- # swarmauri/community/tools/concrete/GithubCommunityTool.py
2
-
3
- from github import Github, GithubException
4
- from typing import List, Dict, Literal, Any
5
- from swarmauri_core.ComponentBase import ComponentBase
6
- from pydantic import Field, ConfigDict
7
- from swarmauri_base.tools.ToolBase import ToolBase
8
- from swarmauri_standard.tools.Parameter import Parameter
9
-
10
-
11
- @ComponentBase.register_type(ToolBase, "GithubBranchTool")
12
- class GithubBranchTool(ToolBase):
13
- version: str = "1.1.0"
14
- parameters: List[Parameter] = Field(
15
- default_factory=lambda: [
16
- Parameter(
17
- name="action",
18
- type="string",
19
- description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
20
- required=True,
21
- ),
22
- Parameter(
23
- name="repo_name",
24
- type="string",
25
- description="The full name of the repository to interact with, e.g. 'owner/repository'.",
26
- required=True,
27
- ),
28
- Parameter(
29
- name="branch_name",
30
- type="string",
31
- description="The name of the branch to interact with.",
32
- required=False,
33
- ),
34
- Parameter(
35
- name="source_branch",
36
- type="string",
37
- description="The name of the source branch to create a branch from.",
38
- required=False,
39
- ),
40
- ]
41
- )
42
- name: str = "GithubBranchTool"
43
- description: str = "Interacts with GitHub branches using PyGithub."
44
- type: Literal["GithubBranchTool"] = "GithubBranchTool"
45
- token: str
46
- model_config = ConfigDict(arbitrary_types_allowed=True)
47
-
48
- def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
49
- """
50
- Central method to call various GitHub API actions.
51
-
52
- Args:
53
- action (str): The action to perform.
54
- **kwargs: Additional keyword arguments related to the action.
55
-
56
- Returns:
57
- Dict[str, Any]: The result of the action.
58
- """
59
- action_map = {
60
- "create_branch": self.create_branch,
61
- "delete_branch": self.delete_branch,
62
- "list_branches": self.list_branches,
63
- "get_branch": self.get_branch,
64
- }
65
-
66
- if action in action_map:
67
- self._github = Github(self.token)
68
- return {action: action_map[action](**kwargs)}
69
-
70
- raise ValueError(f"Action '{action}' is not supported.")
71
-
72
- # Branch Management Methods
73
- def create_branch(
74
- self, repo_name: str, branch_name: str, source: str = "main"
75
- ) -> str:
76
- try:
77
- repo = self._github.get_repo(repo_name)
78
- source_branch = repo.get_branch(source)
79
- repo.create_git_ref(
80
- ref=f"refs/heads/{branch_name}", sha=source_branch.commit.sha
81
- )
82
- return f"Branch '{branch_name}' created successfully."
83
- except GithubException as e:
84
- return f"Error creating branch: {e}"
85
-
86
- def delete_branch(self, repo_name: str, branch_name: str) -> str:
87
- try:
88
- repo = self._github.get_repo(repo_name)
89
- ref = repo.get_git_ref(f"heads/{branch_name}")
90
- ref.delete()
91
- return f"Branch '{branch_name}' deleted successfully."
92
- except GithubException as e:
93
- return f"Error deleting branch: {e}"
94
-
95
- def list_branches(self, repo_name: str) -> List[str]:
96
- try:
97
- repo = self._github.get_repo(repo_name)
98
- return [branch.name for branch in repo.get_branches()]
99
- except GithubException as e:
100
- return f"Error listing branches: {e}"
101
-
102
- def get_branch(self, repo_name: str, branch_name: str) -> str:
103
- try:
104
- repo = self._github.get_repo(repo_name)
105
- branch = repo.get_branch(branch_name)
106
- return f"Branch {branch.name}: {branch.commit.sha}"
107
- except GithubException as e:
108
- return f"Error retrieving branch: {e}"
1
+ # swarmauri/community/tools/concrete/GithubCommunityTool.py
2
+
3
+ from github import Github, GithubException
4
+ from typing import List, Dict, Literal, Any
5
+ from swarmauri_core.ComponentBase import ComponentBase
6
+ from pydantic import Field, ConfigDict
7
+ from swarmauri_base.tools.ToolBase import ToolBase
8
+ from swarmauri_standard.tools.Parameter import Parameter
9
+
10
+
11
+ @ComponentBase.register_type(ToolBase, "GithubBranchTool")
12
+ class GithubBranchTool(ToolBase):
13
+ version: str = "1.1.0"
14
+ parameters: List[Parameter] = Field(
15
+ default_factory=lambda: [
16
+ Parameter(
17
+ name="action",
18
+ type="string",
19
+ description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
20
+ required=True,
21
+ ),
22
+ Parameter(
23
+ name="repo_name",
24
+ type="string",
25
+ description="The full name of the repository to interact with, e.g. 'owner/repository'.",
26
+ required=True,
27
+ ),
28
+ Parameter(
29
+ name="branch_name",
30
+ type="string",
31
+ description="The name of the branch to interact with.",
32
+ required=False,
33
+ ),
34
+ Parameter(
35
+ name="source_branch",
36
+ type="string",
37
+ description="The name of the source branch to create a branch from.",
38
+ required=False,
39
+ ),
40
+ ]
41
+ )
42
+ name: str = "GithubBranchTool"
43
+ description: str = "Interacts with GitHub branches using PyGithub."
44
+ type: Literal["GithubBranchTool"] = "GithubBranchTool"
45
+ token: str
46
+ model_config = ConfigDict(arbitrary_types_allowed=True)
47
+
48
+ def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
49
+ """
50
+ Central method to call various GitHub API actions.
51
+
52
+ Args:
53
+ action (str): The action to perform.
54
+ **kwargs: Additional keyword arguments related to the action.
55
+
56
+ Returns:
57
+ Dict[str, Any]: The result of the action.
58
+ """
59
+ action_map = {
60
+ "create_branch": self.create_branch,
61
+ "delete_branch": self.delete_branch,
62
+ "list_branches": self.list_branches,
63
+ "get_branch": self.get_branch,
64
+ }
65
+
66
+ if action in action_map:
67
+ self._github = Github(self.token)
68
+ return {action: action_map[action](**kwargs)}
69
+
70
+ raise ValueError(f"Action '{action}' is not supported.")
71
+
72
+ # Branch Management Methods
73
+ def create_branch(
74
+ self, repo_name: str, branch_name: str, source: str = "main"
75
+ ) -> str:
76
+ try:
77
+ repo = self._github.get_repo(repo_name)
78
+ source_branch = repo.get_branch(source)
79
+ repo.create_git_ref(
80
+ ref=f"refs/heads/{branch_name}", sha=source_branch.commit.sha
81
+ )
82
+ return f"Branch '{branch_name}' created successfully."
83
+ except GithubException as e:
84
+ return f"Error creating branch: {e}"
85
+
86
+ def delete_branch(self, repo_name: str, branch_name: str) -> str:
87
+ try:
88
+ repo = self._github.get_repo(repo_name)
89
+ ref = repo.get_git_ref(f"heads/{branch_name}")
90
+ ref.delete()
91
+ return f"Branch '{branch_name}' deleted successfully."
92
+ except GithubException as e:
93
+ return f"Error deleting branch: {e}"
94
+
95
+ def list_branches(self, repo_name: str) -> List[str]:
96
+ try:
97
+ repo = self._github.get_repo(repo_name)
98
+ return [branch.name for branch in repo.get_branches()]
99
+ except GithubException as e:
100
+ return f"Error listing branches: {e}"
101
+
102
+ def get_branch(self, repo_name: str, branch_name: str) -> str:
103
+ try:
104
+ repo = self._github.get_repo(repo_name)
105
+ branch = repo.get_branch(branch_name)
106
+ return f"Branch {branch.name}: {branch.commit.sha}"
107
+ except GithubException as e:
108
+ return f"Error retrieving branch: {e}"
@@ -1,141 +1,141 @@
1
- from github import Github, GithubException
2
- from typing import List, Dict, Literal, Any
3
- from swarmauri_core.ComponentBase import ComponentBase
4
- from pydantic import Field, ConfigDict
5
- from swarmauri_base.tools.ToolBase import ToolBase
6
- from swarmauri_standard.tools.Parameter import Parameter
7
-
8
-
9
- @ComponentBase.register_type(ToolBase, "GithubCommitTool")
10
- class GithubCommitTool(ToolBase):
11
- version: str = "1.1.0"
12
- parameters: List[Parameter] = Field(
13
- default_factory=lambda: [
14
- Parameter(
15
- name="action",
16
- type="string",
17
- description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
18
- required=True,
19
- ),
20
- Parameter(
21
- name="repo_name",
22
- type="string",
23
- description="The full name of the repository to interact with, e.g. 'owner/repository'.",
24
- required=True,
25
- ),
26
- Parameter(
27
- name="file_path",
28
- type="string",
29
- description="The path to the file in the repository, e.g. 'path/to/file.txt'.",
30
- required=False,
31
- ),
32
- Parameter(
33
- name="message",
34
- type="string",
35
- description=".",
36
- required=False,
37
- ),
38
- Parameter(
39
- name="content",
40
- type="string",
41
- description="The name of the branch to interact with.",
42
- required=False,
43
- ),
44
- Parameter(
45
- name="branch_name",
46
- type="string",
47
- description="The name of the branch to interact with.",
48
- required=False,
49
- ),
50
- Parameter(
51
- name="sha",
52
- type="string",
53
- description="The sha of the commit to interact with.",
54
- required=False,
55
- ),
56
- Parameter(
57
- name="base",
58
- type="string",
59
- description="The base of the commit to interact with.",
60
- required=False,
61
- ),
62
- Parameter(
63
- name="head",
64
- type="string",
65
- description="The head of the commit to interact with.",
66
- required=False,
67
- ),
68
- ]
69
- )
70
- name: str = "GithubCommitTool"
71
- description: str = (
72
- "Interacts with GitHub repositories using PyGithub to submit commits."
73
- )
74
- type: Literal["GithubCommitTool"] = "GithubCommitTool"
75
- token: str
76
- model_config = ConfigDict(arbitrary_types_allowed=True)
77
-
78
- def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
79
- """
80
- Central method to call various GitHub API actions.
81
-
82
- Args:
83
- action (str): The action to perform.
84
- **kwargs: Additional keyword arguments related to the action.
85
-
86
- Returns:
87
- Dict[str, Any]: The result of the action.
88
- """
89
- action_map = {
90
- "create_commit": self.create_commit,
91
- "list_commits": self.list_commits,
92
- "get_commit": self.get_commit,
93
- "compare_commits": self.compare_commits,
94
- }
95
-
96
- if action in action_map:
97
- self._github = Github(self.token)
98
- return {action: action_map[action](**kwargs)}
99
-
100
- raise ValueError(f"Action '{action}' is not supported.")
101
-
102
- # Commit Management Methods
103
- def create_commit(
104
- self,
105
- repo_name: str,
106
- file_path: str,
107
- message: str,
108
- content: str,
109
- branch: str = "main",
110
- ) -> str:
111
- try:
112
- repo = self._github.get_repo(repo_name)
113
- repo.create_file(
114
- path=file_path, message=message, content=content, branch=branch
115
- )
116
- return f"Commit created successfully at {file_path}."
117
- except GithubException as e:
118
- return f"Error creating commit: {e}"
119
-
120
- def list_commits(self, repo_name: str) -> List[str]:
121
- try:
122
- repo = self._github.get_repo(repo_name)
123
- return [commit.commit.message for commit in repo.get_commits()]
124
- except GithubException as e:
125
- return f"Error listing commits: {e}"
126
-
127
- def get_commit(self, repo_name: str, sha: str) -> str:
128
- try:
129
- repo = self._github.get_repo(repo_name)
130
- commit = repo.get_commit(sha=sha)
131
- return f"Commit {commit.sha}: {commit.commit.message}"
132
- except GithubException as e:
133
- return f"Error retrieving commit: {e}"
134
-
135
- def compare_commits(self, repo_name: str, base: str, head: str) -> str:
136
- try:
137
- repo = self._github.get_repo(repo_name)
138
- comparison = repo.compare(base, head)
139
- return f"Comparison from {base} to {head}:\n{comparison.diff_url}"
140
- except GithubException as e:
141
- return f"Error comparing commits: {e}"
1
+ from github import Github, GithubException
2
+ from typing import List, Dict, Literal, Any
3
+ from swarmauri_core.ComponentBase import ComponentBase
4
+ from pydantic import Field, ConfigDict
5
+ from swarmauri_base.tools.ToolBase import ToolBase
6
+ from swarmauri_standard.tools.Parameter import Parameter
7
+
8
+
9
+ @ComponentBase.register_type(ToolBase, "GithubCommitTool")
10
+ class GithubCommitTool(ToolBase):
11
+ version: str = "1.1.0"
12
+ parameters: List[Parameter] = Field(
13
+ default_factory=lambda: [
14
+ Parameter(
15
+ name="action",
16
+ type="string",
17
+ description="The action to perform on the GitHub API, e.g., 'create_repo', 'delete_repo', 'create_issue', etc.",
18
+ required=True,
19
+ ),
20
+ Parameter(
21
+ name="repo_name",
22
+ type="string",
23
+ description="The full name of the repository to interact with, e.g. 'owner/repository'.",
24
+ required=True,
25
+ ),
26
+ Parameter(
27
+ name="file_path",
28
+ type="string",
29
+ description="The path to the file in the repository, e.g. 'path/to/file.txt'.",
30
+ required=False,
31
+ ),
32
+ Parameter(
33
+ name="message",
34
+ type="string",
35
+ description=".",
36
+ required=False,
37
+ ),
38
+ Parameter(
39
+ name="content",
40
+ type="string",
41
+ description="The name of the branch to interact with.",
42
+ required=False,
43
+ ),
44
+ Parameter(
45
+ name="branch_name",
46
+ type="string",
47
+ description="The name of the branch to interact with.",
48
+ required=False,
49
+ ),
50
+ Parameter(
51
+ name="sha",
52
+ type="string",
53
+ description="The sha of the commit to interact with.",
54
+ required=False,
55
+ ),
56
+ Parameter(
57
+ name="base",
58
+ type="string",
59
+ description="The base of the commit to interact with.",
60
+ required=False,
61
+ ),
62
+ Parameter(
63
+ name="head",
64
+ type="string",
65
+ description="The head of the commit to interact with.",
66
+ required=False,
67
+ ),
68
+ ]
69
+ )
70
+ name: str = "GithubCommitTool"
71
+ description: str = (
72
+ "Interacts with GitHub repositories using PyGithub to submit commits."
73
+ )
74
+ type: Literal["GithubCommitTool"] = "GithubCommitTool"
75
+ token: str
76
+ model_config = ConfigDict(arbitrary_types_allowed=True)
77
+
78
+ def __call__(self, action: str, **kwargs) -> Dict[str, Any]:
79
+ """
80
+ Central method to call various GitHub API actions.
81
+
82
+ Args:
83
+ action (str): The action to perform.
84
+ **kwargs: Additional keyword arguments related to the action.
85
+
86
+ Returns:
87
+ Dict[str, Any]: The result of the action.
88
+ """
89
+ action_map = {
90
+ "create_commit": self.create_commit,
91
+ "list_commits": self.list_commits,
92
+ "get_commit": self.get_commit,
93
+ "compare_commits": self.compare_commits,
94
+ }
95
+
96
+ if action in action_map:
97
+ self._github = Github(self.token)
98
+ return {action: action_map[action](**kwargs)}
99
+
100
+ raise ValueError(f"Action '{action}' is not supported.")
101
+
102
+ # Commit Management Methods
103
+ def create_commit(
104
+ self,
105
+ repo_name: str,
106
+ file_path: str,
107
+ message: str,
108
+ content: str,
109
+ branch: str = "main",
110
+ ) -> str:
111
+ try:
112
+ repo = self._github.get_repo(repo_name)
113
+ repo.create_file(
114
+ path=file_path, message=message, content=content, branch=branch
115
+ )
116
+ return f"Commit created successfully at {file_path}."
117
+ except GithubException as e:
118
+ return f"Error creating commit: {e}"
119
+
120
+ def list_commits(self, repo_name: str) -> List[str]:
121
+ try:
122
+ repo = self._github.get_repo(repo_name)
123
+ return [commit.commit.message for commit in repo.get_commits()]
124
+ except GithubException as e:
125
+ return f"Error listing commits: {e}"
126
+
127
+ def get_commit(self, repo_name: str, sha: str) -> str:
128
+ try:
129
+ repo = self._github.get_repo(repo_name)
130
+ commit = repo.get_commit(sha=sha)
131
+ return f"Commit {commit.sha}: {commit.commit.message}"
132
+ except GithubException as e:
133
+ return f"Error retrieving commit: {e}"
134
+
135
+ def compare_commits(self, repo_name: str, base: str, head: str) -> str:
136
+ try:
137
+ repo = self._github.get_repo(repo_name)
138
+ comparison = repo.compare(base, head)
139
+ return f"Comparison from {base} to {head}:\n{comparison.diff_url}"
140
+ except GithubException as e:
141
+ return f"Error comparing commits: {e}"