Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 9 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ jobs:
artifact-ids: ${{ needs.build.outputs.artifact-id }}
path: build_output

- name: Read the PR number
id: pr_number_reader
run: echo "PR_NUMBER=$(cat build_output/PR_NUMBER.txt)" >> $GITHUB_ENV
- name: Read the asset list
id: asset-list
run: |
echo "WHL_CHECKSUM='$(sha256sum build_output/*whl)'" >> $GITHUB_ENV
echo "PEX_CHECKSUM='$(sha256sum build_output/*pex)'" >> $GITHUB_ENV

- name: Create PR comment with asset link
uses: thollander/actions-comment-pull-request@v3
with:
message: |
🎉 **Build Assets are ready!**

You can download the artifacts from the [build run](https://github.com{{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}).
You can download the artifacts from the [build run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
```
$(ls -al build_output/)
${{ env.WHL_CHECKSUM }}
${{ env.PEX_CHECKSUM }}
```
pr_number: ${{ env.PR_NUMBER }}
comment-tag: build-assets
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ repos:
- id: end-of-file-fixer
exclude: '^.+?\.json.+?\.ya?ml$'
- repo: https://github.com/PyCQA/flake8
rev: 7.1.2
rev: '7.1.2'
hooks:
- id: flake8
additional_dependencies: [
'flake8-print==5.0.0'
'flake8-pyproject'
]
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.16.0
hooks:
- id: reorder-python-imports
language_version: python3
- repo: https://github.com/python/black
rev: 24.10
- repo: https://github.com/psf/black
rev: '24.10.0'
hooks:
- id: black
additional_dependencies: [
'click>=8.0.4'
]
]
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gh-worktree = "gh_worktree.cli:main"
[dependency-groups]
dev = [
"pytest>=8.0.0",
"exceptiongroup; python_version < '3.11'",
"pre-commit"
]

Expand All @@ -27,3 +28,7 @@ build-backend = "uv_build"
[tool.pytest.ini_options]
pythonpath = "src"
testpaths = ["tests"]

[tool.flake8]
max-line-length = 100
max-complexity = 10
7 changes: 7 additions & 0 deletions src/gh_worktree/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = version("gh-worktree")
except PackageNotFoundError:
# Package is not installed
__version__ = "unknown"
5 changes: 5 additions & 0 deletions src/gh_worktree/command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List

from gh_worktree.context import Context
from gh_worktree.runtime import Runtime

Expand All @@ -8,6 +10,9 @@ def __init__(self):


class Command(BaseCommand):
_name: str
_aliases: List[str] = []

def __init__(self, runtime: Runtime):
super().__init__()
self._runtime = runtime
Expand Down
5 changes: 5 additions & 0 deletions src/gh_worktree/commands/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@


class CheckoutCommand(Command):
_name = "checkout"

def __call__(self, branch_or_pr: str):
"""Checkout an existing branch or PR as a worktree
:param branch_or_pr: The branch, PR number, or PR URL to create as a worktree
"""
self._context.assert_within_project()
config = self._context.get_config()

Expand Down
2 changes: 2 additions & 0 deletions src/gh_worktree/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@


class CreateCommand(Command):
_name = "create"

def __call__(self, worktree_name: str, *base_ref: Optional[str]):
"""
Create a new worktree in the current project.
Expand Down
2 changes: 2 additions & 0 deletions src/gh_worktree/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def destination_dir(self):
class InitCommand(Command):
"""Initialize a project for use with gh-worktree"""

_name = "init"

def __call__(self, repo: str, *destination_dir: Optional[str]):
"""
Initialize a project for using gh-worktree with it, by cloning the project and configuring
Expand Down
10 changes: 10 additions & 0 deletions src/gh_worktree/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@


class RemoveCommand(Command):
"""Remove a worktree from the current project"""

_name = "remove"
_aliases = ["rm"]

def __call__(self, worktree_name: str, force: bool = False):
"""
Remove a worktree from the current project that was added with `create` or `checkout`
:param worktree_name: The name of the worktree to remove
:param force: Whether to force the removal of the worktree, if it's unmerged
"""
project_dir = self._context.project_dir
if not os.path.exists(os.path.join(project_dir, worktree_name)):
raise ValueError(f"Worktree {worktree_name} does not exist")
Expand Down
26 changes: 17 additions & 9 deletions src/gh_worktree/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from gh_worktree.runtime import Runtime
from gh_worktree import __version__
from gh_worktree.command import Command
from gh_worktree.commands.checkout import CheckoutCommand
from gh_worktree.commands.create import CreateCommand
from gh_worktree.commands.init import InitCommand
from gh_worktree.commands.remove import RemoveCommand
from gh_worktree.runtime import Runtime


class WorktreeCommands(Command):
Expand All @@ -12,21 +13,28 @@ class WorktreeCommands(Command):
Can be used standalone but still requires the Github CLI (`gh`) to be installed.
"""

_name = "gh-worktree"

def __init__(self):
runtime = Runtime()
super().__init__(runtime)
self._add("create", CreateCommand(self._runtime))
self._add("checkout", CheckoutCommand(self._runtime))
self._add("init", InitCommand(self._runtime))
self._add("remove", RemoveCommand(self._runtime))
self._add(CreateCommand(self._runtime))
self._add(CheckoutCommand(self._runtime))
self._add(InitCommand(self._runtime))
self._add(RemoveCommand(self._runtime))

def _add(self, name: str, command: Command):
def _add(self, command: Command):
"""
Get around where Fire wants keyword flags if commands are set as callable attributes. This
approach allows positional arguments

:param name: The attribute to assign the command's callable
:param command: The command instance
"""
setattr(self, f"_{name}", command)
setattr(self, name, command.__call__)
setattr(self, command._name, command)
setattr(self, command._name, command.__call__)
for alias in command._aliases:
setattr(self, alias, command.__call__)

def version(self):
"""Outputs the version of gh-worktree"""
print(f"gh-worktree {__version__}")
Loading