Skip to content

fix: sync batch should not trigger some PR post-sync events#85

Merged
waltergalvao merged 1 commit intomainfrom
fix/sync-batch-actions
Feb 21, 2026
Merged

fix: sync batch should not trigger some PR post-sync events#85
waltergalvao merged 1 commit intomainfrom
fix/sync-batch-actions

Conversation

@waltergalvao
Copy link
Copy Markdown
Contributor

@waltergalvao waltergalvao commented Feb 21, 2026

Greptile Summary

Refactored the PR sync worker to conditionally skip certain automation jobs when processing PRs as part of a batch sync operation. The code extracts post-sync actions into a separate handlePostSyncActions function that checks for the presence of syncBatchId and skips AUTOMATION_PR_SIZE_LABELER and ALERT_MERGED_WITHOUT_APPROVAL jobs during batch syncs.

Key changes:

  • Extracted inline post-sync logic into handlePostSyncActions function for better code organization
  • Added conditional logic to skip AUTOMATION_PR_SIZE_LABELER when syncBatchId is present
  • Added conditional logic to skip ALERT_MERGED_WITHOUT_APPROVAL when syncBatchId is present
  • Added DataIntegrityException for missing installation ID in post-sync actions
  • Created JobData type alias to simplify type annotations

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring improves code organization and correctly implements the conditional logic to prevent redundant automation jobs during batch syncs. The changes are well-structured, maintain backward compatibility, and add appropriate error handling.
  • No files require special attention

Important Files Changed

Filename Overview
apps/api/src/app/github/workers/github-sync-pull-request.worker.ts Refactored post-sync actions into a separate function with conditional logic to skip certain automation jobs during batch sync operations

Last reviewed commit: daf76c1

@sweetr-dev sweetr-dev Bot added the small Small PR - Quick and easy to review label Feb 21, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 21, 2026

Walkthrough

Refactors the GitHub sync pull request worker to use strongly-typed JobData, introduces a handlePostSyncActions helper function, adds node_id validation, implements DataIntegrityException for critical errors, and adjusts control flow based on syncBatchId presence.

Changes

Cohort / File(s) Summary
Worker Refactoring & Type System
apps/api/src/app/github/workers/github-sync-pull-request.worker.ts
Introduces strongly-typed JobData payload replacing union types. Adds handlePostSyncActions helper encapsulating post-sync job logic (code review, size-labeler, merged-alert, deployment-trigger). Implements DataIntegrityException for missing-installation scenarios. Enhances validation with node_id check. Adjusts control flow to skip size-labeler and merged-alert when syncBatchId is present. Updates imports to include DataIntegrityException and PullRequest type.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

medium

Suggested reviewers

  • sweetrdev
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The pull request has no description provided by the author, making it impossible to assess the intent or scope of changes. Add a pull request description explaining the changes, why they are needed, and how they address the sync batch issue mentioned in the title.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: preventing certain PR post-sync events from being triggered during batch sync operations, which aligns with the refactoring that adds conditional logic based on syncBatchId.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/sync-batch-actions

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@waltergalvao waltergalvao merged commit 39094b6 into main Feb 21, 2026
9 of 10 checks passed
Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
apps/api/src/app/github/workers/github-sync-pull-request.worker.ts (1)

73-85: Redundant installationId guard, and helper defined after its call site.

Two minor points:

  1. handlePostSyncActions is a const defined at line 73 but referenced at line 67 inside the worker callback. This is safe at runtime (the module is fully initialised before any job is processed), but it is unconventional — hoisting the helper above syncPullRequestWorker is the standard ordering and easier to follow.

  2. The installationId null-check at lines 80-85 is unreachable from the current call path: installation.id is already validated at lines 29-34, and the worker throws before ever calling this helper. The guard is only meaningful if handlePostSyncActions is called from a future site that skips the worker-level validation. A brief comment (// defensive: called from contexts that may not pre-validate) or removing it would clarify intent.

♻️ Suggested ordering fix
-export const syncPullRequestWorker = createWorker(
-  SweetQueue.GITHUB_SYNC_PULL_REQUEST,
-  async (job: Job<JobData>, token?: string) => {
-    ...
-    if (pullRequest) {
-      await handlePostSyncActions(job.data, pullRequest);
-    }
-  },
-  { limiter: { max: 8, duration: 1000 } }
-);
-
 const handlePostSyncActions = async (
   jobData: JobData,
   pullRequest: PullRequest
 ) => {
   ...
 };
+
+export const syncPullRequestWorker = createWorker(
+  SweetQueue.GITHUB_SYNC_PULL_REQUEST,
+  async (job: Job<JobData>, token?: string) => {
+    ...
+    if (pullRequest) {
+      await handlePostSyncActions(job.data, pullRequest);
+    }
+  },
+  { limiter: { max: 8, duration: 1000 } }
+);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/api/src/app/github/workers/github-sync-pull-request.worker.ts` around
lines 73 - 85, Move the helper handlePostSyncActions above syncPullRequestWorker
to follow conventional ordering and improve readability, and then remove the
redundant runtime guard that throws when installationId is missing (the worker
already validates installation.id before calling this helper); if you want to
retain a safety note instead of removing the check, replace the throw with a
short defensive comment like "// defensive: called from contexts that may not
pre-validate" next to the installationId extraction (jobData.installation?.id)
so intent is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/api/src/app/github/workers/github-sync-pull-request.worker.ts`:
- Around line 73-85: Move the helper handlePostSyncActions above
syncPullRequestWorker to follow conventional ordering and improve readability,
and then remove the redundant runtime guard that throws when installationId is
missing (the worker already validates installation.id before calling this
helper); if you want to retain a safety note instead of removing the check,
replace the throw with a short defensive comment like "// defensive: called from
contexts that may not pre-validate" next to the installationId extraction
(jobData.installation?.id) so intent is clear.

@waltergalvao waltergalvao deleted the fix/sync-batch-actions branch March 15, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

small Small PR - Quick and easy to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants