website
git clone https://git.pyrossh.dev/website
木 Personal website of pyrossh. Built with astrojs, shiki, vite.
0856749
— pyrossh
2026-07-07T12:12:56+05:30
feat: add repo issues workers with htmx interactivity
- packages/workers/repos/issues/detail/package.json +14 -0
- packages/workers/repos/issues/detail/src/index.tsx +139 -0
- packages/workers/repos/issues/detail/tsconfig.json +4 -0
- packages/workers/repos/issues/detail/wrangler.jsonc +10 -0
- packages/workers/repos/issues/index/package.json +14 -0
- packages/workers/repos/issues/index/src/index.tsx +84 -0
- packages/workers/repos/issues/index/tsconfig.json +4 -0
- packages/workers/repos/issues/index/wrangler.jsonc +10 -0
packages/workers/repos/issues/detail/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pyrossh/repos-issues-detail",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.tsx",
|
|
7
|
+
"types": "src/index.tsx",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@pyrossh/config": "workspace:*",
|
|
10
|
+
"@pyrossh/core": "workspace:*",
|
|
11
|
+
"@pyrossh/types": "workspace:*",
|
|
12
|
+
"@pyrossh/ui": "workspace:*"
|
|
13
|
+
}
|
|
14
|
+
}
|
packages/workers/repos/issues/detail/src/index.tsx
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { RepoLayout } from "@pyrossh/ui";
|
|
2
|
+
import { getRepo, getGitBugIssue, addGitBugIssueComment, setGitBugIssueState } from "@pyrossh/core";
|
|
3
|
+
import type { Env, GitBugIssue } from "@pyrossh/types";
|
|
4
|
+
|
|
5
|
+
const TimeAgo = (date: string) => <time-ago data-date={date}></time-ago>;
|
|
6
|
+
|
|
7
|
+
const StateBadge = (issue: GitBugIssue) => (
|
|
8
|
+
<span id="state-badge" class={`state ${issue.state}`}>
|
|
9
|
+
{issue.state}
|
|
10
|
+
</span>
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const CommentsSection = (repoId: string, issue: GitBugIssue) => (
|
|
14
|
+
<section id="comments-section" class="comments">
|
|
15
|
+
{issue.comments.length > 0 && (
|
|
16
|
+
<>
|
|
17
|
+
<h3>Comments</h3>
|
|
18
|
+
{issue.comments.map((comment) => (
|
|
19
|
+
<article class="comment">
|
|
20
|
+
<div class="comment-meta">
|
|
21
|
+
{comment.author && <strong>{comment.author}</strong>}
|
|
22
|
+
{comment.createdAt && TimeAgo(comment.createdAt)}
|
|
23
|
+
</div>
|
|
24
|
+
<pre>{comment.body}</pre>
|
|
25
|
+
</article>
|
|
26
|
+
))}
|
|
27
|
+
</>
|
|
28
|
+
)}
|
|
29
|
+
<form
|
|
30
|
+
class="comment-form"
|
|
31
|
+
hx-post={`/repos/${repoId}/issues/${issue.id}`}
|
|
32
|
+
hx-target="#comments-section"
|
|
33
|
+
hx-swap="outerHTML"
|
|
34
|
+
>
|
|
35
|
+
<input name="repoId" type="hidden" value={repoId} />
|
|
36
|
+
<input name="issueId" type="hidden" value={issue.id} />
|
|
37
|
+
<textarea name="body" placeholder="Comment" required></textarea>
|
|
38
|
+
<div class="comment-actions">
|
|
39
|
+
<input name="author" placeholder="Author" />
|
|
40
|
+
<button type="submit">Comment</button>
|
|
41
|
+
</div>
|
|
42
|
+
</form>
|
|
43
|
+
</section>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const IssueHeader = (repoId: string, issue: GitBugIssue) => (
|
|
47
|
+
<article class="issue">
|
|
48
|
+
<div class="issue-title">
|
|
49
|
+
<a href={`/repos/${repoId}/issues/${issue.id}`} title={issue.id}>
|
|
50
|
+
{issue.title}
|
|
51
|
+
</a>
|
|
52
|
+
{StateBadge(issue)}
|
|
53
|
+
</div>
|
|
54
|
+
<div class="meta">
|
|
55
|
+
<a href={`/repos/${repoId}/issues/${issue.id}`} title={issue.id}>
|
|
56
|
+
{issue.id.substring(0, 8)}
|
|
57
|
+
</a>
|
|
58
|
+
{issue.author && <span>by {issue.author}</span>}
|
|
59
|
+
{issue.createdAt && TimeAgo(issue.createdAt)}
|
|
60
|
+
{issue.comments.length > 0 && <span>{issue.comments.length} comments</span>}
|
|
61
|
+
</div>
|
|
62
|
+
{issue.labels.length > 0 && (
|
|
63
|
+
<div class="labels">
|
|
64
|
+
{issue.labels.map((label) => (
|
|
65
|
+
<span class="label">#{label}</span>
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
)}
|
|
69
|
+
</article>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const StateForm = (repoId: string, issue: GitBugIssue) => (
|
|
73
|
+
<form
|
|
74
|
+
class="state-form"
|
|
75
|
+
hx-put={`/repos/${repoId}/issues/${issue.id}`}
|
|
76
|
+
hx-target="#state-badge"
|
|
77
|
+
hx-swap="outerHTML"
|
|
78
|
+
>
|
|
79
|
+
<input name="repoId" type="hidden" value={repoId} />
|
|
80
|
+
<input name="issueId" type="hidden" value={issue.id} />
|
|
81
|
+
<input name="state" type="hidden" value={issue.state === "open" ? "closed" : "open"} />
|
|
82
|
+
<input name="author" type="hidden" value={issue.author || ""} />
|
|
83
|
+
<button type="submit">{issue.state === "open" ? "Close" : "Reopen"}</button>
|
|
84
|
+
</form>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
89
|
+
const url = new URL(request.url);
|
|
90
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
91
|
+
const repoId = parts[1];
|
|
92
|
+
const issueId = parts[3];
|
|
93
|
+
|
|
94
|
+
const repo = getRepo(repoId);
|
|
95
|
+
if (!repo) return Response.redirect(`${url.origin}/404`, 302);
|
|
96
|
+
|
|
97
|
+
const issue = await getGitBugIssue(env.REPOS, repo.id, issueId ?? "");
|
|
98
|
+
if (!issue) return Response.redirect(`${url.origin}/repos/${repo.id}/issues`, 302);
|
|
99
|
+
|
|
100
|
+
if (request.method === "POST") {
|
|
101
|
+
const formData = await request.formData();
|
|
102
|
+
const body = formData.get("body") as string;
|
|
103
|
+
const author = formData.get("author") as string;
|
|
104
|
+
const updated = await addGitBugIssueComment(env.REPOS, repo.id, issueId, { body, author });
|
|
105
|
+
return new Response("<!---->" + CommentsSection(repo.id, updated).toString(), {
|
|
106
|
+
headers: { "Content-Type": "text/html" },
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (request.method === "PUT") {
|
|
111
|
+
const formData = await request.formData();
|
|
112
|
+
const state = formData.get("state") as "open" | "closed";
|
|
113
|
+
const author = formData.get("author") as string;
|
|
114
|
+
const updated = await setGitBugIssueState(env.REPOS, repo.id, issueId, state, author);
|
|
115
|
+
return new Response(StateBadge(updated).toString(), {
|
|
116
|
+
headers: { "Content-Type": "text/html" },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return new Response(
|
|
121
|
+
<RepoLayout repo={repo} request={request} currentTab="Issues">
|
|
122
|
+
{IssueHeader(repo.id, issue)}
|
|
123
|
+
{StateForm(repo.id, issue)}
|
|
124
|
+
{issue.body && (
|
|
125
|
+
<section class="body">
|
|
126
|
+
<pre>{issue.body}</pre>
|
|
127
|
+
</section>
|
|
128
|
+
)}
|
|
129
|
+
{CommentsSection(repo.id, issue)}
|
|
130
|
+
</RepoLayout>,
|
|
131
|
+
{
|
|
132
|
+
headers: {
|
|
133
|
+
"Content-Type": "text/html",
|
|
134
|
+
"Cache-Control": "public, max-age=300, s-maxage=3600",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
};
|
packages/workers/repos/issues/detail/tsconfig.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"]
|
|
4
|
+
}
|
packages/workers/repos/issues/detail/wrangler.jsonc
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/cloudflare/workers-sdk/main/packages/wrangler/config-schema.json",
|
|
3
|
+
"name": "pyrossh-repos-issues-detail",
|
|
4
|
+
"main": "src/index.tsx",
|
|
5
|
+
"compatibility_date": "2026-07-07",
|
|
6
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
7
|
+
"workers_dev": false,
|
|
8
|
+
"routes": [{ "pattern": "pyrossh.dev/repos/*/issues/*", "custom_domain": true }],
|
|
9
|
+
"r2_buckets": [{ "binding": "REPOS", "bucket_name": "pyrossh-repos-prd" }],
|
|
10
|
+
}
|
packages/workers/repos/issues/index/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pyrossh/repos-issues-index",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.tsx",
|
|
7
|
+
"types": "src/index.tsx",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@pyrossh/config": "workspace:*",
|
|
10
|
+
"@pyrossh/core": "workspace:*",
|
|
11
|
+
"@pyrossh/types": "workspace:*",
|
|
12
|
+
"@pyrossh/ui": "workspace:*"
|
|
13
|
+
}
|
|
14
|
+
}
|
packages/workers/repos/issues/index/src/index.tsx
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { RepoLayout, IssueCard } from "@pyrossh/ui";
|
|
2
|
+
import { getRepo, getGitBugIssues, createGitBugIssue } from "@pyrossh/core";
|
|
3
|
+
import type { Env, GitBugIssue, GitBugIssuesResult } from "@pyrossh/types";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
7
|
+
const url = new URL(request.url);
|
|
8
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
9
|
+
const repoId = parts[1];
|
|
10
|
+
const repo = getRepo(repoId);
|
|
11
|
+
if (!repo) return Response.redirect(`${url.origin}/404`, 302);
|
|
12
|
+
|
|
13
|
+
if (request.method === "POST") {
|
|
14
|
+
const formData = await request.formData();
|
|
15
|
+
const title = formData.get("title") as string;
|
|
16
|
+
const body = formData.get("body") as string;
|
|
17
|
+
const author = formData.get("author") as string;
|
|
18
|
+
const labelsRaw = formData.get("labels") as string;
|
|
19
|
+
const labels = labelsRaw
|
|
20
|
+
? labelsRaw
|
|
21
|
+
.split(",")
|
|
22
|
+
.map((l) => l.trim())
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
: undefined;
|
|
25
|
+
|
|
26
|
+
const issue = await createGitBugIssue(env.REPOS, repo.id, { title, body, author, labels });
|
|
27
|
+
|
|
28
|
+
const { issues } = await getGitBugIssues(env.REPOS, repo.id);
|
|
29
|
+
const html = issues.map((i) => <IssueCard repoId={repo.id} issue={i} />).join("");
|
|
30
|
+
|
|
31
|
+
return new Response(html, {
|
|
32
|
+
headers: { "Content-Type": "text/html" },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const { issues, isAvailable } = await getGitBugIssues(env.REPOS, repo.id);
|
|
37
|
+
const openIssues = issues.filter((issue) => issue.state === "open");
|
|
38
|
+
const closedIssues = issues.filter((issue) => issue.state === "closed");
|
|
39
|
+
|
|
40
|
+
return new Response(
|
|
41
|
+
<RepoLayout repo={repo} request={request} currentTab="Issues">
|
|
42
|
+
<section class="issues">
|
|
43
|
+
<div class="summary">
|
|
44
|
+
<strong>{issues.length}</strong> issues
|
|
45
|
+
<span>{openIssues.length} open</span>
|
|
46
|
+
<span>{closedIssues.length} closed</span>
|
|
47
|
+
</div>
|
|
48
|
+
<form
|
|
49
|
+
class="new-issue"
|
|
50
|
+
hx-post={`/repos/${repo.id}/issues`}
|
|
51
|
+
hx-target="#issues-list"
|
|
52
|
+
hx-swap="innerHTML"
|
|
53
|
+
>
|
|
54
|
+
<input name="repoId" type="hidden" value={repo.id} />
|
|
55
|
+
<input name="title" placeholder="Title" required />
|
|
56
|
+
<textarea name="body" placeholder="Description"></textarea>
|
|
57
|
+
<div class="form-row">
|
|
58
|
+
<input name="author" placeholder="Author" />
|
|
59
|
+
<input name="labels" placeholder="labels, comma-separated" />
|
|
60
|
+
<button type="submit">Create</button>
|
|
61
|
+
</div>
|
|
62
|
+
</form>
|
|
63
|
+
<div id="issues-list">
|
|
64
|
+
{issues.length > 0 ? (
|
|
65
|
+
issues.map((issue) => <IssueCard repoId={repo.id} issue={issue} />)
|
|
66
|
+
) : (
|
|
67
|
+
<p class="empty">
|
|
68
|
+
{isAvailable
|
|
69
|
+
? "No git-bug issues found in this repository."
|
|
70
|
+
: "No git-bug issues could be loaded from R2."}
|
|
71
|
+
</p>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
</section>
|
|
75
|
+
</RepoLayout>,
|
|
76
|
+
{
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "text/html",
|
|
79
|
+
"Cache-Control": "public, max-age=300, s-maxage=3600",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
};
|
packages/workers/repos/issues/index/tsconfig.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.base.json",
|
|
3
|
+
"include": ["src"]
|
|
4
|
+
}
|
packages/workers/repos/issues/index/wrangler.jsonc
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://raw.githubusercontent.com/cloudflare/workers-sdk/main/packages/wrangler/config-schema.json",
|
|
3
|
+
"name": "pyrossh-repos-issues-index",
|
|
4
|
+
"main": "src/index.tsx",
|
|
5
|
+
"compatibility_date": "2026-07-07",
|
|
6
|
+
"compatibility_flags": ["nodejs_compat"],
|
|
7
|
+
"workers_dev": false,
|
|
8
|
+
"routes": [{ "pattern": "pyrossh.dev/repos/*/issues", "custom_domain": true }],
|
|
9
|
+
"r2_buckets": [{ "binding": "REPOS", "bucket_name": "pyrossh-repos-prd" }],
|
|
10
|
+
}
|