diff options
| author | Joe Mou <dev@mou.fo> | 2026-05-27 14:02:36 -0400 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-05-27 23:37:23 -0400 |
| commit | c57123139794c3ef174b62c6bd2a54a60bbf3327 (patch) | |
| tree | dfa27f2843efd30b2fab6ae65abd233ee488e69d /cgithub/src/index.ts | |
| parent | 123da65350888dc0fbe04003c5ffc36fdded3a46 (diff) | |
Add repo-scoped search support for issues and PRs
We do not support hybrid issue/PR search. Any searches on the issues
endpoint will redirect to an explicit issue-only search.
Diffstat (limited to 'cgithub/src/index.ts')
| -rw-r--r-- | cgithub/src/index.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/cgithub/src/index.ts b/cgithub/src/index.ts index eb3a0ee..db9915f 100644 --- a/cgithub/src/index.ts +++ b/cgithub/src/index.ts @@ -70,7 +70,31 @@ app.get("/:owner/:repo/raw/:branch/:path{.*}", async (c) => { app.get("/:owner/:repo/issues", async (c) => { const { owner, repo } = c.req.param(); - return tryRender(c, "issues.eta", getGitHubIssues(owner, repo)); + const q = c.req.query("q"); + + // GitHub supports combined issue/PR search, apparently for legacy. We just + // redirect to issue-only search. + if (q && !/\bis:issue\b/.test(q)) { + return c.redirect(`/${owner}/${repo}/issues?q=${encodeURIComponent(`is:issue ${q}`)}`); + } + + return tryRender(c, "issues.eta", getGitHubIssues(owner, repo, { q })); +}); + +app.get("/:owner/:repo/search", async (c) => { + const { owner, repo } = c.req.param(); + const q = c.req.query("q") ?? ""; + const type = c.req.query("type") ?? "issues"; + + if (type === "issues") { + return c.redirect(`/${owner}/${repo}/issues?q=${encodeURIComponent(q)}`); + } + + // Redirect unhandled search types (like code, which requires sign in anyway). + c.header("Referrer-Policy", "no-referrer"); + return c.redirect( + `https://github.com/${owner}/${repo}/search?${new URLSearchParams(c.req.query()).toString()}`, + ); }); app.get("/:owner/:repo/commits/:branch/:path{.*}?", async (c) => { |
