Skip to content

test: add codebase.create_pr tests #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import uuid

import pytest

from codegen.git.repo_operator.local_repo_operator import LocalRepoOperator
from codegen.git.utils.clone import clone_repo
from codegen.git.utils.clone_url import get_authenticated_clone_url_for_repo_config
from codegen.sdk.codebase.config import ProjectConfig
from codegen.sdk.core.codebase import Codebase
from codegen.shared.configs.config import config


@pytest.fixture
def codebase(repo_config, tmpdir):
clone_repo(repo_path=f"{tmpdir}/{repo_config.name}", clone_url=get_authenticated_clone_url_for_repo_config(repo_config, token=config.secrets.github_token))
op = LocalRepoOperator(repo_config=repo_config, github_api_key=config.secrets.github_token)
project_config = ProjectConfig(repo_operator=op)
codebase = Codebase(projects=[project_config])
yield codebase


def test_codebase_create_pr_active_branch(codebase: Codebase):
head = f"test-create-pr-{uuid.uuid4()}"
codebase.checkout(branch=head, create_if_missing=True)
codebase.files[0].remove()

Check failure on line 25 in tests/integration/codegen/git/codebase/test_codebase_create_pr.py

View workflow job for this annotation

GitHub Actions / mypy

error: Value of type overloaded function is not indexable [index]
codebase.commit()
pr = codebase.create_pr(title="test-create-pr title", body="test-create-pr body")
assert pr.title == "test-create-pr title"
assert pr.body == "test-create-pr body"
assert pr.draft is False
assert pr.state == "open"
assert pr.head.ref == head
assert pr.base.ref == "main"


def test_codebase_create_pr_detached_head(codebase: Codebase):
codebase.checkout(commit=codebase._op.git_cli.head.commit) # move to detached head state
with pytest.raises(ValueError) as exc_info:
codebase.create_pr(title="test-create-pr title", body="test-create-pr body")
assert "Cannot make a PR from a detached HEAD" in str(exc_info.value)
Loading