-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): Rewrite with @hono/hono (#41)
Use Hono, a more useful web framework.
- Loading branch information
Showing
16 changed files
with
206 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,14 @@ | |
"run": "deno run --env='.env' --allow-env='REPOSITORY_OWNER,REPOSITORY_NAME,REPOSITORY_PATH,GITHUB_TOKEN' --allow-net='0.0.0.0,api.github.com'", | ||
"start": "deno task run ./src/server.ts", | ||
"dev": "deno task run --watch ./src/server.ts", | ||
"test": "deno test --allow-env='REPOSITORY_OWNER,REPOSITORY_NAME,REPOSITORY_PATH,GITHUB_TOKEN' --allow-net='api.github.com' --parallel --shuffle", | ||
"test": "deno test --allow-env='REPOSITORY_OWNER,REPOSITORY_NAME,REPOSITORY_PATH,GITHUB_TOKEN' --allow-net='0.0.0.0,api.github.com' --parallel --shuffle", | ||
"cov": "deno task test --coverage && deno coverage --lcov > coverage.lcov" | ||
}, | ||
"imports": { | ||
"@oak/oak": "jsr:@oak/[email protected]", | ||
"@hono/hono": "jsr:@hono/[email protected]", | ||
"@octokit/rest": "https://esm.sh/@octokit/[email protected]", | ||
"@std/assert": "jsr:@std/[email protected]", | ||
"@std/fmt": "jsr:@std/[email protected]", | ||
"@std/http": "jsr:@std/[email protected]", | ||
"@std/http/user-agent": "jsr:@std/http@~0.223/user-agent", | ||
"@std/path": "jsr:@std/[email protected]" | ||
}, | ||
"deploy": { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { assertEquals, assertExists, assertStringIncludes } from "@std/assert"; | ||
import { STATUS_CODE } from "@std/http/status"; | ||
|
||
import { getContent } from "./content.ts"; | ||
import { exportRepo, testRef, testRepo, unknownRepo } from "../test_utils.ts"; | ||
|
||
Deno.test("Get Content", async (t: Deno.TestContext) => { | ||
await t.step("normal", async () => { | ||
exportRepo(testRepo); | ||
const [data, status] = await getContent(); | ||
|
||
assertExists(data); | ||
assertEquals(status, STATUS_CODE.OK); | ||
}); | ||
|
||
await t.step("with ref", async () => { | ||
exportRepo(testRepo); | ||
const [data, status] = await getContent(testRef); | ||
|
||
assertExists(data); | ||
assertEquals(status, STATUS_CODE.OK); | ||
}); | ||
|
||
await t.step("not found", async () => { | ||
exportRepo(unknownRepo); | ||
const [data, status] = await getContent(); | ||
|
||
assertStringIncludes(data, `⚠️ ${STATUS_CODE.NotFound}:`); | ||
assertEquals(status, STATUS_CODE.NotFound); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { UserAgent } from "@std/http/user-agent"; | ||
|
||
import { getGitHubUrl, getRepository } from "../utils/env.ts"; | ||
|
||
export function redirect( | ||
userAgent: UserAgent, | ||
ref: string = "master", | ||
): URL | null { | ||
const url = getGitHubUrl(getRepository(), ref); | ||
|
||
return userAgent?.browser.name ? url : null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { assertEquals } from "@std/assert"; | ||
|
||
import { redirect } from "./redirect.ts"; | ||
import { exportRepo, testRef, testRepo, testUserAgent } from "../test_utils.ts"; | ||
import { getGitHubUrl } from "../utils/env.ts"; | ||
|
||
Deno.test("Redirect Detection", async (t: Deno.TestContext) => { | ||
await t.step("normal", () => { | ||
exportRepo(testRepo); | ||
const url: URL | null = redirect(testUserAgent); | ||
|
||
assertEquals(url, getGitHubUrl(testRepo)); | ||
}); | ||
|
||
await t.step("with ref", () => { | ||
exportRepo(testRepo); | ||
const url: URL | null = redirect(testUserAgent, testRef); | ||
|
||
assertEquals(url, getGitHubUrl(testRepo, testRef)); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.