Skip to content

Commit

Permalink
Default new PR head to current branch
Browse files Browse the repository at this point in the history
  • Loading branch information
gizmo385 committed Dec 17, 2024
1 parent 7743900 commit 30e2668
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lazy_github/lib/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from lazy_github.lib.config import Config
from lazy_github.lib.constants import JSON_CONTENT_ACCEPT_TYPE
from lazy_github.lib.git_cli import current_local_repo_full_name
from lazy_github.lib.git_cli import current_local_branch_name, current_local_repo_full_name
from lazy_github.lib.github.backends.protocol import BackendType
from lazy_github.lib.github.client import GithubClient
from lazy_github.lib.logging import LazyGithubLogFormatter, lg
Expand All @@ -18,6 +18,7 @@ class LazyGithubContext:
_config: Config | None = None
_client: GithubClient | None = None
_current_directory_repo: str | None = None
_current_directory_branch: str | None = None

# Directly assigned attributes
current_repo: Repository | None = None
Expand Down Expand Up @@ -65,6 +66,13 @@ def current_directory_repo(cls) -> str | None:
cls._current_directory_repo = current_local_repo_full_name()
return cls._current_directory_repo

@classproperty
def current_directory_branch(cls) -> str | None:
"""The owner/name of the repo associated with the current working directory (if one exists)"""
if not cls._current_directory_branch:
cls._current_directory_branch = current_local_branch_name()
return cls._current_directory_branch


def github_headers(accept: str = JSON_CONTENT_ACCEPT_TYPE, cache_duration: Optional[int] = None) -> dict[str, str]:
"""Helper function to build headers for Github API requests"""
Expand Down
7 changes: 7 additions & 0 deletions lazy_github/ui/screens/new_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ def head_ref(self) -> str:
def base_ref(self) -> str:
return self._base_ref_input.value

@work
async def set_default_branch_value(self) -> None:
if LazyGithubContext.current_directory_repo == LazyGithubContext.current_repo.full_name:
if LazyGithubContext.current_directory_branch:
self.query_one("#head_ref", Input).value = LazyGithubContext.current_directory_branch

async def on_mount(self) -> None:
self.fetch_branches()
self.set_default_branch_value()

@on(BranchesLoaded)
def handle_loaded_branches(self, message: BranchesLoaded) -> None:
Expand Down

0 comments on commit 30e2668

Please sign in to comment.