Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
claude/adoring-hopper-5x74bqclaude/affectionate-feynman-ykrf1hclaude/architecture-audit-design-wxprenclaude/build-status-update-3MXsfclaude/charming-meitner-mllb5rclaude/compare-gate-gluecron-s4mFQclaude/confident-faraday-tikcwbclaude/continue-work-XMTlIclaude/crontech-gluecron-deploy-7MIECclaude/crontech-platform-setup-SeKfwclaude/design-2026claude/ecstatic-ptolemy-jMdigclaude/enhance-github-integration-QNHdGclaude/fix-aa-loop-issue-PonMQclaude/fix-actions-and-processclaude/fix-desktop-errors-XqoW8claude/fix-red-workflowsclaude/fix-website-access-6FKJNclaude/gatetest-integration-hardeningclaude/github-audit-improvements-bDFr9claude/gluecron-launch-status-FoMRlclaude/hopeful-lamport-olfCTclaude/issue-to-pr-and-protectionsclaude/jolly-heisenberg-2sg1Qclaude/launch-preparation-QmTb6claude/new-session-xk1l7claude/plan-platform-architecture-kkN4yclaude/platform-analysis-roadmap-1nUGLclaude/platform-launch-assessment-8dWV8claude/polish-platform-release-AeDrUclaude/resume-previous-work-KzyLwclaude/review-crontech-handoff-qYEVqclaude/review-project-completeness-lHhS2claude/review-readme-docs-ulqPKclaude/serene-edison-rj87weclaude/setup-multi-repo-dev-BCwNQclaude/ship-fixes-and-tests-Jvz1cclaude/site-audit-competitive-pctlwgclaude/site-migration-vercel-XstpKclaude/standalone-product-repos-XHFTDcopilot/feat-smart-empty-states-keyboard-first-enhancementcopilot/feat-smart-morning-digest-review-context-restorecopilot/fix-and-process-workflowscopilot/update-ai-powered-code-reviewfeat/debt-mapfeat/push-policy-codeowners-hardeningfeat/smart-digest-contextfeat/stage-impactfeat/t1-secret-migrationfeat/u-polishfeat/w-self-hostfeat/w2-claude-configfix/agent-journey-orphan-sweepgatetest/auto-fix-1776586424172gatetest/auto-fix-1776586534814gatetest/auto-fix-1776590685143gatetest/auto-fix-1776590808199mainops/redeploy-retriggerstyle/dxt-cta-themeworktree-agent-a3377aad30d55da26worktree-agent-a7ef607b7ee1d6c74
migrations.tsx12.2 KB · 363 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/**
 * Migration history — tracks repos imported from GitHub (bulk org import + single
 * repo import) and lets owners re-run the post-migration verifier on demand.
 *
 * The `repositories` table does NOT currently carry an `importedAt` /
 * `importSource` / `mirrorUpstreamUrl` column (see `src/db/schema.ts`), so
 * we fall back to a best-effort derivation: list every repo owned by the
 * current user and surface `createdAt` as the "imported at" timestamp. When
 * the schema eventually grows an `importedAt` column we can switch the
 * filter to `isNotNull(repositories.importedAt)` without changing the UI.
 *
 * The verifier itself lives in `src/lib/import-verify.ts` and is being
 * supplied by a parallel agent. We load it via dynamic import inside a
 * try/catch so a missing module produces a helpful "verifier not available"
 * note instead of a 500.
 */

import { Hono } from "hono";
import { desc, eq } from "drizzle-orm";
import { db } from "../db";
import { repositories } from "../db/schema";
import { Layout } from "../views/layout";
import { formatRelative } from "../views/ui";
import { requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";

const migrations = new Hono<AuthEnv>();

migrations.use("/migrations", requireAuth);
migrations.use("/migrations/*", requireAuth);

// ─── Verifier loader ─────────────────────────────────────────
//
// The verifier is optional at app boot — a parallel agent owns the file.
// We load it dynamically so this route works whether or not the module
// is present on disk. The expected interface is:
//
//   export async function verifyMigration(repoId: number): Promise<{
//     repoId: number;
//     clonable: boolean;
//     hasDefaultBranch: boolean;
//     commitCount: number;
//     issues: string[];
//   }>
//
type VerifyResult = {
  repoId: number;
  clonable: boolean;
  hasDefaultBranch: boolean;
  commitCount: number;
  issues: string[];
};

async function loadVerifier(): Promise<
  ((repoId: number) => Promise<VerifyResult>) | null
> {
  try {
    // eslint-disable-next-line @typescript-eslint/no-var-requires
    const mod: any = await import("../lib/import-verify");
    if (mod && typeof mod.verifyMigration === "function") {
      return mod.verifyMigration as (id: number) => Promise<VerifyResult>;
    }
    return null;
  } catch {
    return null;
  }
}

// ─── GET /migrations ─────────────────────────────────────────
migrations.get("/migrations", async (c) => {
  const user = c.get("user")!;

  // Best-effort listing: all repos owned by the user, newest first.
  // When an `importedAt` column is added later, narrow this WHERE to
  // `and(eq(ownerId, user.id), isNotNull(importedAt))`.
  let rows: Array<{
    id: string;
    name: string;
    createdAt: Date;
    description: string | null;
  }> = [];
  try {
    const result = await db
      .select({
        id: repositories.id,
        name: repositories.name,
        createdAt: repositories.createdAt,
        description: repositories.description,
      })
      .from(repositories)
      .where(eq(repositories.ownerId, user.id))
      .orderBy(desc(repositories.createdAt));
    rows = result as any;
  } catch {
    rows = [];
  }

  return c.html(
    <Layout title="Migration history" user={user}>
      <div style="max-width: 900px; margin: 0 auto; padding: 24px">
        <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:16px">
          <h1 style="margin:0">Migration history</h1>
          <div style="display:flex;gap:8px">
            <a class="btn" href="/import">
              Import
            </a>
            <a class="btn" href="/import/bulk">
              Bulk import
            </a>
          </div>
        </div>

        <p style="color: var(--text-muted); margin-bottom: 16px">
          Repositories you've migrated to gluecron. Use <strong>Verify</strong>
          {" "}to re-run the post-migration check (clonability, default branch,
          commit count).
        </p>

        {rows.length === 0 ? (
          <div class="panel-empty" style="padding: 32px; text-align: center">
            You haven't migrated any repos yet. Try{" "}
            <a href="/import">/import</a> or{" "}
            <a href="/import/bulk">/import/bulk</a>.
          </div>
        ) : (
          <div class="panel">
            <div
              class="panel-item"
              style="font-weight:600;background:var(--bg-subtle)"
            >
              <div style="flex:2;min-width:0">Repo</div>
              <div style="flex:2;min-width:0">Source</div>
              <div style="flex:1;min-width:0">Imported at</div>
              <div style="width:120px;text-align:right">Action</div>
            </div>
            {rows.map((r) => (
              <div class="panel-item">
                <div style="flex:2;min-width:0;overflow:hidden;text-overflow:ellipsis">
                  <a href={`/${user.username}/${r.name}`}>
                    <strong>{r.name}</strong>
                  </a>
                  {r.description && (
                    <div
                      style="font-size:12px;color:var(--text-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis"
                    >
                      {r.description}
                    </div>
                  )}
                </div>
                <div
                  style="flex:2;min-width:0;font-size:12px;color:var(--text-muted);font-family:var(--font-mono);overflow:hidden;text-overflow:ellipsis"
                >
                  {/* Source URL column — we don't persist the upstream URL
                      yet, so show a neutral placeholder. */}
                  —
                </div>
                <div style="flex:1;min-width:0;font-size:12px;color:var(--text-muted)">
                  {r.createdAt ? formatRelative(r.createdAt as unknown as string) : "—"}
                </div>
                <div style="width:120px;text-align:right">
                  <a
                    class="btn btn-primary"
                    href={`/migrations/verify/${r.id}`}
                  >
                    Verify
                  </a>
                </div>
              </div>
            ))}
          </div>
        )}
      </div>
    </Layout>
  );
});

// ─── GET /migrations/verify/:repoId ──────────────────────────
migrations.get("/migrations/verify/:repoId", async (c) => {
  const user = c.get("user")!;
  const repoId = c.req.param("repoId");

  // Ownership check: the verifier must only run for repos this user owns.
  let repo:
    | {
        id: string;
        name: string;
        ownerId: string;
        defaultBranch: string;
      }
    | null = null;
  try {
    const [row] = await db
      .select({
        id: repositories.id,
        name: repositories.name,
        ownerId: repositories.ownerId,
        defaultBranch: repositories.defaultBranch,
      })
      .from(repositories)
      .where(eq(repositories.id, repoId))
      .limit(1);
    repo = (row as any) || null;
  } catch {
    repo = null;
  }

  if (!repo) {
    return c.html(
      <Layout title="Verify migration" user={user}>
        <div style="max-width: 700px; margin: 0 auto; padding: 24px">
          <h1>Repository not found</h1>
          <p style="color:var(--text-muted)">
            <a href="/migrations">Back to migration history</a>
          </p>
        </div>
      </Layout>,
      404
    );
  }

  if (repo.ownerId !== user.id) {
    return c.html(
      <Layout title="Verify migration" user={user}>
        <div style="max-width: 700px; margin: 0 auto; padding: 24px">
          <h1>Forbidden</h1>
          <p style="color:var(--text-muted)">
            You can only verify repositories you own.
          </p>
          <p>
            <a href="/migrations">Back to migration history</a>
          </p>
        </div>
      </Layout>,
      403
    );
  }

  const verify = await loadVerifier();
  let result: VerifyResult | null = null;
  let verifierError: string | null = null;
  if (!verify) {
    verifierError =
      "Verifier not available. The import-verify module is not installed yet.";
  } else {
    try {
      // Schema stores repo id as uuid string; the verifier interface
      // types it as `number` but many callers pass through strings. Cast
      // defensively so we don't crash on either shape.
      result = await verify(repo.id as unknown as number);
    } catch (err: any) {
      verifierError =
        "Verifier failed: " + (err && err.message ? err.message : String(err));
    }
  }

  const indicator = (ok: boolean) => (
    <span
      style={`display:inline-block;width:10px;height:10px;border-radius:50%;margin-right:6px;background:${
        ok ? "var(--green, #2ea043)" : "var(--red, #f85149)"
      }`}
    />
  );

  return c.html(
    <Layout title={`Verify ${repo.name}`} user={user}>
      <div style="max-width: 700px; margin: 0 auto; padding: 24px">
        <div style="margin-bottom: 12px">
          <a href="/migrations" style="font-size:12px">
            ← Migration history
          </a>
        </div>
        <h1 style="margin:0 0 4px 0">Verify migration</h1>
        <div style="color:var(--text-muted);font-family:var(--font-mono);margin-bottom:16px">
          {user.username}/{repo.name}
        </div>

        {verifierError && (
          <div
            class="panel-empty"
            style="padding:16px;border-left:3px solid var(--red, #f85149)"
          >
            {verifierError}
          </div>
        )}

        {result && (
          <div class="panel">
            <div class="panel-item">
              <div style="flex:1">
                {indicator(result.clonable)}
                <strong>Clonable</strong>
              </div>
              <div style="color:var(--text-muted);font-size:12px">
                {result.clonable ? "Repository responds to git clone" : "Clone failed"}
              </div>
            </div>
            <div class="panel-item">
              <div style="flex:1">
                {indicator(result.hasDefaultBranch)}
                <strong>Default branch</strong>
              </div>
              <div style="color:var(--text-muted);font-size:12px">
                {result.hasDefaultBranch
                  ? `Found ${repo.defaultBranch}`
                  : `Missing ${repo.defaultBranch}`}
              </div>
            </div>
            <div class="panel-item">
              <div style="flex:1">
                {indicator(result.commitCount > 0)}
                <strong>Commits</strong>
              </div>
              <div style="color:var(--text-muted);font-size:12px">
                {result.commitCount} commit
                {result.commitCount === 1 ? "" : "s"}
              </div>
            </div>
            {result.issues && result.issues.length > 0 && (
              <div
                class="panel-item"
                style="flex-direction:column;align-items:stretch;gap:4px"
              >
                <div>
                  {indicator(false)}
                  <strong>Issues</strong>
                </div>
                <ul style="margin:0;padding-left:20px;color:var(--text-muted);font-size:13px">
                  {result.issues.map((i) => (
                    <li>{i}</li>
                  ))}
                </ul>
              </div>
            )}
            {(!result.issues || result.issues.length === 0) &&
              result.clonable &&
              result.hasDefaultBranch &&
              result.commitCount > 0 && (
                <div class="panel-item">
                  <div style="flex:1;color:var(--green, #2ea043)">
                    All checks passed.
                  </div>
                </div>
              )}
          </div>
        )}

        <div style="margin-top:16px;display:flex;gap:8px">
          <a
            class="btn btn-primary"
            href={`/migrations/verify/${repo.id}`}
          >
            Re-run verification
          </a>
          <a class="btn" href="/migrations">
            Back
          </a>
        </div>
      </div>
    </Layout>
  );
});

export default migrations;