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
discussions.tsx20.9 KB · 674 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/**
 * Block E2 — Discussions: forum-style threaded conversations attached to a repo.
 *
 * Similar to GitHub Discussions: categorised, pinnable, answer-able threads
 * that sit alongside issues but are conversational (Q&A, ideas, announcements).
 *
 * Never throws — all DB paths wrapped in try/catch; callers see a 500-like
 * shell page or a redirect on any failure.
 */

import { Hono } from "hono";
import { and, eq, desc, sql } from "drizzle-orm";
import { db } from "../db";
import {
  discussions,
  discussionComments,
  repositories,
  users,
} from "../db/schema";
import { Layout } from "../views/layout";
import { RepoHeader, RepoNav } from "../views/components";
import { renderMarkdown } from "../lib/markdown";
import { softAuth, requireAuth } from "../middleware/auth";
import type { AuthEnv } from "../middleware/auth";

const CATEGORIES = [
  "general",
  "q-and-a",
  "ideas",
  "announcements",
  "show-and-tell",
] as const;

export function isValidCategory(c: string): boolean {
  return (CATEGORIES as readonly string[]).includes(c);
}

const discussionRoutes = new Hono<AuthEnv>();

async function resolveRepo(ownerName: string, repoName: string) {
  try {
    const [owner] = await db
      .select()
      .from(users)
      .where(eq(users.username, ownerName))
      .limit(1);
    if (!owner) return null;
    const [repo] = await db
      .select()
      .from(repositories)
      .where(
        and(
          eq(repositories.ownerId, owner.id),
          eq(repositories.name, repoName)
        )
      )
      .limit(1);
    if (!repo) return null;
    return { owner, repo };
  } catch {
    return null;
  }
}

function notFound(user: any, label = "Not found") {
  return (
    <Layout title={label} user={user}>
      <div class="empty-state">
        <h2>{label}</h2>
      </div>
    </Layout>
  );
}

// List
discussionRoutes.get("/:owner/:repo/discussions", softAuth, async (c) => {
  const { owner: ownerName, repo: repoName } = c.req.param();
  const user = c.get("user");
  const category = c.req.query("category") || "";

  const resolved = await resolveRepo(ownerName, repoName);
  if (!resolved) return c.html(notFound(user, "Repository not found"), 404);
  const { repo } = resolved;

  let rows: any[] = [];
  try {
    const whereClause =
      category && isValidCategory(category)
        ? and(
            eq(discussions.repositoryId, repo.id),
            eq(discussions.category, category)
          )
        : eq(discussions.repositoryId, repo.id);
    rows = await db
      .select({
        d: discussions,
        author: { username: users.username },
        commentCount: sql<number>`(SELECT count(*) FROM discussion_comments WHERE discussion_id = ${discussions.id})`,
      })
      .from(discussions)
      .innerJoin(users, eq(discussions.authorId, users.id))
      .where(whereClause)
      .orderBy(desc(discussions.pinned), desc(discussions.updatedAt));
  } catch {
    rows = [];
  }

  return c.html(
    <Layout title={`Discussions — ${ownerName}/${repoName}`} user={user}>
      <RepoHeader owner={ownerName} repo={repoName} />
      <div class="repo-nav">
        <a href={`/${ownerName}/${repoName}`}>Code</a>
        <a href={`/${ownerName}/${repoName}/issues`}>Issues</a>
        <a href={`/${ownerName}/${repoName}/pulls`}>Pull Requests</a>
        <a href={`/${ownerName}/${repoName}/discussions`} class="active">
          Discussions
        </a>
      </div>
      <div style="display: flex; justify-content: space-between; align-items: center; margin: 16px 0;">
        <div style="display: flex; gap: 8px;">
          <a
            href={`/${ownerName}/${repoName}/discussions`}
            class={!category ? "active" : ""}
            style="padding: 4px 10px; border-radius: 6px;"
          >
            All
          </a>
          {CATEGORIES.map((cat) => (
            <a
              href={`/${ownerName}/${repoName}/discussions?category=${cat}`}
              class={cat === category ? "active" : ""}
              style="padding: 4px 10px; border-radius: 6px;"
            >
              {cat}
            </a>
          ))}
        </div>
        {user && (
          <a
            href={`/${ownerName}/${repoName}/discussions/new`}
            class="btn btn-primary"
          >
            New discussion
          </a>
        )}
      </div>
      {rows.length === 0 ? (
        <div class="empty-state">
          <p>No discussions yet.</p>
        </div>
      ) : (
        <table class="file-table">
          <tbody>
            {rows.map((r) => (
              <tr>
                <td style="width: 40px; color: var(--text-muted);">
                  #{r.d.number}
                </td>
                <td>
                  {r.d.pinned && <span class="badge">📌 Pinned</span>}{" "}
                  <a
                    href={`/${ownerName}/${repoName}/discussions/${r.d.number}`}
                  >
                    <strong>{r.d.title}</strong>
                  </a>{" "}
                  <span class="badge">{r.d.category}</span>
                  <div style="font-size: 12px; color: var(--text-muted); margin-top: 2px;">
                    by @{r.author.username}
                    {r.d.state === "closed" ? " · closed" : ""}
                    {r.d.locked ? " · locked" : ""}
                  </div>
                </td>
                <td style="text-align: right; color: var(--text-muted); font-size: 13px;">
                  💬 {r.commentCount}
                </td>
              </tr>
            ))}
          </tbody>
        </table>
      )}
    </Layout>
  );
});

// New discussion form
discussionRoutes.get(
  "/:owner/:repo/discussions/new",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user");
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.html(notFound(user, "Repository not found"), 404);
    return c.html(
      <Layout title="New discussion" user={user}>
        <RepoHeader owner={ownerName} repo={repoName} />
        <h2 style="margin-top: 20px;">Start a discussion</h2>
        <form
          method="POST"
          action={`/${ownerName}/${repoName}/discussions`}
          style="display: flex; flex-direction: column; gap: 12px; margin-top: 16px;"
        >
          <input
            type="text"
            name="title"
            placeholder="Title"
            required
            style="padding: 8px;"
          />
          <select name="category" style="padding: 8px;">
            {CATEGORIES.map((c) => (
              <option value={c}>{c}</option>
            ))}
          </select>
          <textarea
            name="body"
            rows={10}
            placeholder="Write your post (markdown supported)"
            style="padding: 8px; font-family: inherit;"
          ></textarea>
          <button type="submit" class="btn btn-primary">
            Start discussion
          </button>
        </form>
      </Layout>
    );
  }
);

// Create
discussionRoutes.post(
  "/:owner/:repo/discussions",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);

    const form = await c.req.formData();
    const title = (form.get("title") as string || "").trim();
    const body = (form.get("body") as string || "").trim();
    const categoryRaw = (form.get("category") as string || "general").trim();
    const category = isValidCategory(categoryRaw) ? categoryRaw : "general";

    if (!title) {
      return c.redirect(`/${ownerName}/${repoName}/discussions/new`);
    }

    try {
      const [row] = await db
        .insert(discussions)
        .values({
          repositoryId: resolved.repo.id,
          authorId: user.id,
          category,
          title,
          body,
        })
        .returning({ number: discussions.number });
      return c.redirect(
        `/${ownerName}/${repoName}/discussions/${row.number}`
      );
    } catch {
      return c.redirect(`/${ownerName}/${repoName}/discussions`);
    }
  }
);

// Detail
discussionRoutes.get(
  "/:owner/:repo/discussions/:number",
  softAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user");
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.html(notFound(user, "Repository not found"), 404);

    let discussion: any = null;
    let comments: any[] = [];
    try {
      const [row] = await db
        .select({ d: discussions, author: { username: users.username } })
        .from(discussions)
        .innerJoin(users, eq(discussions.authorId, users.id))
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (row) discussion = row;
      if (discussion) {
        comments = await db
          .select({
            c: discussionComments,
            author: { username: users.username },
          })
          .from(discussionComments)
          .innerJoin(users, eq(discussionComments.authorId, users.id))
          .where(eq(discussionComments.discussionId, discussion.d.id))
          .orderBy(discussionComments.createdAt);
      }
    } catch {
      // leave nulls
    }

    if (!discussion) return c.html(notFound(user, "Discussion not found"), 404);

    const isOwner = user && user.id === resolved.repo.ownerId;
    const isAuthor = user && user.id === discussion.d.authorId;
    const canModerate = isOwner || isAuthor;

    return c.html(
      <Layout
        title={`${discussion.d.title} · discussion #${discussion.d.number}`}
        user={user}
      >
        <RepoHeader owner={ownerName} repo={repoName} />
        <div style="margin-top: 16px;">
          <div style="display: flex; justify-content: space-between; align-items: center;">
            <h1 style="margin: 0;">
              {discussion.d.title}{" "}
              <span style="color: var(--text-muted);">
                #{discussion.d.number}
              </span>
            </h1>
            <div style="display: flex; gap: 8px;">
              <span class="badge">{discussion.d.category}</span>
              {discussion.d.state === "closed" && (
                <span class="badge">closed</span>
              )}
              {discussion.d.locked && <span class="badge">🔒 locked</span>}
              {discussion.d.pinned && <span class="badge">📌 pinned</span>}
            </div>
          </div>
          <div style="color: var(--text-muted); font-size: 13px; margin-top: 4px;">
            Started by @{discussion.author.username}
          </div>
        </div>
        <article class="comment" style="margin-top: 16px;">
          <div
            // biome-ignore lint: rendered server-side from trusted markdown
            dangerouslySetInnerHTML={{
              __html: renderMarkdown(discussion.d.body || ""),
            }}
          />
        </article>
        <h3 style="margin-top: 32px;">{comments.length} Comments</h3>
        {comments.map((com) => {
          const isAnswer = com.c.id === discussion.d.answerCommentId;
          return (
            <article
              class="comment"
              style={`margin-top: 12px; ${isAnswer ? "border: 2px solid var(--green); padding: 12px;" : ""}`}
            >
              <div style="display: flex; justify-content: space-between;">
                <div style="font-size: 13px; color: var(--text-muted);">
                  @{com.author.username}
                  {isAnswer && " · ✅ Answer"}
                </div>
                {isOwner &&
                  discussion.d.category === "q-and-a" &&
                  !isAnswer && (
                    <form
                      method="POST"
                      action={`/${ownerName}/${repoName}/discussions/${discussion.d.number}/answer/${com.c.id}`}
                      style="display: inline;"
                    >
                      <button type="submit" class="btn">
                        Mark as answer
                      </button>
                    </form>
                  )}
              </div>
              <div
                style="margin-top: 8px;"
                dangerouslySetInnerHTML={{
                  __html: renderMarkdown(com.c.body || ""),
                }}
              />
            </article>
          );
        })}
        {user && !discussion.d.locked && discussion.d.state === "open" && (
          <form
            method="POST"
            action={`/${ownerName}/${repoName}/discussions/${discussion.d.number}/comment`}
            style="margin-top: 24px; display: flex; flex-direction: column; gap: 8px;"
          >
            <textarea
              name="body"
              rows={5}
              placeholder="Add a comment (markdown supported)"
              required
              style="padding: 8px; font-family: inherit;"
            ></textarea>
            <button type="submit" class="btn btn-primary">
              Comment
            </button>
          </form>
        )}
        {user && (
          <div style="margin-top: 24px; display: flex; gap: 8px;">
            {canModerate && (
              <form
                method="POST"
                action={`/${ownerName}/${repoName}/discussions/${discussion.d.number}/close`}
                style="display: inline;"
              >
                <button type="submit" class="btn">
                  {discussion.d.state === "open" ? "Close" : "Reopen"}
                </button>
              </form>
            )}
            {isOwner && (
              <>
                <form
                  method="POST"
                  action={`/${ownerName}/${repoName}/discussions/${discussion.d.number}/lock`}
                  style="display: inline;"
                >
                  <button type="submit" class="btn">
                    {discussion.d.locked ? "Unlock" : "Lock"}
                  </button>
                </form>
                <form
                  method="POST"
                  action={`/${ownerName}/${repoName}/discussions/${discussion.d.number}/pin`}
                  style="display: inline;"
                >
                  <button type="submit" class="btn">
                    {discussion.d.pinned ? "Unpin" : "Pin"}
                  </button>
                </form>
              </>
            )}
          </div>
        )}
      </Layout>
    );
  }
);

// Add comment
discussionRoutes.post(
  "/:owner/:repo/discussions/:number/comment",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);

    const form = await c.req.formData();
    const body = (form.get("body") as string || "").trim();
    const parent = (form.get("parent_comment_id") as string) || null;
    if (!body) {
      return c.redirect(
        `/${ownerName}/${repoName}/discussions/${numParam}`
      );
    }

    try {
      const [row] = await db
        .select()
        .from(discussions)
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (!row || row.locked || row.state === "closed") {
        return c.redirect(
          `/${ownerName}/${repoName}/discussions/${numParam}`
        );
      }
      await db.insert(discussionComments).values({
        discussionId: row.id,
        authorId: user.id,
        body,
        parentCommentId: parent || null,
      });
      await db
        .update(discussions)
        .set({ updatedAt: new Date() })
        .where(eq(discussions.id, row.id));
    } catch {
      // swallow
    }
    return c.redirect(`/${ownerName}/${repoName}/discussions/${numParam}`);
  }
);

// Toggle lock (owner)
discussionRoutes.post(
  "/:owner/:repo/discussions/:number/lock",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);
    if (user.id !== resolved.repo.ownerId) {
      return c.redirect(
        `/${ownerName}/${repoName}/discussions/${numParam}`
      );
    }
    try {
      const [row] = await db
        .select()
        .from(discussions)
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (row) {
        await db
          .update(discussions)
          .set({ locked: !row.locked })
          .where(eq(discussions.id, row.id));
      }
    } catch {
      // swallow
    }
    return c.redirect(`/${ownerName}/${repoName}/discussions/${numParam}`);
  }
);

// Toggle pin (owner)
discussionRoutes.post(
  "/:owner/:repo/discussions/:number/pin",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);
    if (user.id !== resolved.repo.ownerId) {
      return c.redirect(
        `/${ownerName}/${repoName}/discussions/${numParam}`
      );
    }
    try {
      const [row] = await db
        .select()
        .from(discussions)
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (row) {
        await db
          .update(discussions)
          .set({ pinned: !row.pinned })
          .where(eq(discussions.id, row.id));
      }
    } catch {
      // swallow
    }
    return c.redirect(`/${ownerName}/${repoName}/discussions/${numParam}`);
  }
);

// Mark answer (owner on q-and-a)
discussionRoutes.post(
  "/:owner/:repo/discussions/:number/answer/:commentId",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName, commentId } = c.req.param();
    const user = c.get("user")!;
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);

    try {
      const [row] = await db
        .select()
        .from(discussions)
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (!row) {
        return c.redirect(`/${ownerName}/${repoName}/discussions`);
      }
      const isOwner = user.id === resolved.repo.ownerId;
      const isAuthor = user.id === row.authorId;
      if (!isOwner && !isAuthor) {
        return c.redirect(
          `/${ownerName}/${repoName}/discussions/${numParam}`
        );
      }
      if (row.category !== "q-and-a") {
        return c.text(
          "Only q-and-a discussions can have answers",
          400
        );
      }
      await db
        .update(discussions)
        .set({ answerCommentId: commentId })
        .where(eq(discussions.id, row.id));
      await db
        .update(discussionComments)
        .set({ isAnswer: true })
        .where(eq(discussionComments.id, commentId));
    } catch {
      // swallow
    }
    return c.redirect(`/${ownerName}/${repoName}/discussions/${numParam}`);
  }
);

// Toggle close (owner or author)
discussionRoutes.post(
  "/:owner/:repo/discussions/:number/close",
  requireAuth,
  async (c) => {
    const { owner: ownerName, repo: repoName } = c.req.param();
    const user = c.get("user")!;
    const numParam = Number(c.req.param("number"));
    const resolved = await resolveRepo(ownerName, repoName);
    if (!resolved) return c.redirect(`/${ownerName}/${repoName}`);
    try {
      const [row] = await db
        .select()
        .from(discussions)
        .where(
          and(
            eq(discussions.repositoryId, resolved.repo.id),
            eq(discussions.number, numParam)
          )
        )
        .limit(1);
      if (!row) {
        return c.redirect(`/${ownerName}/${repoName}/discussions`);
      }
      const isOwner = user.id === resolved.repo.ownerId;
      const isAuthor = user.id === row.authorId;
      if (!isOwner && !isAuthor) {
        return c.redirect(
          `/${ownerName}/${repoName}/discussions/${numParam}`
        );
      }
      await db
        .update(discussions)
        .set({ state: row.state === "open" ? "closed" : "open" })
        .where(eq(discussions.id, row.id));
    } catch {
      // swallow
    }
    return c.redirect(`/${ownerName}/${repoName}/discussions/${numParam}`);
  }
);

export default discussionRoutes;