37 |
38 | {count} result
39 | {count > 1 ? "s" : ""}{" "}
40 | {count ? (
41 | <>
42 | ({from}-
43 | {to})
44 | >
45 | ) : null}
46 | {typeLabel ? (
47 | <>
48 | {" "}
49 | for{" "}
50 |
51 | {typeLabel}
52 | {" "}
53 | repositories
54 | >
55 | ) : null}{" "}
56 | sorted by{" "}
57 | {sortByLabel}
58 |
59 |
60 |
68 |
69 |
70 | );
71 | }
72 |
--------------------------------------------------------------------------------
/src/utils/github/repository.ts:
--------------------------------------------------------------------------------
1 | import type { ParsedUrlQuery } from "querystring";
2 | /**
3 | * Parse query from urls like :
4 | * - `[owner]/[repository]/tree/[branchName]`
5 | * - `[owner]/[repository]/commit/[commitId]`
6 | * - `[owner]/[repository]/blob/[branchName]?path=[path]`
7 | */
8 | export const parseQuery = (
9 | query: ParsedUrlQuery
10 | ): {
11 | owner: string;
12 | repositoryName: string;
13 | branchName?: string;
14 | commitId?: string;
15 | path?: string;
16 | } => {
17 | const { owner, repositoryName, branchName, commitId, path } = query;
18 | return {
19 | owner: typeof owner === "string" ? owner : "",
20 | repositoryName: typeof repositoryName === "string" ? repositoryName : "",
21 | branchName:
22 | // eslint-disable-next-line no-nested-ternary
23 | typeof branchName === "string"
24 | ? branchName
25 | : Array.isArray(branchName)
26 | ? branchName.join("/")
27 | : undefined,
28 | commitId: typeof commitId === "string" ? commitId : undefined,
29 | path: typeof path === "string" ? path : undefined,
30 | };
31 | };
32 |
33 | export function getRepositoryVariables({
34 | owner,
35 | repositoryName,
36 | branchName,
37 | commitId,
38 | path,
39 | }: {
40 | owner: string;
41 | repositoryName: string;
42 | branchName?: string;
43 | commitId?: string;
44 | path?: string;
45 | }): {
46 | owner: string;
47 | name: string;
48 | ref: string;
49 | refPath: string;
50 | upperCaseReadmeRefPath: string;
51 | lowerCaseReadmeRefPath: string;
52 | commit?: string;
53 | path?: string;
54 | } {
55 | return {
56 | owner,
57 | name: repositoryName,
58 | ref: branchName ?? "HEAD",
59 | refPath: `${branchName ?? "HEAD"}:${path || ""}`,
60 | upperCaseReadmeRefPath: `${branchName ?? "HEAD"}:README.md`,
61 | lowerCaseReadmeRefPath: `${branchName ?? "HEAD"}:readme.md`,
62 | commit: commitId,
63 | path,
64 | };
65 | }
66 |
67 | type ResolveCurrentRefType = {
68 | currentRef: {
69 | name: string;
70 | prefix: "refs/heads/" | "refs/tags/";
71 | } | null;
72 | defaultBranchName: string;
73 | };
74 |
75 | export function resolveCurrentRef({
76 | currentRef,
77 | defaultBranchName,
78 | }: ResolveCurrentRefType): {
79 | name: string;
80 | prefix: "refs/heads/" | "refs/tags/";
81 | } {
82 | return (
83 | currentRef || {
84 | name: defaultBranchName,
85 | prefix: "refs/heads/",
86 | }
87 | );
88 | }
89 |
--------------------------------------------------------------------------------
/src/stories/assets/stackalt.svg:
--------------------------------------------------------------------------------
1 |