fix(sync): honor per-spoon auto-sync settings
This commit is contained in:
@@ -190,7 +190,7 @@ export const createForkSpoonRecord = internalMutation({
|
||||
ownerId: args.ownerId,
|
||||
autoRefreshEnabled: true,
|
||||
autoReviewEnabled: true,
|
||||
autoSyncEnabled: false,
|
||||
autoSyncEnabled: true,
|
||||
requireAiLowRiskForSync: true,
|
||||
requireCleanCompareForSync: true,
|
||||
ignoredFilePatterns: [],
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
listPullRequests,
|
||||
syncForkBranch,
|
||||
} from './githubClient';
|
||||
import { shouldAutoSync, shouldCreateReviewThread } from './syncGating';
|
||||
|
||||
const getRequiredUserId = async (ctx: ActionCtx) => {
|
||||
const userId = await getAuthUserId(ctx);
|
||||
@@ -69,6 +70,16 @@ const refreshOwnedSpoon = async (
|
||||
'GitHub refresh is only available for GitHub Spoons.',
|
||||
);
|
||||
}
|
||||
const settings = await ctx.runQuery(internal.spoonSettings.getInternal, {
|
||||
spoonId,
|
||||
ownerId,
|
||||
});
|
||||
const autoSyncEnabled = settings?.autoSyncEnabled ?? false;
|
||||
const autoReviewEnabled = settings?.autoReviewEnabled ?? true;
|
||||
const requireCleanCompareForSync =
|
||||
settings?.requireCleanCompareForSync ?? true;
|
||||
// requireAiLowRiskForSync applies to the future AI review-to-auto-merge path,
|
||||
// which is deliberately deferred until Phase 4.
|
||||
const connection = await ctx.runQuery(internal.github.getConnectionForUser, {
|
||||
userId: ownerId,
|
||||
});
|
||||
@@ -202,7 +213,13 @@ const refreshOwnedSpoon = async (
|
||||
summary: `GitHub refresh complete: ${upstreamCompare.aheadBy} upstream commit(s), ${forkCompare.aheadBy} fork-only commit(s).`,
|
||||
});
|
||||
|
||||
if (status === 'behind' && forkCompare.aheadBy === 0 && allowAutoSync) {
|
||||
if (
|
||||
allowAutoSync &&
|
||||
shouldAutoSync(
|
||||
{ autoSyncEnabled, requireCleanCompareForSync },
|
||||
{ status, forkAheadBy: forkCompare.aheadBy },
|
||||
)
|
||||
) {
|
||||
try {
|
||||
await syncForkBranch(octokit, {
|
||||
forkOwner,
|
||||
@@ -258,7 +275,7 @@ const refreshOwnedSpoon = async (
|
||||
}
|
||||
}
|
||||
|
||||
if (status === 'diverged') {
|
||||
if (shouldCreateReviewThread({ autoReviewEnabled }, { status })) {
|
||||
const threadId = await ctx.runMutation(
|
||||
internal.threads.createMaintenanceThread,
|
||||
{
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { v } from 'convex/values';
|
||||
|
||||
import { internalMutation } from './_generated/server';
|
||||
|
||||
// One-shot backfill: preserve existing automatic fast-forward behavior for
|
||||
// GitHub spoons now that refreshes honor autoSyncEnabled. Idempotent.
|
||||
export const backfillAutoSyncDefaults = internalMutation({
|
||||
args: {},
|
||||
returns: v.object({ updated: v.number() }),
|
||||
handler: async (ctx) => {
|
||||
const settings = await ctx.db.query('spoonSettings').collect();
|
||||
let updated = 0;
|
||||
for (const row of settings) {
|
||||
if (row.autoSyncEnabled) continue;
|
||||
const spoon = await ctx.db.get(row.spoonId);
|
||||
if (spoon?.provider !== 'github') continue;
|
||||
await ctx.db.patch(row._id, {
|
||||
autoSyncEnabled: true,
|
||||
updatedAt: Date.now(),
|
||||
});
|
||||
updated += 1;
|
||||
}
|
||||
return { updated };
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
export const shouldAutoSync = (
|
||||
settings: {
|
||||
autoSyncEnabled: boolean;
|
||||
requireCleanCompareForSync: boolean;
|
||||
},
|
||||
ctx: { status: string; forkAheadBy: number },
|
||||
): boolean => {
|
||||
if (!settings.autoSyncEnabled) return false;
|
||||
if (ctx.status !== 'behind') return false;
|
||||
if (settings.requireCleanCompareForSync && ctx.forkAheadBy !== 0) {
|
||||
return false;
|
||||
}
|
||||
return ctx.forkAheadBy === 0;
|
||||
};
|
||||
|
||||
export const shouldCreateReviewThread = (
|
||||
settings: { autoReviewEnabled: boolean },
|
||||
ctx: { status: string },
|
||||
): boolean => settings.autoReviewEnabled && ctx.status === 'diverged';
|
||||
Reference in New Issue
Block a user