Skip to content

agent: @U0AJM7X8FBR Slack Action: Merge test to main in the slack client in the#279

Merged
recoup-coding-agent merged 2 commits intotestfrom
agent/-u0ajm7x8fbr-slack-action--mer-1773153587086
Mar 10, 2026
Merged

agent: @U0AJM7X8FBR Slack Action: Merge test to main in the slack client in the#279
recoup-coding-agent merged 2 commits intotestfrom
agent/-u0ajm7x8fbr-slack-action--mer-1773153587086

Conversation

@sweetmantech
Copy link
Contributor

@sweetmantech sweetmantech commented Mar 10, 2026

Automated PR from coding agent.

Summary by CodeRabbit

  • New Features
    • Added ability to merge repository's test branch into main with a dedicated action button.
    • Automatically suggests merging test to main after a PR is successfully merged to the test branch.

@vercel
Copy link
Contributor

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Mar 10, 2026 3:51pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66e95747-d3a4-4fd6-9d09-540bde9cb7e8

📥 Commits

Reviewing files that changed from the base of the PR and between ad471ec and d75f342.

⛔ Files ignored due to path filters (2)
  • lib/coding-agent/__tests__/onMergeTestToMainAction.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/coding-agent/__tests__/parseMergeTestToMainActionId.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (2)
  • lib/coding-agent/handlers/onMergeTestToMainAction.ts
  • lib/coding-agent/parseMergeTestToMainActionId.ts
📝 Walkthrough

Walkthrough

This PR introduces a complete "Merge test to main" workflow by adding a card builder, GitHub branch merge utility, action handler, and integrating it into the existing merge action flow. The implementation includes validation, GitHub API integration, and user-facing feedback messages.

Changes

Cohort / File(s) Summary
UI Card Builder
lib/coding-agent/buildMergeTestToMainCard.ts
Creates a new Card component prompting users to merge test branch into main, composing title, descriptive text, and a primary action button with repo-specific labeling.
Handler Registration & Merge Action Extension
lib/coding-agent/handlers/registerHandlers.ts, lib/coding-agent/handlers/onMergeAction.ts
Registers the new merge test-to-main action handler and extends post-merge behavior to post the "Merge test to main" card when a PR targeting the test branch is merged.
Merge Test-to-Main Action Handler
lib/coding-agent/handlers/onMergeTestToMainAction.ts
Implements action ID parsing and handler registration for the "merge_test_to_main:" action, validating input, reading GitHub credentials, invoking the branch merge operation, and posting success/failure feedback.
GitHub Branch Merge Utility
lib/coding-agent/mergeGithubBranch.ts
Provides a discriminated union return type and async function to perform GitHub API-based branch merges, including error handling and structured result propagation.

Sequence Diagram

sequenceDiagram
    participant User as User
    participant Bot as Coding Agent Bot
    participant Handler as Merge Handler
    participant GitHub as GitHub API
    participant Thread as Chat Thread

    User->>Bot: Click "Merge test → main" button
    Bot->>Handler: Trigger merge_test_to_main action
    Handler->>Handler: Validate & parse action ID
    Handler->>Handler: Retrieve GITHUB_TOKEN
    Handler->>GitHub: POST /repos/{owner}/{repo}/merges
    GitHub-->>Handler: Success response (ok)
    Handler->>Thread: Post success message
    Thread-->>User: Display "Test → Main merge successful!"
    
    Note over Handler,GitHub: On failure path:
    GitHub-->>Handler: Error response
    Handler->>Thread: Post error message with details
    Thread-->>User: Display failure notification
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

Poem

🌿 From test to main, the branches dance,
A card appears—a gentle prompt,
GitHub's API hears the chance,
To merge with grace, no stone unturned,
Where clean workflows have earned their keep. 🚀

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Solid & Clean Code ⚠️ Warning Pull request violates clean code and SOLID principles with unprotected JSON.parse() call and duplicated GITHUB_TOKEN validation logic across multiple handlers. Wrap JSON.parse() in try-catch, extract GITHUB_TOKEN validation into reusable helper function, and centralize environment variable access pattern.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch agent/-u0ajm7x8fbr-slack-action--mer-1773153587086

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sweetmantech sweetmantech force-pushed the agent/-u0ajm7x8fbr-slack-action--mer-1773153587086 branch from c4dc579 to ad471ec Compare March 10, 2026 15:39
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
lib/coding-agent/handlers/onMergeTestToMainAction.ts (1)

8-13: Consider extracting parser to separate file for SRP compliance.

Per coding guidelines, each file should have one exported function. This file exports both parseMergeTestToMainActionId and registerOnMergeTestToMainAction.

However, I see this follows the pattern established with parseMergeActionId being in its own file while onMergeAction.ts imports it. For consistency, consider moving parseMergeTestToMainActionId to lib/coding-agent/parseMergeTestToMainActionId.ts.

That said, the tight coupling makes co-location pragmatic—this is a minor nit.

♻️ Optional: Extract parser to separate file

Create lib/coding-agent/parseMergeTestToMainActionId.ts:

/**
 * Parses a merge_test_to_main action ID like "merge_test_to_main:recoupable/api"
 * into the repo string, or null if the format doesn't match.
 */
export function parseMergeTestToMainActionId(actionId: string): string | null {
  const prefix = "merge_test_to_main:";
  if (!actionId.startsWith(prefix)) return null;
  const repo = actionId.slice(prefix.length);
  return repo.includes("/") ? repo : null;
}

Then import it in onMergeTestToMainAction.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/coding-agent/handlers/onMergeTestToMainAction.ts` around lines 8 - 13,
Move the parser function out of onMergeTestToMainAction.ts into a new module
named lib/coding-agent/parseMergeTestToMainActionId.ts and export it there as
parseMergeTestToMainActionId, keeping the exact implementation; then update
lib/coding-agent/handlers/onMergeTestToMainAction.ts to import
parseMergeTestToMainActionId and leave registerOnMergeTestToMainAction as the
sole exported symbol in that file to satisfy SRP and match the
parseMergeActionId pattern used elsewhere.
lib/coding-agent/mergeGithubBranch.ts (1)

26-26: Consider defensive validation for malformed repo parameter.

While parseMergeTestToMainActionId validates the repo format upstream, this function could be called from other contexts. If repo doesn't contain "/", owner and repoName will be undefined or incorrect, leading to a confusing API error.

🛡️ Optional: Add defensive check
 ): Promise<MergeGithubBranchResult> {
   const [owner, repoName] = repo.split("/");
+  if (!owner || !repoName) {
+    return { ok: false, message: `Invalid repo format: ${repo}` };
+  }
   const response = await fetch(
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/coding-agent/mergeGithubBranch.ts` at line 26, The destructuring const
[owner, repoName] = repo.split("/") in mergeGithubBranch.ts can break if repo is
malformed; add a defensive validation before that line (within the
mergeGithubBranch function) to ensure repo is a non-empty string containing
exactly one "/" (e.g., check typeof repo === "string" and repo.split("/").length
=== 2 after trimming) and if invalid throw or return a clear error (include repo
value) so callers get a helpful message; reference parseMergeTestToMainActionId
to note upstream validation but still perform this local check for safety.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/coding-agent/mergeGithubBranch.ts`:
- Around line 49-54: The branch-merge error handler currently calls
JSON.parse(errorBody) without protection; wrap that parse in a try-catch inside
the mergeGithubBranch error handling block so non-JSON responses (HTML, proxy
pages, rate-limit text) don't throw; if JSON.parse succeeds extract
error.message, otherwise fall back to using the raw errorBody (or a generic
message) when returning { ok: false, message: ... } and ensure the process log
still includes the original errorBody; update the code around the existing
variables response, errorBody, and the return that builds the message
accordingly.

---

Nitpick comments:
In `@lib/coding-agent/handlers/onMergeTestToMainAction.ts`:
- Around line 8-13: Move the parser function out of onMergeTestToMainAction.ts
into a new module named lib/coding-agent/parseMergeTestToMainActionId.ts and
export it there as parseMergeTestToMainActionId, keeping the exact
implementation; then update lib/coding-agent/handlers/onMergeTestToMainAction.ts
to import parseMergeTestToMainActionId and leave registerOnMergeTestToMainAction
as the sole exported symbol in that file to satisfy SRP and match the
parseMergeActionId pattern used elsewhere.

In `@lib/coding-agent/mergeGithubBranch.ts`:
- Line 26: The destructuring const [owner, repoName] = repo.split("/") in
mergeGithubBranch.ts can break if repo is malformed; add a defensive validation
before that line (within the mergeGithubBranch function) to ensure repo is a
non-empty string containing exactly one "/" (e.g., check typeof repo ===
"string" and repo.split("/").length === 2 after trimming) and if invalid throw
or return a clear error (include repo value) so callers get a helpful message;
reference parseMergeTestToMainActionId to note upstream validation but still
perform this local check for safety.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c42e9190-5419-4af5-9972-309d1b484c97

📥 Commits

Reviewing files that changed from the base of the PR and between d54447d and ad471ec.

⛔ Files ignored due to path filters (2)
  • lib/coding-agent/__tests__/mergeGithubBranch.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
  • lib/coding-agent/__tests__/onMergeTestToMainAction.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (5)
  • lib/coding-agent/buildMergeTestToMainCard.ts
  • lib/coding-agent/handlers/onMergeAction.ts
  • lib/coding-agent/handlers/onMergeTestToMainAction.ts
  • lib/coding-agent/handlers/registerHandlers.ts
  • lib/coding-agent/mergeGithubBranch.ts

Comment on lines +49 to +54
const errorBody = await response.text();
console.error(
`[coding-agent] branch merge failed for ${repo} (${head} → ${base}): ${response.status} ${errorBody}`,
);
const error = JSON.parse(errorBody);
return { ok: false, message: error.message };
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Missing try-catch around JSON.parse can cause unhandled exceptions.

If the GitHub API returns a non-JSON response (e.g., HTML error page during outage, proxy errors, or rate-limit pages), JSON.parse(errorBody) will throw a SyntaxError, crashing the handler and leaving the user without feedback.

🐛 Proposed fix with fallback for non-JSON responses
   const errorBody = await response.text();
   console.error(
     `[coding-agent] branch merge failed for ${repo} (${head} → ${base}): ${response.status} ${errorBody}`,
   );
-  const error = JSON.parse(errorBody);
-  return { ok: false, message: error.message };
+  try {
+    const error = JSON.parse(errorBody);
+    return { ok: false, message: error.message ?? errorBody };
+  } catch {
+    return { ok: false, message: `GitHub API error: ${response.status}` };
+  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/coding-agent/mergeGithubBranch.ts` around lines 49 - 54, The branch-merge
error handler currently calls JSON.parse(errorBody) without protection; wrap
that parse in a try-catch inside the mergeGithubBranch error handling block so
non-JSON responses (HTML, proxy pages, rate-limit text) don't throw; if
JSON.parse succeeds extract error.message, otherwise fall back to using the raw
errorBody (or a generic message) when returning { ok: false, message: ... } and
ensure the process log still includes the original errorBody; update the code
around the existing variables response, errorBody, and the return that builds
the message accordingly.

@recoup-coding-agent recoup-coding-agent merged commit ff15919 into test Mar 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants