From cc79d782802463e52c0af8122309b9645267ee3e Mon Sep 17 00:00:00 2001 From: Basic Factory Date: Sun, 24 Nov 2024 19:09:10 -0600 Subject: [PATCH] re-add github.py --- src/basic_factory/github.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/basic_factory/github.py diff --git a/src/basic_factory/github.py b/src/basic_factory/github.py new file mode 100644 index 0000000..6f7affa --- /dev/null +++ b/src/basic_factory/github.py @@ -0,0 +1,53 @@ +"""GitHub API operations for basic-factory.""" +from dataclasses import dataclass +from github import Github +from github.Repository import Repository + + +@dataclass +class GitHubConfig: + """Configuration for GitHub operations.""" + token: str + repo_owner: str + repo_name: str + + +class GitHubOps: + """GitHub API operations.""" + + def __init__(self, config: GitHubConfig): + self.config = config + self.github = Github(config.token) + self.repo = self.github.get_repo(f"{config.repo_owner}/{config.repo_name}") + + def create_pull_request( + self, + title: str, + body: str, + head_branch: str, + base_branch: str = "main" + ) -> str: + """Create a pull request and return its URL.""" + pr = self.repo.create_pull( + title=title, + body=body, + head=head_branch, + base=base_branch + ) + return pr.html_url + + +def create_hello_world_pr(github: GitHubOps) -> str: + """Create pull request for hello world example.""" + title = "Add hello world function" + body = """This PR adds a basic hello world function with tests. + +Changes: +- Add hello_world() function in hello.py +- Add corresponding test in test_hello.py""" + + return github.create_pull_request( + title=title, + body=body, + head_branch="feature/hello-world" + ) \ No newline at end of file