Skip to content

Conversation

@jayhack
Copy link
Contributor

@jayhack jayhack commented Aug 15, 2025

Motivation

Content

Testing

Please check the following before marking your PR as ready for review

  • I have added tests for my changes
  • I have updated the documentation or added new documentation as needed

@jayhack jayhack requested review from a team and codegen-team as code owners August 15, 2025 04:12
@codecov
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

❌ Patch coverage is 3.82166% with 151 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/codegen/cli/commands/agent/main.py 3.82% 151 Missing ⚠️

@jayhack jayhack merged commit 81c9e7b into develop Aug 15, 2025
18 checks passed
@jayhack jayhack deleted the jay/codegen-pull-command branch August 15, 2025 04:14
from codegen.cli.rich.spinners import create_spinner
from codegen.cli.utils.org import resolve_org_id
from codegen.git.repo_operator.local_git_repo import LocalGitRepo
from codegen.git.repo_operator.repo_operator import RepoOperator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax error: API_ENDPOINT is used but not imported
This will raise a NameError at runtime when pull() accesses API_ENDPOINT.

Suggested change
from codegen.git.repo_operator.repo_operator import RepoOperator
from codegen.cli.api.endpoints import API_ENDPOINT

except requests.RequestException as e:
console.print(f"[red]Error fetching agent run:[/red] {e}")
raise typer.Exit(1)
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic bug: argument position mismatch for typer.Option in pull
The pull function defines agent_id as --id but positional argument agent_id is also required when calling pull() internally.

Suggested change
except Exception as e:
agent_id: int = typer.Argument(..., help="Agent run ID to pull PR branch for"),

# Check if agent run has PRs
github_prs = agent_data.get("github_pull_requests", [])
if not github_prs:
console.print(f"[yellow]Warning:[/yellow] Agent run {agent_id} has no associated pull requests.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security issue: unsanitized external URL usage in GitHub API call
github_api_url is built directly from owner and repo extracted from the PR URL; malicious repo names could lead to SSRF.

Suggested change
console.print(f"[yellow]Warning:[/yellow] Agent run {agent_id} has no associated pull requests.")
from urllib.parse import quote_plus
owner = quote_plus(owner)
repo = quote_plus(repo)
github_api_url = f"https://api.github.com/repos/{owner}/{repo}/pulls/{pr_number}" # safe URL encoding

head_branch_name = pr_data.get("head", {}).get("ref")
if head_branch_name:
console.print(f"[green]✓ Found branch name from GitHub API:[/green] {head_branch_name}")
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic error: Fetching remote before validating branch existence maybe unnecessary; but main issue: resetting existing local branch is not implemented
checkout_remote_branch will fail if local branch exists and diverged; you already warn but don't reset.

Suggested change
else:
if head_branch_name in local_branches:
repo_operator.git_cli.git('reset', '--hard', f'origin/{head_branch_name}')
else:
repo_operator.checkout_remote_branch(head_branch_name)

@codegen-sh
Copy link
Contributor

codegen-sh bot commented Aug 15, 2025

Found 4 issues. Please review my inline comments above.

🔍 View my analysis

@github-actions
Copy link
Contributor

🎉 This PR is included in version 0.56.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants