AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(blocks): Add github create repo block (#9169)
Bently858dc7adc3d2
diff --git a/autogpt_platform/backend/backend/blocks/github/pull_requests.py b/autogpt_platform/backend/backend/blocks/github/pull_requests.pyindex 905b6e3462..cd5c7a3588 100644--- a/autogpt_platform/backend/backend/blocks/github/pull_requests.py+++ b/autogpt_platform/backend/backend/blocks/github/pull_requests.py@@ -732,3 +732,111 @@ class GithubUpdateFileBlock(Block):yield "sha", shaexcept Exception as e:yield "error", str(e)+++class GithubCreateRepositoryBlock(Block):+ class Input(BlockSchema):+ credentials: GithubCredentialsInput = GithubCredentialsField("repo")+ name: str = SchemaField(+ description="Name of the repository to create",+ placeholder="my-new-repo",+ )+ description: str = SchemaField(+ description="Description of the repository",+ placeholder="A description of the repository",+ default="",+ )+ private: bool = SchemaField(+ description="Whether the repository should be private",+ default=False,+ )+ auto_init: bool = SchemaField(+ description="Whether to initialize the repository with a README",+ default=True,+ )+ gitignore_template: str = SchemaField(+ description="Git ignore template to use (e.g., Python, Node, Java)",+ default="",+ )++ class Output(BlockSchema):+ url: str = SchemaField(description="URL of the created repository")+ clone_url: str = SchemaField(description="Git clone URL of the repository")+ error: str = SchemaField(+ description="Error message if the repository creation failed"+ )++ def __init__(self):+ super().__init__(+ id="029ec3b8-1cfd-46d3-b6aa-28e4a706efd1",+ description="This block creates a new GitHub repository.",+ categories={BlockCategory.DEVELOPER_TOOLS},+ input_schema=GithubCreateRepositoryBlock.Input,+ output_schema=GithubCreateRepositoryBlock.Output,+ test_input={+ "name": "test-repo",+ "description": "A test repository",+ "private": False,+ "auto_init": True,+ "gitignore_template": "Python",+ "credentials": TEST_CREDENTIALS_INPUT,+ },+ test_credentials=TEST_CREDENTIALS,+ test_output=[+ ("url", "https://github.com/owner/test-repo"),+ ("clone_url", "https://github.com/owner/test-repo.git"),+ ],+ test_mock={+ "create_repository": lambda *args, **kwargs: (+ "https://github.com/owner/test-repo",+ "https://github.com/owner/test-repo.git",+ )+ },+ )++ @staticmethod+ def create_repository(+ credentials: GithubCredentials,+ name: str,+ description: str,+ private: bool,+ auto_init: bool,+ gitignore_template: str,+ ) -> tuple[str, str]:+ api = get_api(credentials, convert_urls=False) # Disable URL conversion+ data = {+ "name": name,+ "description": description,+ "private": private,+ "auto_init": auto_init,+ }++ if gitignore_template:+ data["gitignore_template"] = gitignore_template++ # Create repository using the user endpoint+ response = api.post("https://api.github.com/user/repos", json=data)+ result = response.json()++ return result["html_url"], result["clone_url"]++ def run(+ self,+ input_data: Input,+ *,+ credentials: GithubCredentials,+ **kwargs,+ ) -> BlockOutput:+ try:+ url, clone_url = self.create_repository(+ credentials,+ input_data.name,+ input_data.description,+ input_data.private,+ input_data.auto_init,+ input_data.gitignore_template,+ )+ yield "url", url+ yield "clone_url", clone_url+ except Exception as e:+ yield "error", str(e)