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
20 changes: 9 additions & 11 deletions src/ghpr/commands/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,12 @@ def clone(

def register(cli):
"""Register command with CLI."""
cli.command()(
opt('-d', '--directory', help='Directory to clone into (default: gh/{number})')(
flag('-G', '--no-gist', help='Skip creating a gist')(
flag('--no-comments', help='Skip cloning comments')(
arg('spec', required=False)(
clone
)
)
)
)
)

@cli.command()
@arg('spec', required=False)
@flag('--no-comments', help='Skip cloning comments')
@flag('-G', '--no-gist', help='Skip creating a gist')
@opt('-d', '--directory', help='Directory to clone into (default: gh/{number})')
def clone_cmd(spec, no_comments, no_gist, directory):
"""Clone a PR or Issue description and comments to a local directory."""
clone(spec, directory, no_gist, no_comments)
79 changes: 54 additions & 25 deletions src/ghpr/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,33 @@ def _finalize_created_item(
proc.run('git', 'commit', '-m', f'Rename to {new_filename} and add {item_label} #{number} link', log=None)
err(f"Updated {new_filename} with {item_label} link")

# Push updates to GitHub (link-def and footer)
from . import push as push_module
err("Pushing updates to GitHub...")
push_module.push(
gist=False,
dry_run=False,
footer=0, # Auto-detect footer based on gist existence
no_footer=False,
open_browser=False,
images=False,
gist_private=None,
no_comments=True, # Don't sync comments during create
force_others=False
)

# Push to gist remote if it exists
from ..gist import find_gist_remote
gist_remote = find_gist_remote()
if gist_remote:
try:
proc.run('git', 'push', gist_remote, 'main', log=None)
err(f"Pushed to gist remote '{gist_remote}'")
except Exception as e:
err(f"Warning: Could not push to gist: {e}")
else:
err("No gist remote found, skipping gist push")

# Rename directory from gh/new to gh/{number}
current_dir = Path.cwd()
parent_dir = current_dir.parent
Expand Down Expand Up @@ -300,7 +327,17 @@ def create(
yes: int,
dry_run: bool,
) -> None:
"""Create a new PR or Issue from the current draft."""
"""Create a new PR or Issue from the current draft.

By default, opens GitHub's web editor for interactive creation.
Use -y to skip the web editor and create via API instead.
"""
# Validate draft flag with web editor mode
if draft and yes == 0:
err("Error: --draft flag requires -y (cannot use draft mode with web editor)")
err("Use: ghpr create -d -y (or -yy for silent creation)")
exit(1)

if issue:
create_new_issue(repo, yes, dry_run)
else:
Expand Down Expand Up @@ -623,30 +660,22 @@ def create_new_issue(

def register(cli):
"""Register commands with CLI."""

# Register init command
cli.command()(
opt('-r', '--repo', help='Repository (owner/repo format)')(
opt('-b', '--base', help='Base branch (default: repo default branch)')(
init
)
)
)
@cli.command()
@opt('-r', '--repo', help='Repository (owner/repo format)')
@opt('-b', '--base', help='Base branch (default: repo default branch)')
def init_cmd(repo, base):
init(repo, base)

# Register create command
cli.command()(
opt('-b', '--base', help='Base branch (default: repo default branch)')(
flag('-d', '--draft', help='Create as draft PR')(
opt('-h', '--head', help='Head branch (default: auto-detect from parent repo)')(
flag('-i', '--issue', help='Create an issue instead of a PR')(
flag('-n', '--dry-run', help='Show what would be done without creating')(
opt('-r', '--repo', help='Repository (owner/repo format, default: auto-detect)')(
opt('-y', '--yes', count=True, default=0, help='Skip prompt: once = create then view, twice = create silently (default: open web editor during creation)')(
create
)
)
)
)
)
)
)
)
@cli.command(name='create', help='Create PR/Issue (default: web editor; use -y for API mode)')
@opt('-y', '--yes', count=True, default=0, help='Skip web editor: -y = create via API then view, -yy = create silently (default: interactive web editor)')
@opt('-r', '--repo', help='Repository (owner/repo format, default: auto-detect)')
@flag('-n', '--dry-run', help='Show what would be done without creating')
@flag('-i', '--issue', help='Create an issue instead of a PR')
@opt('-h', '--head', help='Head branch (default: auto-detect from parent repo)')
@flag('-d', '--draft', help='Create as draft PR (requires -y; incompatible with web editor)')
@opt('-b', '--base', help='Base branch (default: repo default branch)')
def create_cmd(yes, repo, dry_run, issue, head, draft, base):
create(head, base, draft, issue, repo, yes, dry_run)
14 changes: 6 additions & 8 deletions src/ghpr/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ def diff(

def register(cli):
"""Register command with CLI."""
cli.command()(
opt('-c', '--color', type=Choice(['auto', 'always', 'never']), default='auto',
help='When to use colored output (default: auto)')(
flag('--no-comments', help='Skip diffing comments')(
diff
)
)
)

@cli.command()
@flag('--no-comments', help='Skip diffing comments')
@opt('-c', '--color', type=Choice(['auto', 'always', 'never']), default='auto', help='When to use colored output (default: auto)')
def diff_cmd(no_comments, color):
diff(color, no_comments)
16 changes: 7 additions & 9 deletions src/ghpr/commands/ingest_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,10 @@ def ingest_attachments(

def register(cli):
"""Register command with CLI."""
cli.command(name='ingest-attachments')(
opt('-b', '--branch', help='Branch name for attachments (default: $GHPR_INGEST_BRANCH or "attachments")')(
flag('--no-ingest', help='Disable attachment ingestion')(
flag('-n', '--dry-run', help='Show what would be done without making changes')(
ingest_attachments
)
)
)
)

@cli.command(name='ingest-attachments')
@flag('-n', '--dry-run', help='Show what would be done without making changes')
@flag('--no-ingest', help='Disable attachment ingestion')
@opt('-b', '--branch', help='Branch name for attachments (default: $GHPR_INGEST_BRANCH or "attachments")')
def ingest_attachments_cmd(dry_run, no_ingest, branch):
ingest_attachments(branch, no_ingest, dry_run)
10 changes: 5 additions & 5 deletions src/ghpr/commands/open.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def open_pr(gist: bool) -> None:

def register(cli):
"""Register command with CLI."""
cli.command(name='open')(
flag('-g', '--gist', help='Open gist instead of PR')(
open_pr
)
)

@cli.command(name='open')
@flag('-g', '--gist', help='Open gist instead of PR')
def open_cmd(gist):
open_pr(gist)
25 changes: 10 additions & 15 deletions src/ghpr/commands/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,13 @@ def pull(

def register(cli):
"""Register command with CLI."""
cli.command()(
flag('-g', '--gist', help='Also sync to gist')(
flag('-n', '--dry-run', help='Show what would be done')(
opt('-f/-F', '--footer/--no-footer', default=None, help='Add gist footer to PR (default: auto - add if gist exists)')(
flag('-o', '--open', 'open_browser', help='Open PR in browser after pulling')(
opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')(
flag('--no-comments', help='Skip syncing comments')(
pull
)
)
)
)
)
)
)

@cli.command()
@flag('--no-comments', help='Skip syncing comments')
@opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')
@flag('-o', '--open', 'open_browser', help='Open PR in browser after pulling')
@opt('-f/-F', '--footer/--no-footer', default=None, help='Add gist footer to PR (default: auto - add if gist exists)')
@flag('-n', '--dry-run', help='Show what would be done')
@flag('-g', '--gist', help='Also sync to gist')
def pull_cmd(no_comments, gist_private, open_browser, footer, dry_run, gist):
pull(gist, dry_run, footer, open_browser, gist_private, no_comments)
34 changes: 13 additions & 21 deletions src/ghpr/commands/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,24 +625,16 @@ def sync_to_gist(

def register(cli):
"""Register command with CLI."""
cli.command()(
flag('-g', '--gist', help='Also sync to gist')(
flag('-n', '--dry-run', help='Show what would be done without making changes')(
opt('-f', '--footer', count=True, help='Footer level: -f = hidden footer, -ff = visible footer')(
flag('-F', '--no-footer', help='Disable footer completely')(
flag('-o', '--open', 'open_browser', help='Open PR in browser after pushing')(
flag('-i', '--images', help='Upload local images and replace references')(
opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')(
flag('--no-comments', help='Skip pushing comment changes')(
flag('-C', '--force-others', help='Allow pushing edits to other users\' comments (may fail at API level)')(
push
)
)
)
)
)
)
)
)
)
)

@cli.command()
@flag('-C', '--force-others', help='Allow pushing edits to other users\' comments (may fail at API level)')
@flag('--no-comments', help='Skip pushing comment changes')
@opt('-p/-P', '--private/--public', 'gist_private', default=None, help='Gist visibility: -p = private, -P = public (default: match repo visibility)')
@flag('-i', '--images', help='Upload local images and replace references')
@flag('-o', '--open', 'open_browser', help='Open PR in browser after pushing')
@flag('-F', '--no-footer', help='Disable footer completely')
@opt('-f', '--footer', count=True, help='Footer level: -f = hidden footer, -ff = visible footer')
@flag('-n', '--dry-run', help='Show what would be done without making changes')
@flag('-g', '--gist', help='Also sync to gist')
def push_cmd(force_others, no_comments, gist_private, images, open_browser, no_footer, footer, dry_run, gist):
push(gist, dry_run, footer, no_footer, open_browser, images, gist_private, no_comments, force_others)
10 changes: 5 additions & 5 deletions src/ghpr/commands/shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def shell_integration(shell: str | None) -> None:

def register(cli):
"""Register command with CLI."""
cli.command(name='shell-integration')(
arg('shell', type=Choice(['bash', 'zsh', 'fish']), required=False)(
shell_integration
)
)

@cli.command(name='shell-integration')
@arg('shell', type=Choice(['bash', 'zsh', 'fish']), required=False)
def shell_integration_cmd(shell):
shell_integration(shell)
10 changes: 5 additions & 5 deletions src/ghpr/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def show(gist: bool) -> None:

def register(cli):
"""Register command with CLI."""
cli.command()(
flag('-g', '--gist', help='Only show gist URL')(
show
)
)

@cli.command()
@flag('-g', '--gist', help='Only show gist URL')
def show_cmd(gist):
show(gist)
20 changes: 8 additions & 12 deletions src/ghpr/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,11 @@ def upload(

def register(cli):
"""Register command with CLI."""
cli.command()(
arg('files', nargs=-1, required=True)(
opt('-b', '--branch', default='assets', help='Branch name in gist (default: assets)')(
opt('-f', '--format', type=Choice(['url', 'markdown', 'img', 'auto']), default='auto',
help='Output format (default: auto - img for images, url for others)')(
opt('-a', '--alt', help='Alt text for markdown/img format')(
upload
)
)
)
)
)

@cli.command()
@opt('-a', '--alt', help='Alt text for markdown/img format')
@opt('-f', '--format', type=Choice(['url', 'markdown', 'img', 'auto']), default='auto', help='Output format (default: auto - img for images, url for others)')
@opt('-b', '--branch', default='assets', help='Branch name in gist (default: assets)')
@arg('files', nargs=-1, required=True)
def upload_cmd(alt, format, branch, files):
upload(files, branch, format, alt)
Loading