@sourcepress/github 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +15 -0
- package/dist/__tests__/approval.test.d.ts +2 -0
- package/dist/__tests__/approval.test.d.ts.map +1 -0
- package/dist/__tests__/approval.test.js +171 -0
- package/dist/__tests__/approval.test.js.map +1 -0
- package/dist/__tests__/content.test.d.ts +2 -0
- package/dist/__tests__/content.test.d.ts.map +1 -0
- package/dist/__tests__/content.test.js +58 -0
- package/dist/__tests__/content.test.js.map +1 -0
- package/dist/approval.d.ts +15 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +87 -0
- package/dist/approval.js.map +1 -0
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +138 -0
- package/dist/client.js.map +1 -0
- package/dist/content.d.ts +6 -0
- package/dist/content.d.ts.map +1 -0
- package/dist/content.js +39 -0
- package/dist/content.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/__tests__/approval.test.ts +207 -0
- package/src/__tests__/content.test.ts +68 -0
- package/src/approval.ts +117 -0
- package/src/client.ts +170 -0
- package/src/content.ts +57 -0
- package/src/index.ts +4 -0
- package/src/types.ts +30 -0
- package/tsconfig.json +5 -0
- package/vitest.config.ts +2 -0
package/src/content.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ContentFile } from "@sourcepress/core";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
import type { GitHubClient } from "./client.js";
|
|
4
|
+
|
|
5
|
+
function parseFrontmatter(raw: string): { frontmatter: Record<string, unknown>; body: string } {
|
|
6
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
7
|
+
if (!match) return { frontmatter: {}, body: raw };
|
|
8
|
+
|
|
9
|
+
const frontmatter = parseYaml(match[1]) as Record<string, unknown>;
|
|
10
|
+
|
|
11
|
+
return { frontmatter, body: match[2].trim() };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function listContentFiles(
|
|
15
|
+
client: GitHubClient,
|
|
16
|
+
contentPath: string,
|
|
17
|
+
): Promise<string[]> {
|
|
18
|
+
const tree = await client.getTree();
|
|
19
|
+
return tree
|
|
20
|
+
.filter((entry) => entry.path.startsWith(contentPath) && entry.type === "blob")
|
|
21
|
+
.map((entry) => entry.path);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function getContentFile(
|
|
25
|
+
client: GitHubClient,
|
|
26
|
+
path: string,
|
|
27
|
+
collection: string,
|
|
28
|
+
): Promise<ContentFile | null> {
|
|
29
|
+
const file = await client.getFile(path);
|
|
30
|
+
if (!file) return null;
|
|
31
|
+
|
|
32
|
+
const { frontmatter, body } = parseFrontmatter(file.content);
|
|
33
|
+
const slug =
|
|
34
|
+
path
|
|
35
|
+
.split("/")
|
|
36
|
+
.pop()
|
|
37
|
+
?.replace(/\.(mdx?|ya?ml|json)$/, "") ?? "";
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
collection,
|
|
41
|
+
slug,
|
|
42
|
+
path,
|
|
43
|
+
frontmatter,
|
|
44
|
+
body,
|
|
45
|
+
provenance: frontmatter._provenance as ContentFile["provenance"],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function listKnowledgeFiles(
|
|
50
|
+
client: GitHubClient,
|
|
51
|
+
knowledgePath: string,
|
|
52
|
+
): Promise<string[]> {
|
|
53
|
+
const tree = await client.getTree();
|
|
54
|
+
return tree
|
|
55
|
+
.filter((entry) => entry.path.startsWith(knowledgePath) && entry.type === "blob")
|
|
56
|
+
.map((entry) => entry.path);
|
|
57
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { GitHubClient } from "./client.js";
|
|
2
|
+
export { listContentFiles, getContentFile, listKnowledgeFiles } from "./content.js";
|
|
3
|
+
export { GitHubPRApprovalProvider } from "./approval.js";
|
|
4
|
+
export type { GitHubClientConfig, GitHubFile, GitHubTreeEntry, GitHubPR } from "./types.js";
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface GitHubClientConfig {
|
|
2
|
+
owner: string;
|
|
3
|
+
repo: string;
|
|
4
|
+
branch: string;
|
|
5
|
+
token: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface GitHubFile {
|
|
9
|
+
path: string;
|
|
10
|
+
sha: string;
|
|
11
|
+
content: string;
|
|
12
|
+
encoding: "utf-8" | "base64";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface GitHubTreeEntry {
|
|
16
|
+
path: string;
|
|
17
|
+
sha: string;
|
|
18
|
+
type: "blob" | "tree";
|
|
19
|
+
size?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface GitHubPR {
|
|
23
|
+
number: number;
|
|
24
|
+
title: string;
|
|
25
|
+
body: string;
|
|
26
|
+
state: "open" | "closed" | "merged";
|
|
27
|
+
html_url: string;
|
|
28
|
+
head: { ref: string; sha: string };
|
|
29
|
+
base: { ref: string };
|
|
30
|
+
}
|
package/tsconfig.json
ADDED
package/vitest.config.ts
ADDED