feat(agents): add pr and commit commands (4/8)#8283
Conversation
📝 WalkthroughWalkthroughThis PR adds two new CLI subcommands to the Netlify agents command: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
c6e77a5 to
3220465
Compare
e8fd223 to
7d3ac26
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/agents/agents-commit.ts`:
- Around line 85-93: The current success messaging in agents-commit.ts assumes a
completed commit whenever runner.merge_commit_error is falsy; update the logic
to first check runner.merge_commit_is_being_created and, if true, print an “in
progress” message instead of the success line (and avoid showing the SHA), only
printing the green "Committed to <branch>" and the SHA when
merge_commit_is_being_created is false and merge_commit_sha exists; similarly
ensure any caller/display logic that relies on
merge_commit_sha/merge_commit_error (e.g., agents-show.ts) treats
merge_commit_is_being_created as a separate in-progress state.
In `@src/commands/agents/agents-pr.ts`:
- Around line 33-43: The current success branch misreports a created PR when
AgentRunner indicates an in-progress creation; update the post-PR-handling in
agents-pr.ts to check runner.pr_is_being_created (and absence of
runner.pr_url/runner.pr_error) before logging “Pull request created!” — if
pr_is_being_created is true, log a clear in-progress message (e.g., “Pull
request is being created…”) and return runner early; otherwise continue to log
the created PR info (URL/Branch/State). Ensure you reference the
AgentRunner/runner object fields (runner.pr_is_being_created, runner.pr_url,
runner.pr_error, runner.pr_branch, runner.pr_state) so the conditional handles
async responses from agentRunnerPullRequest correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 68054664-b781-4687-b6f5-77c71c5fe39d
📒 Files selected for processing (7)
docs/commands/agents.mddocs/index.mdsrc/commands/agents/agents-commit.tssrc/commands/agents/agents-pr.tssrc/commands/agents/agents.tstests/integration/commands/agents/agents-commit.test.tstests/integration/commands/agents/agents-pr.test.ts
- agents:pr opens a pull request for the run's branch; refuses on projects without a git remote - agents:commit commits the run's changes, defaulting to runner.branch (or runner.pr_branch when a PR is already open); git-only Part 4/8 of the agents CLI revamp split.
3220465 to
35a38b9
Compare
7d3ac26 to
e4e146c
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/integration/commands/agents/agents-pr.test.ts (1)
148-159: ⚡ Quick winConsider covering the git-repo guard and 404 branches.
The suite exercises the API-success/error paths well, but two implementation branches in
agents-pr.tsremain untested:
- The
!siteInfo.build_settings?.repo_urlguard that refuses non-git-backed projects (an explicit PR objective: "Refuses on projects without a git remote").- The
error.status === 404→Agent run not found: ${id}mapping.Adding cases for these would lock in the documented behavior and prevent regressions in the error-mapping logic.
Want me to draft these two additional test cases?
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/integration/commands/agents/agents-pr.test.ts` around lines 148 - 159, Add two tests in tests/integration/commands/agents/agents-pr.test.ts: (1) a test that builds a site whose siteInfo lacks build_settings?.repo_url and calls callCli(['agents:pr', '<id>'], ...) expecting the CLI to reject with the guard message (referring to the non-git-backed project path in agents-pr.ts that checks siteInfo.build_settings?.repo_url); (2) a test that uses withMockApi to mock the agent run endpoint to return a 404 and then calls callCli(['agents:pr', id], ...) asserting the thrown error message equals "Agent run not found: <id>" (this covers the error.status === 404 mapping in agents-pr.ts). Ensure you use the same helpers present in the file (withSiteBuilder, withMockApi, getCLIOptions, callCli) and match the exact error strings produced by agents-pr.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/integration/commands/agents/agents-pr.test.ts`:
- Around line 148-159: Add two tests in
tests/integration/commands/agents/agents-pr.test.ts: (1) a test that builds a
site whose siteInfo lacks build_settings?.repo_url and calls
callCli(['agents:pr', '<id>'], ...) expecting the CLI to reject with the guard
message (referring to the non-git-backed project path in agents-pr.ts that
checks siteInfo.build_settings?.repo_url); (2) a test that uses withMockApi to
mock the agent run endpoint to return a 404 and then calls callCli(['agents:pr',
id], ...) asserting the thrown error message equals "Agent run not found: <id>"
(this covers the error.status === 404 mapping in agents-pr.ts). Ensure you use
the same helpers present in the file (withSiteBuilder, withMockApi,
getCLIOptions, callCli) and match the exact error strings produced by
agents-pr.ts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a3f64c8b-20b5-48f7-8099-15803285ad67
📒 Files selected for processing (7)
docs/commands/agents.mddocs/index.mdsrc/commands/agents/agents-commit.tssrc/commands/agents/agents-pr.tssrc/commands/agents/agents.tstests/integration/commands/agents/agents-commit.test.tstests/integration/commands/agents/agents-pr.test.ts
✅ Files skipped from review due to trivial changes (1)
- docs/index.md
🚧 Files skipped from review as they are similar to previous changes (3)
- src/commands/agents/agents.ts
- tests/integration/commands/agents/agents-commit.test.ts
- src/commands/agents/agents-pr.ts
|
Link EX-2195 |
Summary
Linear: https://linear.app/netlify/issue/EX-2195
Part 4 of the agents CLI revamp split. Adds two commands that push a run's work out through git.
agents:propens a pull request for the run's branch. Refuses on projects without a git remote.agents:commitcommits the run's changes, defaulting torunner.branch(orrunner.pr_branchwhen a PR is already open). Git-backed projects only.Stacked on the diff/open PR.
For us to review and ship your PR efficiently, please perform the following steps:
re fixing a typo or something thats on fire 🔥 (e.g. incident related), you can skip this step.passes our tests.