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 | 96396c4ed853652ea311d006b4ebe6af15b40684 (patch) | |
| tree | 84ed30e17bc2232ac755f9d488a30d8aec233577 /src/index.ts | |
| parent | 12a072ded4d8528296bcf9fde6ae8324588da97e (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 'src/index.ts')
| -rw-r--r-- | src/index.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/index.ts b/src/index.ts index eb3a0ee..db9915f 100644 --- a/src/index.ts +++ b/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) => { |
