-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: move logger.debug into function body for github_create_branch #2093
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,14 +7,24 @@ | |||||||||||||||||||||||||||||||
| @tool | ||||||||||||||||||||||||||||||||
| def github_create_branch(branch_name: str) -> str: | ||||||||||||||||||||||||||||||||
| """Create and checkout a new git branch. | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||
| branch_name: The name of the branch to create and checkout. | ||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| # Check if we are in a git repository | ||||||||||||||||||||||||||||||||
| subprocess.run(["git", "rev-parse", "--is-inside-work-tree"], check=True, capture_output=True) | ||||||||||||||||||||||||||||||||
| # Validate branch name to prevent misinterpretation as git options or invalid refs | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| subprocess.run( | ||||||||||||||||||||||||||||||||
| ["git", "check-ref-format", "--branch", branch_name], | ||||||||||||||||||||||||||||||||
| check=True, capture_output=True, text=True | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
| except subprocess.CalledProcessError as e: | ||||||||||||||||||||||||||||||||
| return f"Error: invalid branch name '{branch_name}': {e.stderr.strip() if e.stderr else 'branch name is not a valid git ref'}" | ||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+25
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To strictly validate the literal branch name, use
Suggested change
|
||||||||||||||||||||||||||||||||
| subprocess.run(["git", "checkout", "-B", branch_name], check=True, capture_output=True, text=True) | ||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||
| logger.debug(f"Branch '{branch_name}' checked out successfully.") | ||||||||||||||||||||||||||||||||
| logger.debug(f"Successfully checked out branch '{branch_name}'") | ||||||||||||||||||||||||||||||||
| return f"Successfully created and checked out branch '{branch_name}'" | ||||||||||||||||||||||||||||||||
| except subprocess.CalledProcessError as e: | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Add remediation hint to the error message.
The error message returned on validation failure lacks a remediation hint explaining how to fix the invalid branch name. As per coding guidelines, error messages must include remediation hints to improve debugging and user experience.
Consider adding guidance such as valid branch naming rules or a reference to git documentation.
📝 Suggested improvement
As per coding guidelines, error messages must include remediation hints and propagate context for debugging.
🧰 Tools
🪛 ast-grep (0.43.0)
[error] 24-24: Command coming from incoming request
Context: subprocess.run(["git", "checkout", "-B", branch_name], check=True, capture_output=True, text=True)
Note: [CWE-20].
(subprocess-from-request)
🤖 Prompt for AI Agents
Source: Coding guidelines