Skip to content

Commit a815763

Browse files
chore: [CG-10794] default to Github token if available (#457)
- **chore: default to config env** - **test shouldn't need the token anymore**
1 parent 06661db commit a815763

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from codegen.git.schemas.enums import CheckoutResult, FetchResult
2020
from codegen.git.schemas.repo_config import RepoConfig
2121
from codegen.git.utils.remote_progress import CustomRemoteProgress
22+
from codegen.shared.configs.session_configs import config
2223
from codegen.shared.performance.stopwatch_utils import stopwatch
2324
from codegen.shared.performance.time_utils import humanize_duration
2425

@@ -46,7 +47,7 @@ def __init__(
4647
) -> None:
4748
assert repo_config is not None
4849
self.repo_config = repo_config
49-
self.access_token = access_token
50+
self.access_token = access_token or config.secrets.github_token
5051
self.base_dir = repo_config.base_dir
5152
self.bot_commit = bot_commit
5253

src/codegen/sdk/core/codebase.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,24 @@ def restore_stashed_changes(self):
898898
####################################################################################################################
899899

900900
def create_pr(self, title: str, body: str) -> PullRequest:
901-
"""Creates a PR from the current branch."""
901+
"""Creates a pull request from the current branch to the repository's default branch.
902+
903+
This method will:
904+
1. Stage and commit any pending changes with the PR title as the commit message
905+
2. Push the current branch to the remote repository
906+
3. Create a pull request targeting the default branch
907+
908+
Args:
909+
title (str): The title for the pull request
910+
body (str): The description/body text for the pull request
911+
912+
Returns:
913+
PullRequest: The created GitHub pull request object
914+
915+
Raises:
916+
ValueError: If attempting to create a PR while in a detached HEAD state
917+
ValueError: If the current branch is the default branch
918+
"""
902919
if self._op.git_cli.head.is_detached:
903920
msg = "Cannot make a PR from a detached HEAD"
904921
raise ValueError(msg)

tests/integration/codegen/git/codebase/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def repo_config(tmpdir):
2525
def op(repo_config):
2626
os.chdir(repo_config.base_dir)
2727
GitRepo.clone_from(url=get_authenticated_clone_url_for_repo_config(repo_config, token=config.secrets.github_token), to_path=os.path.join(repo_config.base_dir, repo_config.name), depth=1)
28-
op = LocalRepoOperator(repo_config=repo_config, access_token=config.secrets.github_token)
28+
op = LocalRepoOperator(repo_config=repo_config)
2929
yield op
3030

3131

0 commit comments

Comments
 (0)