Skip to content

Pr Cmd

CLI command for generating pull requests using the refactored lazy-loading pattern.

PRAction

Bases: str, Enum

Actions for PR command.

Source code in src/codemap/cli/pr_cmd.py
14
15
16
17
18
class PRAction(str, Enum):
	"""Actions for PR command."""

	CREATE = "create"
	UPDATE = "update"

CREATE class-attribute instance-attribute

CREATE = 'create'

UPDATE class-attribute instance-attribute

UPDATE = 'update'

validate_workflow_strategy

validate_workflow_strategy(value: str | None) -> str | None

Validate workflow strategy - lightweight callback for typer.

Source code in src/codemap/cli/pr_cmd.py
21
22
23
24
25
26
27
28
def validate_workflow_strategy(value: str | None) -> str | None:
	"""Validate workflow strategy - lightweight callback for typer."""
	# Avoid heavy imports like Console here
	valid_strategies = ["github-flow", "gitflow", "trunk-based"]
	if value is None or value in valid_strategies:
		return value
	msg = f"Invalid workflow strategy: {value}. Must be one of: {', '.join(valid_strategies)}"
	raise typer.BadParameter(msg)

ActionArg module-attribute

ActionArg = Annotated[
	PRAction,
	Argument(help="Action to perform: create or update"),
]

BranchNameOpt module-attribute

BranchNameOpt = Annotated[
	str | None,
	Option("--branch", "-b", help="Target branch name"),
]

BranchTypeOpt module-attribute

BranchTypeOpt = Annotated[
	str | None,
	Option(
		"--type",
		"-t",
		help="Branch type (feature, release, hotfix, bugfix)",
	),
]

BaseBranchOpt module-attribute

BaseBranchOpt = Annotated[
	str | None,
	Option(
		"--base",
		help="Base branch for the PR (defaults to repo default)",
	),
]

TitleOpt module-attribute

TitleOpt = Annotated[
	str | None, Option("--title", help="Pull request title")
]

DescriptionOpt module-attribute

DescriptionOpt = Annotated[
	str | None,
	Option(
		"--desc",
		"-d",
		help="Pull request description (file path or text)",
	),
]

NoCommitOpt module-attribute

NoCommitOpt = Annotated[
	bool,
	Option(
		"--no-commit",
		help="Skip the commit process before creating PR",
	),
]

ForcePushOpt module-attribute

ForcePushOpt = Annotated[
	bool,
	Option(
		"--force-push", "-f", help="Force push the branch"
	),
]

PRNumberOpt module-attribute

PRNumberOpt = Annotated[
	int | None,
	Option(
		"--pr",
		help="PR number to update (required for update action)",
	),
]

WorkflowOpt module-attribute

WorkflowOpt = Annotated[
	str | None,
	Option(
		"--workflow",
		"-w",
		help="Git workflow strategy (github-flow, gitflow, trunk-based)",
		callback=validate_workflow_strategy,
	),
]

NonInteractiveOpt module-attribute

NonInteractiveOpt = Annotated[
	bool,
	Option(
		"--non-interactive",
		help="Run in non-interactive mode",
	),
]

ModelOpt module-attribute

ModelOpt = Annotated[
	str | None,
	Option(
		"--model",
		"-m",
		help="LLM model for content generation",
	),
]

ApiBaseOpt module-attribute

ApiBaseOpt = Annotated[
	str | None,
	Option("--api-base", help="API base URL for LLM"),
]

ApiKeyOpt module-attribute

ApiKeyOpt = Annotated[
	str | None, Option("--api-key", help="API key for LLM")
]

BypassHooksFlag module-attribute

BypassHooksFlag = Annotated[
	bool,
	Option(
		"--bypass-hooks",
		"--no-verify",
		help="Bypass git hooks with --no-verify",
	),
]

register_command

register_command(app: Typer) -> None

Register the pr command with the Typer app.

Source code in src/codemap/cli/pr_cmd.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def register_command(app: typer.Typer) -> None:
	"""Register the pr command with the Typer app."""

	@app.command("pr")
	@asyncer.runnify
	async def pr_command_entrypoint(
		action: ActionArg = PRAction.CREATE,
		branch_name: BranchNameOpt = None,
		branch_type: BranchTypeOpt = None,
		base_branch: BaseBranchOpt = None,
		title: TitleOpt = None,
		description: DescriptionOpt = None,
		no_commit: NoCommitOpt = False,
		force_push: ForcePushOpt = False,
		pr_number: PRNumberOpt = None,
		workflow: WorkflowOpt = None,
		non_interactive: NonInteractiveOpt = False,
		bypass_hooks: BypassHooksFlag = False,
	) -> None:
		"""Create or update a GitHub/GitLab pull request with generated content."""
		await _pr_command_impl(
			action=action,
			branch_name=branch_name,
			branch_type=branch_type,
			base_branch=base_branch,
			title=title,
			description=description,
			no_commit=no_commit,
			force_push=force_push,
			pr_number=pr_number,
			workflow=workflow,
			non_interactive=non_interactive,
			bypass_hooks=bypass_hooks,
		)