MCPcopy Index your code
hub / github.com/SkyworkAI/DeepResearchAgent / GitHubEnvironment

Class GitHubEnvironment

src/environment/github_environment.py:40–981  ·  view source on GitHub ↗

GitHub Environment that provides GitHub operations as an environment interface.

Source from the content-addressed store, hash-verified

38
39@ENVIRONMENT.register_module(force=True)
40class GitHubEnvironment(Environment):
41 """GitHub Environment that provides GitHub operations as an environment interface."""
42 model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
43
44 name: str = Field(default="github", description="The name of the GitHub environment.")
45 description: str = Field(default="GitHub environment for repository and Git operations", description="The description of the GitHub environment.")
46 metadata: Dict[str, Any] = Field(default={
47 "has_vision": False,
48 "additional_rules": {
49 "state": "The state of the GitHub environment including repositories and Git status.",
50 "interaction": dedent(f"""
51 Guidelines for interacting with the GitHub environment:
52 - If DO NOT have remote URL, you should `create_repository` first. Then you can `git_clone` the repository.
53 """),
54 }
55 }, description="The metadata of the GitHub environment.")
56 require_grad: bool = Field(default=False, description="Whether the environment requires gradients")
57
58 def __init__(
59 self,
60 base_dir: str = None,
61 token: Optional[SecretStr] = None,
62 username: Optional[SecretStr] = None,
63 require_grad: bool = False,
64 **kwargs
65 ):
66 """
67 Initialize the GitHub environment.
68
69 Args:
70 base_dir (str): Base directory for GitHub operations
71 token (Optional[SecretStr]): GitHub Personal Access Token (PAT)
72 username (Optional[SecretStr]): GitHub username
73 """
74 super().__init__(**kwargs)
75
76 self.base_dir = assemble_project_path(base_dir)
77 self.token = (token or get_env("GITHUB_TOKEN")).get_secret_value()
78 self.username = (username or get_env("GITHUB_USERNAME")).get_secret_value()
79
80 # Initialize GitHub service
81 self.github_service = GitHubService(
82 token=self.token,
83 username=self.username
84 )
85
86 async def initialize(self) -> None:
87 """Initialize the GitHub environment."""
88 await self.github_service.initialize()
89 logger.info(f"| 🚀 GitHub Environment initialized at: {self.base_dir}")
90
91 async def cleanup(self) -> None:
92 """Cleanup the GitHub environment."""
93 await self.github_service.cleanup()
94 logger.info("| 🧹 GitHub Environment cleanup completed")
95
96 def _resolve_path(self, local_path: str) -> str:
97 """Resolve local path relative to base directory.

Callers 1

test_github_systemFunction · 0.85

Calls 1

dedentFunction · 0.90

Tested by 1

test_github_systemFunction · 0.68