Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 34ab5a6

Browse files
Merge pull request #245 from takker99:commit
feat: Implement `/api/commits/:project/:pageid`
2 parents d1c9b93 + 25a6ec3 commit 34ab5a6

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

‎api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
export * from "./api/commits.ts";
12
export * from "./api/pages.ts";
23
export * from "./api/projects.ts";
3-
export * from "./api/users.ts";
44
export * from "./api/smart-context.ts";
5+
export * from "./api/users.ts";
56
export type { HTTPError, TypedError } from "./error.ts";
67
export type { BaseOptions, ExtendedOptions, OAuthOptions } from "./util.ts";

‎api/commits.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./commits/project.ts";

‎api/commits/project.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./project/page_id.ts";

‎api/commits/project/page_id.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import type {
2+
CommitsResponse,
3+
NotFoundError,
4+
NotLoggedInError,
5+
NotMemberError,
6+
} from "@cosense/types/rest";
7+
import type { ResponseOfEndpoint } from "../../../targeted_response.ts";
8+
import { type BaseOptions, setDefaults } from "../../../util.ts";
9+
import { cookie } from "../../../rest/auth.ts";
10+
11+
/**
12+
* Represents an error when the commit HEAD is invalid.
13+
*/
14+
export interface InvalidHeadError {
15+
/** error message */
16+
message: string;
17+
}
18+
19+
/**
20+
* Options for {@linkcode getCommits}
21+
*
22+
* @experimental **UNSTABLE**: New API, yet to be vetted.
23+
*/
24+
export interface GetCommitsOption<R extends Response | undefined>
25+
extends BaseOptions<R> {
26+
/** Returns only the commits before the specified commit id.
27+
*
28+
* If not specified, returned all commits.
29+
*/
30+
head?: string;
31+
}
32+
33+
/** Constructs a request for the `/api/commits/:project/:pageId` endpoint
34+
*
35+
* @experimental **UNSTABLE**: New API, yet to be vetted.
36+
*
37+
* @param project The project name containing the desired page
38+
* @param pageId The page ID to retrieve
39+
* @param options - Additional configuration options
40+
* @returns A {@linkcode Request} object for fetching page data
41+
*/
42+
export const makeGetCommitsRequest = <R extends Response | undefined>(
43+
project: string,
44+
pageId: string,
45+
options?: GetCommitsOption<R>,
46+
): Request => {
47+
const { sid, baseURL, head } = setDefaults(options ?? {});
48+
49+
return new Request(
50+
`${baseURL}api/commits/${project}/${pageId}?head=${head ?? ""}`,
51+
sid ? { headers: { Cookie: cookie(sid) } } : undefined,
52+
);
53+
};
54+
55+
/** Retrieves the commit history for a specified page
56+
*
57+
* @experimental **UNSTABLE**: New API, yet to be vetted.
58+
*
59+
* @param project The project name containing the desired page
60+
* @param pageId The page ID to retrieve
61+
* @param options Additional configuration options for the request
62+
*/
63+
export const getCommits = <R extends Response | undefined = Response>(
64+
project: string,
65+
pageId: string,
66+
options?: GetCommitsOption<R>,
67+
): Promise<
68+
ResponseOfEndpoint<{
69+
200: CommitsResponse;
70+
400: InvalidHeadError;
71+
401: NotLoggedInError;
72+
403: NotMemberError;
73+
404: NotFoundError;
74+
}, R>
75+
> =>
76+
setDefaults(options ?? {}).fetch(
77+
makeGetCommitsRequest(project, pageId, options),
78+
) as Promise<
79+
ResponseOfEndpoint<{
80+
200: CommitsResponse;
81+
400: InvalidHeadError;
82+
401: NotLoggedInError;
83+
403: NotMemberError;
84+
404: NotFoundError;
85+
}, R>
86+
>;

‎deno.jsonc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"./title": "./title.ts",
2424
"./unstable-api": "./api.ts",
2525
"./unstable-api/pages": "./api/pages.ts",
26+
"./unstable-api/commits": "./api/commits.ts",
27+
"./unstable-api/commits/project": "./api/commits/project.ts",
28+
"./unstable-api/commits/project/page-id": "./api/commits/project/page_id.ts",
2629
"./unstable-api/pages/project": "./api/pages/project.ts",
2730
"./unstable-api/pages/project/replace": "./api/pages/project/replace.ts",
2831
"./unstable-api/pages/project/replace/links": "./api/pages/project/replace/links.ts",

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /