Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/app/api/sync/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { syncIssuesForRepos, mergeLabels } from "@/lib/issue-sync";
import { authorizeRequest } from "@/lib/auth";
import { acquireLock, releaseLock } from "@/lib/sync-lock";

// Sync must see closed issues, or closedIssueStatusFix never runs: the
// closed=>done enforcement (#521) only applies to issues in the fetch set,
// and the default fetch is state=open. Regressed to open-only when the
// heartbeat cron (whose reconcile did its own closed fetch) was retired.
const fetchAllStateIssues = (repoFullName: string) => fetchIssues(repoFullName, { includeClosed: true });


export async function POST(request: NextRequest) {
if (!(await authorizeRequest(request)).authorized) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
Expand Down Expand Up @@ -48,7 +55,7 @@ export async function POST(request: NextRequest) {

try {
const excludedLabels = parseExcludedLabels(process.env.DISPATCH_EXCLUDED_LABELS);
const result = await syncIssuesForRepos(repos, fetchIssues, {
const result = await syncIssuesForRepos(repos, fetchAllStateIssues, {
findIssue(repositoryId, number) {
return prisma.issue.findUnique({
where: { repositoryId_number: { repositoryId, number } },
Expand Down
7 changes: 7 additions & 0 deletions src/app/api/sync/scheduled/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,13 @@ describe("POST /api/sync/scheduled — sync behavior", () => {
expect(body.issues.repos).toBe(1);
});

it("fetches closed issues too, so closed=>done enforcement can run (#521 regression)", async () => {
const { POST } = await import("./route");
const github = await import("@/lib/github");
await POST(makeRequest());
expect(github.fetchIssues).toHaveBeenCalledWith(expect.any(String), { includeClosed: true });
});

it("does not sync automation by default", async () => {
const { POST } = await import("./route");
const res = await POST(makeRequest());
Expand Down
9 changes: 8 additions & 1 deletion src/app/api/sync/scheduled/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import { syncIssuesForRepos, reconcileClosedIssues, SyncResponse, ClosedIssueRec
import { authorizeRequest } from "@/lib/auth";
import { acquireLock, releaseLock } from "@/lib/sync-lock";

// Sync must see closed issues, or closedIssueStatusFix never runs: the
// closed=>done enforcement (#521) only applies to issues in the fetch set,
// and the default fetch is state=open. Regressed to open-only when the
// heartbeat cron (whose reconcile did its own closed fetch) was retired.
const fetchAllStateIssues = (repoFullName: string) => fetchIssues(repoFullName, { includeClosed: true });


// ---------------------------------------------------------------------------
// Route handlers
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -52,7 +59,7 @@ export async function POST(request: Request) {
if (syncIssues) {
const repos = await getSyncRepos();
const excludedLabels = parseExcludedLabels(process.env.DISPATCH_EXCLUDED_LABELS);
issueSync = await syncIssuesForRepos(repos, fetchIssues, {
issueSync = await syncIssuesForRepos(repos, fetchAllStateIssues, {
findIssue(repositoryId, number) {
return prisma.issue.findUnique({
where: { repositoryId_number: { repositoryId, number } },
Expand Down
9 changes: 8 additions & 1 deletion src/lib/heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import { prisma } from "@/lib/prisma";
import { fetchIssues, syncStatusLabels } from "@/lib/github";
import { getSyncRepos, parseExcludedLabels } from "@/lib/config";
import {

syncIssuesForRepos,
mergeLabels,
reconcileClosedIssues,
type SyncedIssueData,
type ClosedIssueReconcileResponse,
} from "@/lib/issue-sync";

// Sync must see closed issues, or closedIssueStatusFix never runs: the
// closed=>done enforcement (#521) only applies to issues in the fetch set,
// and the default fetch is state=open. Regressed to open-only when the
// heartbeat cron (whose reconcile did its own closed fetch) was retired.
const fetchAllStateIssues = (repoFullName: string) => fetchIssues(repoFullName, { includeClosed: true });

// ---------------------------------------------------------------------------
// Sync orchestration
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -54,7 +61,7 @@ export async function runSyncBestEffort(

const excludedLabels = opts?.excludedLabels ?? parseExcludedLabels(process.env.DISPATCH_EXCLUDED_LABELS);

const result = await syncIssuesForRepos(repos, fetchIssues, {
const result = await syncIssuesForRepos(repos, fetchAllStateIssues, {
findIssue(repositoryId: string, number: number) {
return prisma.issue.findUnique({
where: { repositoryId_number: { repositoryId, number } },
Expand Down