Swadhin Biswas Feature/ai code reviewer (#73) · 8/2/2026
105a287
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
---
import { getDatabase } from "@/db";
import { gpgKeys } from "@/db/schema";
import SettingsLayout from "@/layouts/SettingsLayout.astro";
import { desc, eq } from "drizzle-orm";
const user = Astro.locals.user;
if (!user) {
return Astro.redirect("/login");
}
const db = getDatabase();
const keys = await db.query.gpgKeys.findMany({
where: eq(gpgKeys.userId, user.id),
orderBy: [desc(gpgKeys.createdAt)],
});
---
<SettingsLayout title="GPG Keys">
<div class="space-y-6">
<div>
<h3 class="text-lg font-medium leading-6 text-gray-900">GPG Keys</h3>
<p class="mt-1 text-sm text-muted-foreground">
This is a list of GPG keys associated with your account. Keys are used to verify commit signatures.
</p>
</div>
<div class="border-t border-gray-200 pt-6">
<div class="flex justify-between items-center mb-4">
<h4 class="text-md font-medium text-gray-900">Your GPG Keys</h4>
<button
type="button"
id="add-key-btn"
class="inline-flex items-center px-3 py-2 border border-transparent text-sm leading-4 font-medium rounded-md text-foreground bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
>
New GPG Key
</button>
</div>
{
keys.length > 0 ? (
<ul class="divide-y divide-gray-200">
{keys.map((key) => (
<li class="py-4 flex items-center justify-between">
<div>
<p class="text-sm font-medium text-gray-900">{key.name}</p>
<p class="text-sm text-muted-foreground font-mono">
Key ID: {key.keyId}
</p>
<p class="text-xs text-muted-foreground mt-1">
Added on {new Date(key.createdAt).toLocaleDateString()}
</p>
</div>
<button
type="button"
class="delete-key-btn text-red-600 hover:text-red-900 text-sm font-medium"
data-id={key.id}
>
Delete
</button>
</li>
))}
</ul>
) : (
<p class="text-sm text-muted-foreground italic">No GPG keys added yet.</p>
)
}
</div>
<!-- Add Key Modal -->
<div
id="add-key-modal"
class="hidden fixed z-10 inset-0 overflow-y-auto"
aria-labelledby="modal-title"
role="dialog"
aria-modal="true"
>
<div
class="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0"
>
<div
class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"
aria-hidden="true"
>
</div>
<span
class="hidden sm:inline-block sm:align-middle sm:h-screen"
aria-hidden="true">​</span
>
<div
class="inline-block align-bottom bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full sm:p-6"
>
<form id="gpg-key-form">
<div>
<h3
class="text-lg leading-6 font-medium text-gray-900"
id="modal-title"
>
Add New GPG Key
</h3>
<div class="mt-4 space-y-4">
<div>
<label
for="name"
class="block text-sm font-medium text-gray-700">Name</label
>
<input
type="text"
name="name"
id="name"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"
placeholder="e.g. My GPG Key"
/>
</div>
<div>
<label
for="key"
class="block text-sm font-medium text-gray-700">GPG Public Key</label
>
<textarea
name="key"
id="key"
rows="8"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm font-mono text-xs"
placeholder="-----BEGIN PGP PUBLIC KEY BLOCK-----..."></textarea>
</div>
</div>
</div>
<div
class="mt-5 sm:mt-6 sm:grid sm:grid-cols-2 sm:gap-3 sm:grid-flow-row-dense"
>
<button
type="submit"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-foreground hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:col-start-2 sm:text-sm"
>
Add Key
</button>
<button
type="button"
id="cancel-add-key-btn"
class="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:col-start-1 sm:text-sm"
>
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</SettingsLayout>
<script>
const addBtn = document.getElementById("add-key-btn");
const modal = document.getElementById("add-key-modal");
const cancelBtn = document.getElementById("cancel-add-key-btn");
const form = document.getElementById("gpg-key-form") as HTMLFormElement;
const deleteBtns = document.querySelectorAll(".delete-key-btn");
addBtn?.addEventListener("click", () => {
modal?.classList.remove("hidden");
});
cancelBtn?.addEventListener("click", () => {
modal?.classList.add("hidden");
form.reset();
});
form?.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(form);
const data = Object.fromEntries(formData);
try {
const response = await fetch("/api/user/gpg-keys", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
});
if (response.ok) {
window.location.reload();
} else {
const error = await response.json();
alert(error.message || "Failed to add GPG key");
}
} catch (error) {
console.error("Error adding GPG key:", error);
alert("An error occurred");
}
});
deleteBtns.forEach((btn) => {
btn.addEventListener("click", async () => {
if (confirm("Are you sure you want to delete this GPG key?")) {
const id = btn.getAttribute("data-id");
try {
const response = await fetch(`/api/user/gpg-keys/${id}`, {
method: "DELETE",
});
if (response.ok) {
window.location.reload();
} else {
alert("Failed to delete GPG key");
}
} catch (error) {
console.error("Error deleting GPG key:", error);
}
}
});
});
</script>